Skip to content

Commit 34508dc

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 34508dc

File tree

16 files changed

+685
-4
lines changed

16 files changed

+685
-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: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 sequence
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(10, "========", "========", "\n"),
59+
test(10, 10, 1, "========", "========== ...\n", "\n"),
60+
test(4, "========", "==== ...\n", "\n"),
61+
test(4, 10, 1, "========", "==== ...\n", "\n"),
62+
test(4, "====\n====", "====\n====", "\n"),
63+
test(4, 5, 1, "====\n====", "====\n==== ...\n==== ...\n==== ...\n==== ...\n====", "\n"),
64+
test(2, 5, 1, "=======\n==", "== ...\n== ...\n== ...\n== ...\n== ...\n==", "\n"),
65+
test(2, "====\n====", "== ...\n== ...\n", "\n"),
66+
test(2, 5, 1, "====\n====", "== ...\n== ...\n== ...\n== ...\n== ...\n== ...\n", "\n"),
67+
test(2, "=========", "== ...\n", "\n"),
68+
test(2, "=======\n==", "== ...\n==", "\n"),
69+
test(3, "=========", "=== ...\n", "\n"),
70+
test(3, 5, 1, "=========", "=== ...\n", "\n"),
71+
test(3, "========\n=", "=== ...\n=", "\n"),
72+
test(2, "======\n======", "== ...\n== ...\n", "\n"),
73+
test(2, 5, 1, "======\n======", "== ...\n== ...\n== ...\n== ...\n== ...\n== ...\n", "\n"),
74+
test(3, 3, 1, "========\n=", "=== ...\n=== ...\n=== ...\n=" , "\n"),
75+
test(4, 3, 1, "========\n=", "==== ...\n==== ...\n==== ...\n=", "\n"),
76+
77+
// Windows newlines
78+
test(10, "========", "========", "\r\n"),
79+
test(10, 10, 1, "========", "========== ...\r\n", "\r\n"),
80+
test(4, "========", "==== ...\r\n", "\r\n"),
81+
test(4, 10, 1, "========", "==== ...\r\n", "\r\n"),
82+
test(4, "====\r\n====", "====\r\n====", "\r\n"),
83+
test(4, 5, 1, "====\r\n====", "====\r\n==== ...\r\n==== ...\r\n==== ...\r\n==== ...\r\n====", "\r\n"),
84+
test(2, 5, 1, "=======\r\n==", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n==", "\r\n"),
85+
test(2, "====\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", "\r\n"),
87+
test(2, "=========", "== ...\r\n", "\r\n"),
88+
test(2, "=======\r\n==", "== ...\r\n==", "\r\n"),
89+
test(3, "=========", "=== ...\r\n", "\r\n"),
90+
test(3, 5, 1, "=========", "=== ...\r\n", "\r\n"),
91+
test(3, "========\r\n=", "=== ...\r\n=", "\r\n"),
92+
test(2, "======\r\n======", "== ...\r\n== ...\r\n", "\r\n"),
93+
test(2, 5, 1, "======\r\n======", "== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n== ...\r\n", "\r\n"),
94+
test(3, 3, 1, "========\r\n=", "=== ...\r\n=== ...\r\n=== ...\r\n=", "\r\n"),
95+
test(4, 3, 1, "========\r\n=", "==== ...\r\n==== ...\r\n==== ...\r\n=", "\r\n"),
96+
};
97+
98+
private static Stream<Arguments> tests() {
99+
return Arrays.stream(TESTS).map(Arguments::of);
100+
}
101+
102+
@ParameterizedTest
103+
@MethodSource("tests")
104+
public void test(Parameters p) {
105+
ConsoleOutputLineTruncate truncate = new ConsoleOutputLineTruncate(p.nl);
106+
StringBuilder c = new StringBuilder();
107+
for (int i = 0; i < p.chunks; ++i) {
108+
StringBuilder s = new StringBuilder(p.input);
109+
CharSequence text = truncate.modify(s, p.limit);
110+
c.append(text);
111+
}
112+
String expected = repeat(p.output, p.repeat, p.nl);
113+
assertEquals(expected, c.toString());
114+
}
115+
116+
private static String repeat(String s, int r, String nl) {
117+
return (nl + s).repeat(r).substring(nl.length());
118+
}
119+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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 sequence
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(10, "========" , "========" , "\n"),
63+
test(10, 10, 8, "========" , "==========", "\n"),
64+
test( 4, "========" , "====\n====", "\n"),
65+
test( 4, 10, "========" , "====\n====", "\n"),
66+
test( 4, "====\n====" , "====\n====", "\n"),
67+
test( 4, 10, "====\n====" , "====\n====", "\n"),
68+
69+
test( 2, 10, "=======\n==" , "==\n==\n==\n=\n==", "\n"),
70+
test( 2, "====\n====" , "==\n==\n==\n==" , "\n"),
71+
test( 2, 10, "====\n====" , "==\n==\n==\n==" , "\n"),
72+
test( 2, "=========" , "==\n==\n==\n==\n=", "\n"),
73+
test( 2, "=======\n==" , "==\n==\n==\n=\n==", "\n"),
74+
test( 3, "=========" , "===\n===\n===" , "\n"),
75+
test( 3, 10, "=========" , "===\n===\n===" , "\n"),
76+
test( 3, "========\n=" , "===\n===\n==\n=" , "\n"),
77+
78+
test( 2, "======\n======", "==\n==\n==\n==\n==\n==", "\n"),
79+
test( 2, 10, "======\n======", "==\n==\n==\n==\n==\n==", "\n"),
80+
81+
test( 3, 3, 1, "========\n=" , "===\n===\n==\n===\n===\n===\n===\n===\n===\n=", "\n"),
82+
test( 4, 3, 1, "========\n=" , "====\n====\n====\n====\n=\n====\n====\n=\n=" , "\n"),
83+
84+
// Windows newlines
85+
test(10, "========" , "========" , "\r\n"),
86+
test(10, 10, 8, "========" , "==========" , "\r\n"),
87+
test( 4, "========" , "====\r\n====", "\r\n"),
88+
test( 4, 10, "========" , "====\r\n====", "\r\n"),
89+
test( 4, "====\r\n====" , "====\r\n====", "\r\n"),
90+
test( 4, 10, "====\r\n====" , "====\r\n====", "\r\n"),
91+
92+
test( 2, 10, "=======\r\n==" , "==\r\n==\r\n==\r\n=\r\n==", "\r\n"),
93+
test( 2, "====\r\n====" , "==\r\n==\r\n==\r\n==" , "\r\n"),
94+
test( 2, 10, "====\r\n====" , "==\r\n==\r\n==\r\n==" , "\r\n"),
95+
test( 2, "=========" , "==\r\n==\r\n==\r\n==\r\n=", "\r\n"),
96+
test( 2, "=======\r\n==" , "==\r\n==\r\n==\r\n=\r\n==", "\r\n"),
97+
test( 3, "=========" , "===\r\n===\r\n===" , "\r\n"),
98+
test( 3, 10, "=========" , "===\r\n===\r\n===" , "\r\n"),
99+
test( 3, "========\r\n=" , "===\r\n===\r\n==\r\n=" , "\r\n"),
100+
101+
test( 2, "======\r\n======", "==\r\n==\r\n==\r\n==\r\n==\r\n==", "\r\n"),
102+
test( 2, 10, "======\r\n======", "==\r\n==\r\n==\r\n==\r\n==\r\n==", "\r\n"),
103+
104+
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"),
105+
test( 4, 3, 1, "========\r\n=" , "====\r\n====\r\n====\r\n====\r\n=\r\n====\r\n====\r\n=\r\n=" , "\r\n"),
106+
};
107+
108+
private static Stream<Arguments> tests() {
109+
return Arrays.stream(TESTS).map(Arguments::of);
110+
}
111+
112+
@ParameterizedTest
113+
@MethodSource("tests")
114+
public void test(Parameters p) {
115+
ConsoleOutputLineWrap lineBreak = new ConsoleOutputLineWrap(p.nl);
116+
StringBuilder c = new StringBuilder();
117+
for (int i = 0; i < p.chunks; ++i) {
118+
StringBuilder s = new StringBuilder(p.input);
119+
CharSequence text = lineBreak.modify(s, p.limit);
120+
c.append(text);
121+
}
122+
String expected = repeat(p.output, p.repeat, p.nl);
123+
assertEquals(expected, c.toString());
124+
}
125+
126+
private static String repeat(String s, int r, String nl) {
127+
return (nl + s).repeat(r).substring(nl.length());
128+
}
129+
}

0 commit comments

Comments
 (0)