1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.hbtop.screen.help;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView;
22 import org.apache.hadoop.hbase.hbtop.screen.Screen;
23 import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
24 import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
25 import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
26 import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter;
27
28
29
30
31 @InterfaceAudience.Private
32 public class HelpScreenView extends AbstractScreenView {
33
34 private static final int SCREEN_DESCRIPTION_START_ROW = 0;
35 private static final int COMMAND_DESCRIPTION_START_ROW = 3;
36
37 private final HelpScreenPresenter helpScreenPresenter;
38
39 public HelpScreenView(Screen screen, Terminal terminal, long refreshDelay,
40 ScreenView nextScreenView) {
41 super(screen, terminal);
42 this.helpScreenPresenter = new HelpScreenPresenter(this, refreshDelay, nextScreenView);
43 }
44
45 @Override
46 public void init() {
47 helpScreenPresenter.init();
48 }
49
50 @Override
51 public ScreenView handleKeyPress(KeyPress keyPress) {
52 return helpScreenPresenter.transitionToNextScreen();
53 }
54
55 public void showHelpScreen(long refreshDelay, CommandDescription[] commandDescriptions) {
56 showScreenDescription(refreshDelay);
57
58 TerminalPrinter printer = getTerminalPrinter(COMMAND_DESCRIPTION_START_ROW);
59 for (CommandDescription commandDescription : commandDescriptions) {
60 showCommandDescription(printer, commandDescription);
61 }
62
63 printer.endOfLine();
64 printer.print("Press any key to continue").endOfLine();
65 }
66
67 private void showScreenDescription(long refreshDelay) {
68 TerminalPrinter printer = getTerminalPrinter(SCREEN_DESCRIPTION_START_ROW);
69 printer.startBold().print("Help for Interactive Commands").stopBold().endOfLine();
70 printer.print("Refresh delay: ").startBold()
71 .print((double) refreshDelay / 1000).stopBold().endOfLine();
72 }
73
74 private void showCommandDescription(TerminalPrinter terminalPrinter,
75 CommandDescription commandDescription) {
76 terminalPrinter.print(" ");
77 boolean first = true;
78 for (String key : commandDescription.getKeys()) {
79 if (first) {
80 first = false;
81 } else {
82 terminalPrinter.print(",");
83 }
84 terminalPrinter.startBold().print(key).stopBold();
85 }
86
87 terminalPrinter.printFormat(": %s", commandDescription.getDescription()).endOfLine();
88 }
89 }