diff --git a/src/game/menu/MainMenu.java b/src/game/menu/MainMenu.java index c339aae..34392b4 100644 --- a/src/game/menu/MainMenu.java +++ b/src/game/menu/MainMenu.java @@ -78,7 +78,7 @@ public void appendTitleScreen() { " \\_/_| |_|_|\\___|_| |_| |_|_| |_| |_|\\__,_|" + System.lineSeparator(), SemanticColor.ITEM); out.appendln(); - out.appendln(" A Text Adventure Game"); + out.appendln(" A Text Adventure Game"); out.appendln(); // Cheese Quest // printLocation(" .---.\n" diff --git a/src/game/system/output/ConsolePrintBuffer.java b/src/game/system/output/ConsolePrintBuffer.java index c7dc475..0f8a553 100644 --- a/src/game/system/output/ConsolePrintBuffer.java +++ b/src/game/system/output/ConsolePrintBuffer.java @@ -205,34 +205,40 @@ public void append(String output, ConsoleColor consoleColor) { // VERSION 2 -- cleaner, but wrapping is slightly different, potentially doesn't work // for multiple line input text String[] words = output.split(" ", -1); -// out.print("[ Before" + cursorColumn + "]"); + // DEBUG START +// out.println("[ Before" + cursorColumn + "]"); // ArrayList a = new ArrayList(Arrays.asList(words)); -// out.print("[Length: " + output.length() + "]"); -// out.print(a); +// out.println("[Length: " + output.length() + "]"); +// out.println(a); // int visualLength = 0; -// for (String e : a) { -// visualLength += e.length(); +// out.print("Visual length: "); +// for (int i = 0; i < a.size(); i++) { +// visualLength += a.get(i).length(); +// out.print("(" + i + ") length:" + a.get(i).length() + "[" + a.get(i) + "], "); // } -// out.print("[Visual length: " + visualLength + "]"); -// out.print("[Tokens: " + words.length + "]"); +// out.println("[Visual length: " + visualLength + "]"); +// out.println("[Tokens: " + words.length + "]"); + // DEBUG END for (int i = 0; i < words.length; i++) { String word = words[i]; - if (word.equals("\n")) { - out.println(); - cursorColumn = 0; - } else if (words.equals("\r")) { - } else if (cursorColumn + word.length() > wrapWidth) { + boolean wordEndsWithNewline = word.endsWith(System.lineSeparator()); + if (wordEndsWithNewline) { + word = word.substring(0, word.length() - System.lineSeparator().length()); + } + + if (cursorColumn + word.length() > wrapWidth) { printDirect(System.lineSeparator() + word, consoleColor); cursorColumn = System.lineSeparator().length() + word.length(); - if (word.startsWith("\\")) { - cursorColumn--; - } - } - else { // Add space before word, if word is not itself a space + }else { // Add space before word, if word is not itself a space boolean addSpace = i == 0 || output.isEmpty(); printDirect((addSpace ? "" : " ") + word, consoleColor); cursorColumn += (addSpace ? 0 : 1) + word.length(); } + + if (wordEndsWithNewline) { + out.println(); + cursorColumn = 0; + } } if (output.endsWith(System.lineSeparator())) { cursorColumn = 0; diff --git a/src/test/TestTest.java b/src/test/TestTest.java index a8f2d54..dfc8a20 100644 --- a/src/test/TestTest.java +++ b/src/test/TestTest.java @@ -28,6 +28,8 @@ public static void main(String[] args) { String output = "\\" + System.lineSeparator(); c.appendln(output); + // Looks like line separator connects to the end of the previous element + // add to its visual size, without increasing the token size c.appendln("\\"); c.appendln(System.lineSeparator()); c.appendln("1 2 3");