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.terminal.impl; 019 020import java.util.Objects; 021import org.apache.hadoop.hbase.hbtop.terminal.Attributes; 022import org.apache.hadoop.hbase.hbtop.terminal.Color; 023import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * An implementation of the {@link TerminalPrinter} interface for normal display mode. 028 */ 029@InterfaceAudience.Private 030public class TerminalPrinterImpl implements TerminalPrinter { 031 private final ScreenBuffer screenBuffer; 032 private int row; 033 private int column; 034 035 private final Attributes attributes = new Attributes(); 036 037 TerminalPrinterImpl(ScreenBuffer screenBuffer, int startRow) { 038 this.screenBuffer = Objects.requireNonNull(screenBuffer); 039 this.row = startRow; 040 } 041 042 @Override 043 public TerminalPrinter print(String value) { 044 screenBuffer.putString(column, row, value, attributes); 045 column += value.length(); 046 return this; 047 } 048 049 @Override 050 public TerminalPrinter startHighlight() { 051 attributes.setForegroundColor(Color.BLACK); 052 attributes.setBackgroundColor(Color.WHITE); 053 return this; 054 } 055 056 @Override 057 public TerminalPrinter stopHighlight() { 058 attributes.setForegroundColor(Color.WHITE); 059 attributes.setBackgroundColor(Color.BLACK); 060 return this; 061 } 062 063 @Override 064 public TerminalPrinter startBold() { 065 attributes.setBold(true); 066 return this; 067 } 068 069 @Override 070 public TerminalPrinter stopBold() { 071 attributes.setBold(false); 072 return this; 073 } 074 075 @Override 076 public void endOfLine() { 077 screenBuffer.endOfLine(column, row); 078 row += 1; 079 column = 0; 080 } 081}