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.screen.help;
19  
20  import java.util.Arrays;
21  import java.util.Objects;
22  
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
25  
26  /**
27   * The presentation logic for the help screen.
28   */
29  @InterfaceAudience.Private
30  public class HelpScreenPresenter {
31  
32    private static final CommandDescription[] COMMAND_DESCRIPTIONS = new CommandDescription[] {
33      new CommandDescription("f", "Add/Remove/Order/Sort the fields"),
34      new CommandDescription("R", "Toggle the sort order (ascending/descending)"),
35      new CommandDescription("m", "Select mode"),
36      new CommandDescription("o", "Add a filter with ignoring case"),
37      new CommandDescription("O", "Add a filter with case sensitive"),
38      new CommandDescription("^o", "Show the current filters"),
39      new CommandDescription("=", "Clear the current filters"),
40      new CommandDescription("i", "Drill down"),
41      new CommandDescription(
42        Arrays.asList("up", "down", "left", "right", "pageUp", "pageDown", "home", "end"),
43        "Scroll the metrics"),
44      new CommandDescription("d", "Change the refresh delay"),
45      new CommandDescription("X", "Adjust the field length"),
46      new CommandDescription("<Enter>", "Refresh the display"),
47      new CommandDescription("h", "Display this screen"),
48      new CommandDescription(Arrays.asList("q", "<Esc>"), "Quit")
49    };
50  
51    private final HelpScreenView helpScreenView;
52    private final long refreshDelay;
53    private final ScreenView nextScreenView;
54  
55    public HelpScreenPresenter(HelpScreenView helpScreenView, long refreshDelay,
56      ScreenView nextScreenView) {
57      this.helpScreenView = Objects.requireNonNull(helpScreenView);
58      this.refreshDelay = refreshDelay;
59      this.nextScreenView = Objects.requireNonNull(nextScreenView);
60    }
61  
62    public void init() {
63      helpScreenView.hideCursor();
64      helpScreenView.clearTerminal();
65      helpScreenView.showHelpScreen(refreshDelay, COMMAND_DESCRIPTIONS);
66      helpScreenView.refreshTerminal();
67    }
68  
69    public ScreenView transitionToNextScreen() {
70      return nextScreenView;
71    }
72  }