Fri, 19 Jan 2024 21:03:34 +0100
allow custom line breaks in help text
relates to #315
--- a/src/main/java/de/unixwork/uwproj/Feature.java Fri Jan 19 20:48:26 2024 +0100 +++ b/src/main/java/de/unixwork/uwproj/Feature.java Fri Jan 19 21:03:34 2024 +0100 @@ -144,7 +144,6 @@ // Prepare the description by replacing some unwanted spaces final var hdesc = desc.trim() .replaceAll("\\r", "") - .replaceAll("\\n", " ") .replaceAll("\\t", " "); // Declare our frame where the description shall be placed @@ -165,6 +164,9 @@ // get the next word and see where we would end int s = hdesc.indexOf(' ', i); if (s < 0) s = hdesc.length(); + int n = hdesc.indexOf('\n', i); + if (n < 0) n = hdesc.length(); + s = Math.min(s, n); int l = s-i; if (x + l > endx) { // does not fit, break into next line @@ -177,11 +179,27 @@ x += l; i += l; // append the next spaces - while (i < hdesc.length() && hdesc.charAt(i) == ' ') { - i++; - x++; - // as long as we don't need to break, add the spaces - if (x < endx) builder.append(' '); + while (i < hdesc.length()) { + int c = hdesc.charAt(i); + if (c == ' ') { + // as long as we don't need to break, add the spaces + i++; + x++; + if (x < endx) builder.append(' '); + } else if (c == '\n') { + // if user wants us to break, comply + i++; + // if we have still space, just move to the end of the line + if (x < endx) { + x = endx; + } else { + // otherwise, we need to add an extra blank line + builder.append('\n'); + } + } else { + // we have found the next word, so continue with the outer loop + break; + } } // break to new line, when spaces moved us outside the frame if (x > endx) {
--- a/test/configure2 Fri Jan 19 20:48:26 2024 +0100 +++ b/test/configure2 Fri Jan 19 21:03:34 2024 +0100 @@ -76,8 +76,11 @@ --toolkit=(gtk3|cli|gtk2|wpf) Optional Features: - --disable-db Needlessly adds a completely useless SQLite - database. + --disable-db Needlessly adds a completely useless SQLite database + by default. + Here another line to test tabs and line + + breaks. --enable-gui __EOF__
--- a/test/make/project2.xml Fri Jan 19 20:48:26 2024 +0100 +++ b/test/make/project2.xml Fri Jan 19 21:03:34 2024 +0100 @@ -47,8 +47,10 @@ <target name="dav"> <feature name="db" default="true"> <desc> - Needlessly adds a completely - useless SQLite database. + Needlessly adds a completely useless SQLite database by default. + Here another line to test tabs and line + + breaks. </desc> <dependencies>sqlite</dependencies> <define name="DATABASE"/>