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 org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView; 021import org.apache.hadoop.hbase.hbtop.screen.Screen; 022import org.apache.hadoop.hbase.hbtop.screen.ScreenView; 023import org.apache.hadoop.hbase.hbtop.terminal.KeyPress; 024import org.apache.hadoop.hbase.hbtop.terminal.Terminal; 025import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter; 026import org.apache.yetus.audience.InterfaceAudience; 027 028 029/** 030 * The help screen. 031 */ 032@InterfaceAudience.Private 033public class HelpScreenView extends AbstractScreenView { 034 035 private static final int SCREEN_DESCRIPTION_START_ROW = 0; 036 private static final int COMMAND_DESCRIPTION_START_ROW = 3; 037 038 private final HelpScreenPresenter helpScreenPresenter; 039 040 public HelpScreenView(Screen screen, Terminal terminal, long refreshDelay, 041 ScreenView nextScreenView) { 042 super(screen, terminal); 043 this.helpScreenPresenter = new HelpScreenPresenter(this, refreshDelay, nextScreenView); 044 } 045 046 @Override 047 public void init() { 048 helpScreenPresenter.init(); 049 } 050 051 @Override 052 public ScreenView handleKeyPress(KeyPress keyPress) { 053 return helpScreenPresenter.transitionToNextScreen(); 054 } 055 056 public void showHelpScreen(long refreshDelay, CommandDescription[] commandDescriptions) { 057 showScreenDescription(refreshDelay); 058 059 TerminalPrinter printer = getTerminalPrinter(COMMAND_DESCRIPTION_START_ROW); 060 for (CommandDescription commandDescription : commandDescriptions) { 061 showCommandDescription(printer, commandDescription); 062 } 063 064 printer.endOfLine(); 065 printer.print("Press any key to continue").endOfLine(); 066 } 067 068 private void showScreenDescription(long refreshDelay) { 069 TerminalPrinter printer = getTerminalPrinter(SCREEN_DESCRIPTION_START_ROW); 070 printer.startBold().print("Help for Interactive Commands").stopBold().endOfLine(); 071 printer.print("Refresh delay: ").startBold() 072 .print((double) refreshDelay / 1000).stopBold().endOfLine(); 073 } 074 075 private void showCommandDescription(TerminalPrinter terminalPrinter, 076 CommandDescription commandDescription) { 077 terminalPrinter.print(" "); 078 boolean first = true; 079 for (String key : commandDescription.getKeys()) { 080 if (first) { 081 first = false; 082 } else { 083 terminalPrinter.print(","); 084 } 085 terminalPrinter.startBold().print(key).stopBold(); 086 } 087 088 terminalPrinter.printFormat(": %s", commandDescription.getDescription()).endOfLine(); 089 } 090}