1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.hbtop.terminal.impl;
19
20 import java.util.Objects;
21
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.hbtop.terminal.AbstractTerminalPrinter;
24 import org.apache.hadoop.hbase.hbtop.terminal.Attributes;
25 import org.apache.hadoop.hbase.hbtop.terminal.Color;
26 import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter;
27
28
29
30
31 @InterfaceAudience.Private
32 public class TerminalPrinterImpl extends AbstractTerminalPrinter {
33 private final ScreenBuffer screenBuffer;
34 private int row;
35 private int column;
36
37 private final Attributes attributes = new Attributes();
38
39 TerminalPrinterImpl(ScreenBuffer screenBuffer, int startRow) {
40 this.screenBuffer = Objects.requireNonNull(screenBuffer);
41 this.row = startRow;
42 }
43
44 @Override
45 public TerminalPrinter print(String value) {
46 screenBuffer.putString(column, row, value, attributes);
47 column += value.length();
48 return this;
49 }
50
51 @Override
52 public TerminalPrinter startHighlight() {
53 attributes.setForegroundColor(Color.BLACK);
54 attributes.setBackgroundColor(Color.WHITE);
55 return this;
56 }
57
58 @Override
59 public TerminalPrinter stopHighlight() {
60 attributes.setForegroundColor(Color.WHITE);
61 attributes.setBackgroundColor(Color.BLACK);
62 return this;
63 }
64
65 @Override
66 public TerminalPrinter startBold() {
67 attributes.setBold(true);
68 return this;
69 }
70
71 @Override
72 public TerminalPrinter stopBold() {
73 attributes.setBold(false);
74 return this;
75 }
76
77 @Override
78 public void endOfLine() {
79 screenBuffer.endOfLine(column, row);
80 row += 1;
81 column = 0;
82 }
83 }