001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.hbtop.screen.help;
019
020import java.util.Arrays;
021import java.util.Objects;
022
023import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
024import org.apache.yetus.audience.InterfaceAudience;
025
026
027/**
028 * The presentation logic for the help screen.
029 */
030@InterfaceAudience.Private
031public class HelpScreenPresenter {
032
033  private static final CommandDescription[] COMMAND_DESCRIPTIONS = new CommandDescription[] {
034    new CommandDescription("f", "Add/Remove/Order/Sort the fields"),
035    new CommandDescription("R", "Toggle the sort order (ascending/descending)"),
036    new CommandDescription("m", "Select mode"),
037    new CommandDescription("o", "Add a filter with ignoring case"),
038    new CommandDescription("O", "Add a filter with case sensitive"),
039    new CommandDescription("^o", "Show the current filters"),
040    new CommandDescription("=", "Clear the current filters"),
041    new CommandDescription("i", "Drill down"),
042    new CommandDescription(
043      Arrays.asList("up", "down", "left", "right", "pageUp", "pageDown", "home", "end"),
044      "Scroll the metrics"),
045    new CommandDescription("d", "Change the refresh delay"),
046    new CommandDescription("X", "Adjust the field length"),
047    new CommandDescription("<Enter>", "Refresh the display"),
048    new CommandDescription("h", "Display this screen"),
049    new CommandDescription(Arrays.asList("q", "<Esc>"), "Quit")
050  };
051
052  private final HelpScreenView helpScreenView;
053  private final long refreshDelay;
054  private final ScreenView nextScreenView;
055
056  public HelpScreenPresenter(HelpScreenView helpScreenView, long refreshDelay,
057    ScreenView nextScreenView) {
058    this.helpScreenView = Objects.requireNonNull(helpScreenView);
059    this.refreshDelay = refreshDelay;
060    this.nextScreenView = Objects.requireNonNull(nextScreenView);
061  }
062
063  public void init() {
064    helpScreenView.hideCursor();
065    helpScreenView.clearTerminal();
066    helpScreenView.showHelpScreen(refreshDelay, COMMAND_DESCRIPTIONS);
067    helpScreenView.refreshTerminal();
068  }
069
070  public ScreenView transitionToNextScreen() {
071    return nextScreenView;
072  }
073}