@@ -138,8 +138,8 @@ class Repl(
138138 multilineBuffer.clear()
139139 handleMetaCommand(trimmed)
140140
141- // Backslash commands: \h, \q, \t, etc.
142- case _ if firstChar == 104 =>
141+ // Backslash commands: JLine strips the leading \ and delivers just the letter(s)
142+ case _ if backslashCommands.contains(firstWord) =>
143143 multilineBuffer.clear()
144144 handleBackslashCommand(trimmed)
145145
@@ -572,17 +572,20 @@ class Repl(
572572 private def formatLigne (value : String , size : Int ): String = {
573573 // Supprime les espaces en début et fin de ligne
574574 val trimmedValue = value.trim
575+ val visibleLength = stripAnsi(trimmedValue).length
575576
576577 // Vérifie la longueur du texte
577- if (trimmedValue.length > size) {
578+ if (visibleLength > size) {
578579 // Si le texte est trop long, le tronquer avec '...'
579580 trimmedValue.take(size - 3 ) + " ..."
580581 } else {
581582 // Sinon, on complète avec des espaces
582- trimmedValue + " " * (size - trimmedValue.length )
583+ trimmedValue + " " * (size - visibleLength )
583584 }
584585 }
585586
587+ private def stripAnsi (s : String ): String = s.replaceAll(" \u001B\\ [[;\\ d]*m" , " " )
588+
586589 private def printGoodbyeBanner (): Unit = {
587590 println(s " \n ${emoji(" 👋" )} ${cyan(" Goodbye!" )}\n " )
588591 }
0 commit comments