2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.tterminal
;
31 import jexer
.bits
.Cell
;
32 import jexer
.bits
.CellAttributes
;
35 * This represents a single line of the display buffer.
37 public class DisplayLine
{
39 // ------------------------------------------------------------------------
40 // Constants --------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * Maximum line length.
46 private static final int MAX_LINE_LENGTH
= 256;
48 // ------------------------------------------------------------------------
49 // Variables --------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * The characters/attributes of the line.
55 private Cell
[] chars
;
58 * Double-width line flag.
60 private boolean doubleWidth
= false;
63 * Double height line flag. Valid values are:
67 * 1 = top half double height
68 * 2 = bottom half double height
71 private int doubleHeight
= 0;
74 * DECSCNM - reverse video. We copy the flag to the line so that
75 * reverse-mode scrollback lines still show inverted colors correctly.
77 private boolean reverseColor
= false;
79 // ------------------------------------------------------------------------
80 // Constructors -----------------------------------------------------------
81 // ------------------------------------------------------------------------
84 * Public constructor makes a duplicate (deep copy).
86 * @param line the line to duplicate
88 public DisplayLine(final DisplayLine line
) {
89 chars
= new Cell
[MAX_LINE_LENGTH
];
90 for (int i
= 0; i
< chars
.length
; i
++) {
91 chars
[i
] = new Cell(line
.chars
[i
]);
93 doubleWidth
= line
.doubleWidth
;
94 doubleHeight
= line
.doubleHeight
;
95 reverseColor
= line
.reverseColor
;
99 * Public constructor sets everything to drawing attributes.
101 * @param attr current drawing attributes
103 public DisplayLine(final CellAttributes attr
) {
104 chars
= new Cell
[MAX_LINE_LENGTH
];
105 for (int i
= 0; i
< chars
.length
; i
++) {
106 chars
[i
] = new Cell(attr
);
110 // ------------------------------------------------------------------------
111 // DisplayLine ------------------------------------------------------------
112 // ------------------------------------------------------------------------
115 * Get the Cell at a specific column.
117 * @param idx the character index
120 public Cell
charAt(final int idx
) {
125 * Get the length of this line.
127 * @return line length
129 public int length() {
134 * Get double width flag.
136 * @return double width
138 public boolean isDoubleWidth() {
143 * Set double width flag.
145 * @param doubleWidth new value for double width flag
147 public void setDoubleWidth(final boolean doubleWidth
) {
148 this.doubleWidth
= doubleWidth
;
152 * Get double height flag.
154 * @return double height
156 public int getDoubleHeight() {
161 * Set double height flag.
163 * @param doubleHeight new value for double height flag
165 public void setDoubleHeight(final int doubleHeight
) {
166 this.doubleHeight
= doubleHeight
;
170 * Get reverse video flag.
172 * @return reverse video
174 public boolean isReverseColor() {
179 * Set double-height flag.
181 * @param reverseColor new value for reverse video flag
183 public void setReverseColor(final boolean reverseColor
) {
184 this.reverseColor
= reverseColor
;
188 * Insert a character at the specified position.
190 * @param idx the character index
191 * @param newCell the new Cell
193 public void insert(final int idx
, final Cell newCell
) {
194 System
.arraycopy(chars
, idx
, chars
, idx
+ 1, chars
.length
- idx
- 1);
195 chars
[idx
] = new Cell(newCell
);
199 * Replace character at the specified position.
201 * @param idx the character index
202 * @param newCell the new Cell
204 public void replace(final int idx
, final Cell newCell
) {
205 chars
[idx
].setTo(newCell
);
209 * Set the Cell at the specified position to the blank (reset).
211 * @param idx the character index
213 public void setBlank(final int idx
) {
218 * Set the character (just the char, not the attributes) at the specified
221 * @param idx the character index
222 * @param ch the new char
224 public void setChar(final int idx
, final int ch
) {
225 chars
[idx
].setChar(ch
);
229 * Set the attributes (just the attributes, not the char) at the
230 * specified position to attr.
232 * @param idx the character index
233 * @param attr the new attributes
235 public void setAttr(final int idx
, final CellAttributes attr
) {
236 chars
[idx
].setAttr(attr
);
240 * Delete character at the specified position, filling in the new
241 * character on the right with newCell.
243 * @param idx the character index
244 * @param newCell the new Cell
246 public void delete(final int idx
, final Cell newCell
) {
247 System
.arraycopy(chars
, idx
+ 1, chars
, idx
, chars
.length
- idx
- 1);
248 chars
[chars
.length
- 1] = new Cell(newCell
);