Skip to content

Commit b5b841b

Browse files
committed
Add hard wrap limit option to console
This change adds the following options to org.eclipse.debug.ui: * Console.limitLongLines (boolean) * Console.limitLongLinesWrap (boolean) * Console.limitLongLinesLength (int) When limitLongLines is set, long console lines will be trimmed or wrapped. If limitLongLinesWrap is set, lines are wrapped. Otherwise lines are trimmed. The length at which long lines are trimmed/wrapped is limitLongLinesLength. The preferences apply to output before its appended to the console document. In contrast, the existing console word wrapping is applied after the output is appended to the console document. Fixes: #2479
1 parent 0eda9f4 commit b5b841b

File tree

16 files changed

+742
-4
lines changed

16 files changed

+742
-4
lines changed

debug/org.eclipse.debug.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ Export-Package: org.eclipse.debug.tests,
3131
Import-Package: org.assertj.core.api;version="3.24.2",
3232
org.assertj.core.api.iterable,
3333
org.junit.jupiter.api;version="[5.14.0,6.0.0)",
34-
org.junit.jupiter.api.io;version="[5.14.0,6.0.0)",
3534
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
3635
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
36+
org.junit.jupiter.api.io;version="[5.14.0,6.0.0)",
3737
org.junit.jupiter.params;version="[5.14.0,6.0.0)",
38+
org.junit.jupiter.params.provider;version="[5.14.0,6.0.0)",
3839
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
3940
org.opentest4j;version="[1.3.0,2.0.0)"
4041
Eclipse-BundleShape: dir

debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import org.eclipse.debug.tests.breakpoint.BreakpointTests;
2020
import org.eclipse.debug.tests.breakpoint.SerialExecutorTest;
2121
import org.eclipse.debug.tests.console.ConsoleDocumentAdapterTests;
22-
import org.eclipse.debug.tests.console.ConsoleShowHideTests;
2322
import org.eclipse.debug.tests.console.ConsoleManagerTests;
23+
import org.eclipse.debug.tests.console.ConsoleOutputLineTruncateTest;
24+
import org.eclipse.debug.tests.console.ConsoleOutputLineWrapTest;
25+
import org.eclipse.debug.tests.console.ConsoleShowHideTests;
2426
import org.eclipse.debug.tests.console.ConsoleTests;
2527
import org.eclipse.debug.tests.console.FileLinkTests;
2628
import org.eclipse.debug.tests.console.IOConsoleFixedWidthTests;
@@ -122,6 +124,8 @@
122124
ConsoleManagerTests.class, //
123125
ConsoleTests.class, //
124126
IOConsoleTests.class, //
127+
ConsoleOutputLineWrapTest.class, //
128+
ConsoleOutputLineTruncateTest.class, //
125129
IOConsoleFixedWidthTests.class, //
126130
ProcessConsoleManagerTests.class, //
127131
ProcessConsoleTests.class, //
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Simeon Andreev and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Simeon Andreev - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.tests.console;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
18+
import java.util.Arrays;
19+
import java.util.stream.Stream;
20+
21+
import org.eclipse.ui.internal.console.ConsoleOutputLineTruncate;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.Arguments;
24+
import org.junit.jupiter.params.provider.MethodSource;
25+
26+
/**
27+
* Tests {@link ConsoleOutputLineTruncate} handling chunks of input, breaking
28+
* input lines at a specific length limit.
29+
*/
30+
public class ConsoleOutputLineTruncateTest {
31+
32+
/**
33+
* Parameters of a test for {@link ConsoleOutputLineTruncate}.
34+
*
35+
* @param limit the line length limit for the test
36+
* @param chunks how many times the {@code input} is repeated
37+
* @param repeat how many times {@code output} is repeated in the expected
38+
* output, line breaks are inserted between concatenated
39+
* {@code output}
40+
* @param input input string passed to the tested
41+
* {@link ConsoleOutputLineTruncate}
42+
* @param output expected output, repeated {@code repeat} times
43+
* @param nl the newline character sequences
44+
*/
45+
record Parameters(int limit, int chunks, int repeat, String input, String output, String... nl) {
46+
}
47+
48+
private static Parameters test(int limit, String input, String output, String... nl) {
49+
return test(limit, 1, 1, input, output, nl);
50+
}
51+
52+
private static Parameters test(int limit, int chunks, int repeat, String input, String output, String... nl) {
53+
return new Parameters(limit, chunks, repeat, input, output, nl);
54+
}
55+
56+
private static final Parameters[] TESTS = {
57+
// Unix newlines
58+
test(4, "\n========", "\n==== ...\n", "\n"),
59+
test(10, "========", "========", "\n"),
60+
test(10, 10, 1, "========", "========== ...\n", "\n"),
61+
test(4, "========", "==== ...\n", "\n"),
62+
test(4, 10, 1, "========", "==== ...\n", "\n"),
63+
test(4, "====\n====", "====\n====", "\n"),
64+
test(4, 5, 1, "====\n====", "====\n==== ...\n==== ...\n==== ...\n==== ...\n====", "\n"),
65+
test(2, 5, 1, "=======\n==", "== ...\n== ...\n== ...\n== ...\n== ...\n==", "\n"),
66+
test(2, "====\n====", "== ...\n== ...\n", "\n"),
67+
test(2, 5, 1, "====\n====", "== ...\n== ...\n== ...\n== ...\n== ...\n== ...\n", "\n"),
68+
test(2, "=========", "== ...\n", "\n"),
69+
test(2, "=======\n==", "== ...\n==", "\n"),
70+
test(3, "=========", "=== ...\n", "\n"),
71+
test(3, 5, 1, "=========", "=== ...\n", "\n"),
72+
test(3, "========\n=", "=== ...\n=", "\n"),
73+
test(2, "======\n======", "== ...\n== ...\n", "\n"),
74+
test(2, 5, 1, "======\n======", "== ...\n== ...\n== ...\n== ...\n== ...\n== ...\n", "\n"),
75+
test(3, 3, 1, "========\n=", "=== ...\n=== ...\n=== ...\n=" , "\n"),
76+
test(4, 3, 1, "========\n=", "==== ...\n==== ...\n==== ...\n=", "\n"),
77+
78+
// Windows newlines
79+
test(4, "\r\n========", "\r\n==== ...\r\n", "\r\n"),
80+
test(10, "========", "========", "\r\n"),
81+
test(10, 10, 1, "========", "========== ...\r\n", "\r\n"),
82+
test(4, "========", "==== ...\r\n", "\r\n"),
83+
test(4, 10, 1, "========", "==== ...\r\n", "\r\n"),
84+
test(4, "====\r\n====", "====\r\n====", "\r\n"),
85+
test(4, 5, 1, "====\r\n====", "====\r\n==== ...\r\n==== ...\r\n==== ...\r\n==== ...\r\n====", "\r\n"),
86+
test(2, 5, 1, "=======\r\n==", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n==", "\r\n"),
87+
test(2, "====\r\n====", "== ...\r\n== ...\r\n", "\r\n"),
88+
test(2, 5, 1, "====\r\n====", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n", "\r\n"),
89+
test(2, "=========", "== ...\r\n", "\r\n"),
90+
test(2, "=======\r\n==", "== ...\r\n==", "\r\n"),
91+
test(3, "=========", "=== ...\r\n", "\r\n"),
92+
test(3, 5, 1, "=========", "=== ...\r\n", "\r\n"),
93+
test(3, "========\r\n=", "=== ...\r\n=", "\r\n"),
94+
test(2, "======\r\n======", "== ...\r\n== ...\r\n", "\r\n"),
95+
test(2, 5, 1, "======\r\n======", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n", "\r\n"),
96+
test(3, 3, 1, "========\r\n=", "=== ...\r\n=== ...\r\n=== ...\r\n=", "\r\n"),
97+
test(4, 3, 1, "========\r\n=", "==== ...\r\n==== ...\r\n==== ...\r\n=", "\r\n"),
98+
99+
// multiple newlines
100+
test(3, 3, 1, "========\r\n=", "=== ...\r\n=== ...\r\n=== ...\r\n=", "\r\n", "\r", "\n"),
101+
test(4, 3, 1, "========\r\n=", "==== ...\r\n==== ...\r\n==== ...\r\n=", "\r\n", "\r", "\n"),
102+
test(3, 3, 1, "========\r\n=", "=== ...\r\n=== ...\r\n=== ...\r\n=", "\r", "\n", "\r\n"),
103+
test(4, 3, 1, "========\r\n=", "==== ...\r\n==== ...\r\n==== ...\r\n=", "\r", "\n", "\r\n"),
104+
};
105+
106+
private static Stream<Arguments> tests() {
107+
return Arrays.stream(TESTS).map(Arguments::of);
108+
}
109+
110+
@ParameterizedTest
111+
@MethodSource("tests")
112+
public void test(Parameters p) {
113+
ConsoleOutputLineTruncate truncate = new ConsoleOutputLineTruncate(p.limit, p.nl);
114+
StringBuilder c = new StringBuilder();
115+
for (int i = 0; i < p.chunks; ++i) {
116+
StringBuilder s = new StringBuilder(p.input);
117+
CharSequence text = truncate.modify(s);
118+
c.append(text);
119+
}
120+
String expected = repeat(p.output, p.repeat, p.nl[0]);
121+
assertEquals(expected, c.toString());
122+
}
123+
124+
private static String repeat(String s, int r, String nl) {
125+
return (nl + s).repeat(r).substring(nl.length());
126+
}
127+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Simeon Andreev and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Simeon Andreev - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.tests.console;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
18+
import java.util.Arrays;
19+
import java.util.stream.Stream;
20+
21+
import org.eclipse.ui.internal.console.ConsoleOutputLineWrap;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.Arguments;
24+
import org.junit.jupiter.params.provider.MethodSource;
25+
26+
/**
27+
* Tests {@link ConsoleOutputLineWrap} handling chunks of input, breaking input
28+
* lines at a specific length limit.
29+
*/
30+
public class ConsoleOutputLineWrapTest {
31+
32+
/**
33+
* Parameters of a test for {@link ConsoleOutputLineWrap}.
34+
*
35+
* @param limit the line length limit for the test
36+
* @param chunks how many times the {@code input} is repeated
37+
* @param repeat how many times {@code output} is repeated in the expected
38+
* output, line breaks are inserted between concatenated
39+
* {@code output}
40+
* @param input input string passed to the tested
41+
* {@link ConsoleOutputLineWrap}
42+
* @param output expected output, repeated {@code repeat} times
43+
* @param nl the newline character sequences
44+
*/
45+
record Parameters(int limit, int chunks, int repeat, String input, String output, String... nl) {
46+
}
47+
48+
private static Parameters test(int limit, String input, String output, String... nl) {
49+
return test(limit, 1, 1, input, output, nl);
50+
}
51+
52+
private static Parameters test(int limit, int chunks, String input, String output, String... nl) {
53+
return test(limit, chunks, chunks, input, output, nl);
54+
}
55+
56+
private static Parameters test(int limit, int chunks, int repeat, String input, String output, String... nl) {
57+
return new Parameters(limit, chunks, repeat, input, output, nl);
58+
}
59+
60+
private static final Parameters[] TESTS = {
61+
// Unix newlines
62+
test(4, "\n========", "\n====\n====", "\n"),
63+
64+
test(10, "========" , "========" , "\n"),
65+
test(10, 10, 8, "========" , "==========", "\n"),
66+
test( 4, "========" , "====\n====", "\n"),
67+
test( 4, 10, "========" , "====\n====", "\n"),
68+
test( 4, "====\n====" , "====\n====", "\n"),
69+
test( 4, 10, "====\n====" , "====\n====", "\n"),
70+
71+
test( 2, 10, "=======\n==" , "==\n==\n==\n=\n==", "\n"),
72+
test( 2, "====\n====" , "==\n==\n==\n==" , "\n"),
73+
test( 2, 10, "====\n====" , "==\n==\n==\n==" , "\n"),
74+
test( 2, "=========" , "==\n==\n==\n==\n=", "\n"),
75+
test( 2, "=======\n==" , "==\n==\n==\n=\n==", "\n"),
76+
test( 3, "=========" , "===\n===\n===" , "\n"),
77+
test( 3, 10, "=========" , "===\n===\n===" , "\n"),
78+
test( 3, "========\n=" , "===\n===\n==\n=" , "\n"),
79+
80+
test( 2, "======\n======", "==\n==\n==\n==\n==\n==", "\n"),
81+
test( 2, 10, "======\n======", "==\n==\n==\n==\n==\n==", "\n"),
82+
83+
test( 3, 3, 1, "========\n=" , "===\n===\n==\n===\n===\n===\n===\n===\n===\n=", "\n"),
84+
test( 4, 3, 1, "========\n=" , "====\n====\n====\n====\n=\n====\n====\n=\n=" , "\n"),
85+
86+
// Windows newlines
87+
test(4, "\r\n========", "\r\n====\r\n====", "\r\n"),
88+
89+
test(10, "========" , "========" , "\r\n"),
90+
test(10, 10, 8, "========" , "==========" , "\r\n"),
91+
test( 4, "========" , "====\r\n====", "\r\n"),
92+
test( 4, 10, "========" , "====\r\n====", "\r\n"),
93+
test( 4, "====\r\n====" , "====\r\n====", "\r\n"),
94+
test( 4, 10, "====\r\n====" , "====\r\n====", "\r\n"),
95+
96+
test( 2, 10, "=======\r\n==" , "==\r\n==\r\n==\r\n=\r\n==", "\r\n"),
97+
test( 2, "====\r\n====" , "==\r\n==\r\n==\r\n==" , "\r\n"),
98+
test( 2, 10, "====\r\n====" , "==\r\n==\r\n==\r\n==" , "\r\n"),
99+
test( 2, "=========" , "==\r\n==\r\n==\r\n==\r\n=", "\r\n"),
100+
test( 2, "=======\r\n==" , "==\r\n==\r\n==\r\n=\r\n==", "\r\n"),
101+
test( 3, "=========" , "===\r\n===\r\n===" , "\r\n"),
102+
test( 3, 10, "=========" , "===\r\n===\r\n===" , "\r\n"),
103+
test( 3, "========\r\n=" , "===\r\n===\r\n==\r\n=" , "\r\n"),
104+
105+
test( 2, "======\r\n======", "==\r\n==\r\n==\r\n==\r\n==\r\n==", "\r\n"),
106+
test( 2, 10, "======\r\n======", "==\r\n==\r\n==\r\n==\r\n==\r\n==", "\r\n"),
107+
108+
test( 3, 3, 1, "========\r\n=" , "===\r\n===\r\n==\r\n===\r\n===\r\n===\r\n===\r\n===\r\n===\r\n=", "\r\n"),
109+
test( 4, 3, 1, "========\r\n=" , "====\r\n====\r\n====\r\n====\r\n=\r\n====\r\n====\r\n=\r\n=" , "\r\n"),
110+
111+
// multiple newlines
112+
test( 3, 3, 1, "========\r\n=" , "===\r\n===\r\n==\r\n===\r\n===\r\n===\r\n===\r\n===\r\n===\r\n=", "\r\n", "\r", "\n"),
113+
test( 4, 3, 1, "========\r\n=" , "====\r\n====\r\n====\r\n====\r\n=\r\n====\r\n====\r\n=\r\n=" , "\r\n", "\r", "\n"),
114+
115+
test( 3, 3, 1, "========\r\n=" , "===\r===\r==\r\n===\r===\r===\r\n===\r===\r===\r\n=", "\r", "\n", "\r\n"),
116+
test( 4, 3, 1, "========\r\n=" , "====\r====\r\n====\r====\r=\r\n====\r====\r=\r\n=" , "\r", "\n", "\r\n"),
117+
};
118+
119+
private static Stream<Arguments> tests() {
120+
return Arrays.stream(TESTS).map(Arguments::of);
121+
}
122+
123+
@ParameterizedTest
124+
@MethodSource("tests")
125+
public void test(Parameters p) {
126+
ConsoleOutputLineWrap lineBreak = new ConsoleOutputLineWrap(p.limit, p.nl);
127+
StringBuilder c = new StringBuilder();
128+
for (int i = 0; i < p.chunks; ++i) {
129+
StringBuilder s = new StringBuilder(p.input);
130+
CharSequence text = lineBreak.modify(s);
131+
c.append(text);
132+
}
133+
String expected = repeat(p.output, p.repeat, p.nl[0]);
134+
assertEquals(expected, c.toString());
135+
}
136+
137+
private static String repeat(String s, int r, String nl) {
138+
return (nl + s).repeat(r).substring(nl.length());
139+
}
140+
}

0 commit comments

Comments
 (0)