2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 package jexer
.tterminal
;
33 import jexer
.bits
.Cell
;
34 import jexer
.bits
.CellAttributes
;
37 * This represents a single line of the display buffer.
39 public final class DisplayLine
{
41 * Maximum line length.
43 private static final int MAX_LINE_LENGTH
= 256;
46 * The characters/attributes of the line.
48 private Cell
[] chars
;
51 * Get the Cell at a specific column.
53 * @param idx the character index
56 public Cell
charAt(final int idx
) {
61 * Get the length of this line.
70 * Double-width line flag.
72 private boolean doubleWidth
= false;
75 * Get double width flag.
77 * @return double width
79 public boolean isDoubleWidth() {
84 * Set double width flag.
86 * @param doubleWidth new value for double width flag
88 public void setDoubleWidth(final boolean doubleWidth
) {
89 this.doubleWidth
= doubleWidth
;
93 * Double height line flag. Valid values are:
97 * 1 = top half double height
98 * 2 = bottom half double height
101 private int doubleHeight
= 0;
104 * Get double height flag.
106 * @return double height
108 public int getDoubleHeight() {
113 * Set double height flag.
115 * @param doubleHeight new value for double height flag
117 public void setDoubleHeight(final int doubleHeight
) {
118 this.doubleHeight
= doubleHeight
;
122 * DECSCNM - reverse video. We copy the flag to the line so that
123 * reverse-mode scrollback lines still show inverted colors correctly.
125 private boolean reverseColor
= false;
128 * Get reverse video flag.
130 * @return reverse video
132 public boolean isReverseColor() {
137 * Set double-height flag.
139 * @param reverseColor new value for reverse video flag
141 public void setReverseColor(final boolean reverseColor
) {
142 this.reverseColor
= reverseColor
;
146 * Public constructor sets everything to drawing attributes.
148 * @param attr current drawing attributes
150 public DisplayLine(final CellAttributes attr
) {
151 chars
= new Cell
[MAX_LINE_LENGTH
];
152 for (int i
= 0; i
< chars
.length
; i
++) {
153 chars
[i
] = new Cell();
154 chars
[i
].setTo(attr
);
159 * Insert a character at the specified position.
161 * @param idx the character index
162 * @param newCell the new Cell
164 public void insert(final int idx
, final Cell newCell
) {
165 System
.arraycopy(chars
, idx
, chars
, idx
+ 1, chars
.length
- idx
- 1);
166 chars
[idx
] = newCell
;
170 * Replace character at the specified position.
172 * @param idx the character index
173 * @param newCell the new Cell
175 public void replace(final int idx
, final Cell newCell
) {
176 chars
[idx
].setTo(newCell
);
180 * Set the Cell at the specified position to the blank (reset).
182 * @param idx the character index
184 public void setBlank(final int idx
) {
189 * Set the character (just the char, not the attributes) at the specified
192 * @param idx the character index
193 * @param ch the new char
195 public void setChar(final int idx
, final char ch
) {
196 chars
[idx
].setChar(ch
);
200 * Set the attributes (just the attributes, not the char) at the
201 * specified position to attr.
203 * @param idx the character index
204 * @param attr the new attributes
206 public void setAttr(final int idx
, final CellAttributes attr
) {
207 chars
[idx
].setAttr(attr
);
211 * Delete character at the specified position, filling in the new
212 * character on the right with newCell.
214 * @param idx the character index
215 * @param newCell the new Cell
217 public void delete(final int idx
, final Cell newCell
) {
218 System
.arraycopy(chars
, idx
+ 1, chars
, idx
, chars
.length
- idx
- 1);
219 chars
[chars
.length
- 1] = newCell
;