Skip to content

Commit f712b51

Browse files
authored
Revert the use of Integer.MAX_VALUE for display colums when size is zero (fixes #982, see #975) (#1011)
1 parent 0de32ab commit f712b51

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

console/src/test/java/org/jline/widget/TailTipWidgetsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.jline.reader.LineReader;
1616
import org.jline.reader.impl.LineReaderImpl;
17+
import org.jline.terminal.Size;
1718
import org.jline.terminal.Terminal;
1819
import org.jline.terminal.impl.DumbTerminal;
1920
import org.jline.utils.InfoCmp.Capability;
@@ -34,6 +35,7 @@ private SupportedDumbTerminal() throws IOException {
3435
strings.put(Capability.save_cursor, "");
3536
strings.put(Capability.restore_cursor, "");
3637
strings.put(Capability.cursor_address, "");
38+
setSize(new Size(160, 50));
3739
}
3840
}
3941

reader/src/test/java/org/jline/reader/impl/LineReaderTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,16 @@ public void terminalLineInfiniteLoop() throws IOException {
203203
assertEquals("hello", read1);
204204
assertEquals("world", read2);
205205
}
206+
207+
@Test
208+
public void testNoBackspaceInOutputOnDumbTerminal() throws IOException {
209+
ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {'\n'});
210+
ByteArrayOutputStream out = new ByteArrayOutputStream();
211+
try (Terminal terminal = new DumbTerminal(in, out)) {
212+
LineReader r = new LineReaderImpl(terminal);
213+
r.readLine("123");
214+
String written = out.toString();
215+
assertEquals("123", written);
216+
}
217+
}
206218
}

terminal/src/main/java/org/jline/utils/Display.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void setDelayLineWrap(boolean v) {
6868

6969
public void resize(int rows, int columns) {
7070
if (rows == 0 || columns == 0) {
71-
columns = 1;
71+
columns = Integer.MAX_VALUE - 1;
7272
rows = 1;
7373
}
7474
if (this.rows != rows || this.columns != columns) {
@@ -209,7 +209,8 @@ public void update(List<AttributedString> newLines, int targetCursorPos, boolean
209209
cursorPos++;
210210
if (newLength == 0 || newLine.isHidden(0)) {
211211
// go to next line column zero
212-
rawPrint(new AttributedString(" \b"));
212+
rawPrint(' ');
213+
terminal.puts(Capability.key_backspace);
213214
} else {
214215
AttributedString firstChar = newLine.substring(0, 1);
215216
// go to next line column one
@@ -309,7 +310,8 @@ public void update(List<AttributedString> newLines, int targetCursorPos, boolean
309310
} else if (atRight) {
310311
if (this.wrapAtEol) {
311312
if (!fullScreen || (fullScreen && lineIndex < numLines)) {
312-
terminal.writer().write(" \b");
313+
rawPrint(' ');
314+
terminal.puts(Capability.key_backspace);
313315
cursorPos++;
314316
}
315317
} else {

terminal/src/main/java/org/jline/utils/Status.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public Status(Terminal terminal) {
4848
this.supported = terminal.getStringCapability(Capability.change_scroll_region) != null
4949
&& terminal.getStringCapability(Capability.save_cursor) != null
5050
&& terminal.getStringCapability(Capability.restore_cursor) != null
51-
&& terminal.getStringCapability(Capability.cursor_address) != null;
51+
&& terminal.getStringCapability(Capability.cursor_address) != null
52+
&& isValid(terminal.getSize());
5253
if (supported) {
5354
display = new MovingCursorDisplay(terminal);
5455
resize();
@@ -57,6 +58,10 @@ public Status(Terminal terminal) {
5758
}
5859
}
5960

61+
private boolean isValid(Size size) {
62+
return size.getRows() > 0 && size.getRows() < 1000 && size.getColumns() > 0 && size.getColumns() < 1000;
63+
}
64+
6065
public void close() {
6166
terminal.puts(Capability.save_cursor);
6267
terminal.puts(Capability.change_scroll_region, 0, display.rows - 1);

0 commit comments

Comments
 (0)