View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.terminal.impl;
19  
20  import java.util.concurrent.TimeUnit;
21  
22  import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
23  import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
24  import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter;
25  
26  
27  public final class TestTerminalPrinter {
28  
29    private TestTerminalPrinter() {
30    }
31  
32    public static void main(String[] args) throws Exception {
33      try (Terminal terminal = new TerminalImpl()) {
34        terminal.hideCursor();
35        terminal.refresh();
36  
37        TerminalPrinter printer = terminal.getTerminalPrinter(0);
38        printer.print("Normal string").endOfLine();
39        printer.startHighlight().print("Highlighted string").stopHighlight().endOfLine();
40        printer.startBold().print("Bold string").stopBold().endOfLine();
41        printer.startHighlight().startBold().print("Highlighted bold string")
42            .stopBold().stopHighlight().endOfLine();
43        printer.endOfLine();
44        printer.print("Press any key to finish").endOfLine();
45  
46        terminal.refresh();
47  
48        while (true) {
49          KeyPress keyPress = terminal.pollKeyPress();
50          if (keyPress == null) {
51            TimeUnit.MILLISECONDS.sleep(100);
52            continue;
53          }
54          break;
55        }
56      }
57    }
58  }