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.top; 019 020import java.util.List; 021import java.util.function.Function; 022import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView; 023import org.apache.hadoop.hbase.hbtop.screen.Screen; 024import org.apache.hadoop.hbase.hbtop.screen.ScreenView; 025import org.apache.hadoop.hbase.hbtop.terminal.KeyPress; 026import org.apache.hadoop.hbase.hbtop.terminal.Terminal; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * The input mode in the top screen. 031 */ 032@InterfaceAudience.Private 033public class InputModeScreenView extends AbstractScreenView { 034 035 private final int row; 036 private final InputModeScreenPresenter inputModeScreenPresenter; 037 038 public InputModeScreenView(Screen screen, Terminal terminal, int row, String message, 039 List<String> histories, Function<String, ScreenView> resultListener) { 040 super(screen, terminal); 041 this.row = row; 042 this.inputModeScreenPresenter = 043 new InputModeScreenPresenter(this, message, histories, resultListener); 044 } 045 046 @Override 047 public void init() { 048 inputModeScreenPresenter.init(); 049 } 050 051 @Override 052 public ScreenView handleKeyPress(KeyPress keyPress) { 053 054 switch (keyPress.getType()) { 055 case Enter: 056 return inputModeScreenPresenter.returnToNextScreen(); 057 058 case Character: 059 inputModeScreenPresenter.character(keyPress.getCharacter()); 060 break; 061 062 case Backspace: 063 inputModeScreenPresenter.backspace(); 064 break; 065 066 case Delete: 067 inputModeScreenPresenter.delete(); 068 break; 069 070 case ArrowLeft: 071 inputModeScreenPresenter.arrowLeft(); 072 break; 073 074 case ArrowRight: 075 inputModeScreenPresenter.arrowRight(); 076 break; 077 078 case Home: 079 inputModeScreenPresenter.home(); 080 break; 081 082 case End: 083 inputModeScreenPresenter.end(); 084 break; 085 086 case ArrowUp: 087 inputModeScreenPresenter.arrowUp(); 088 break; 089 090 case ArrowDown: 091 inputModeScreenPresenter.arrowDown(); 092 break; 093 094 default: 095 break; 096 } 097 return this; 098 } 099 100 public void showInput(String message, String inputString, int cursorPosition) { 101 getTerminalPrinter(row).startBold().print(message).stopBold().print(" ").print(inputString) 102 .endOfLine(); 103 setCursorPosition(message.length() + 1 + cursorPosition, row); 104 refreshTerminal(); 105 } 106}