diff --git a/cli/build.gradle b/cli/build.gradle index 514b0d4..2b77736 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -11,7 +11,7 @@ dependencies { compile 'ch.qos.logback:logback-core:1.1.3' compile 'org.slf4j:slf4j-api:1.7.14' compile 'com.offbytwo:docopt:0.6.0.20150202' - compile 'com.jdbernard:jdb-util:4.3' + compile 'com.jdbernard:jdb-util:4.4' compile 'jline:jline:2.12' compile project(":wdiwtlt-core") compile 'uk.co.caprica:vlcj:3.10.1' diff --git a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/ScrollText.groovy b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/ScrollText.groovy index 705e294..e8f54d7 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/ScrollText.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/ScrollText.groovy @@ -1,11 +1,14 @@ package com.jdbernard.wdiwtlt.cli +import com.jdbernard.util.AnsiEscapeCodeSequence as ANSI + public class ScrollText { public String text = "" public int maxWidth private int scrollIdx + private String curAnsiPrefix = "" public void setMaxWidth(int max) { this.maxWidth = Math.max(max, 1) } @@ -15,17 +18,52 @@ public class ScrollText { this.scrollIdx = Math.max(0, text.size() - 10) } public String getNextScroll() { - if (text.size() < maxWidth) return text - else { - scrollIdx = (scrollIdx + 1) % text.size() - int endIdx = Math.min(scrollIdx + maxWidth, text.size()) - int wrapIdx = (scrollIdx + maxWidth) % text.size() + if (ANSI.strip(text).size() < maxWidth) return text - // don't need to wrap past the end - if (wrapIdx == endIdx) return text[scrollIdx.. 0 && wrapIdx < scrollIdx) { + def cur + if (endIdx == text.size()) { + cur = text[wrapIdx] + + if (cur == '\u001b') inAnsiSeq = true + + if (inAnsiSeq && Character.isLetter(cur.charAt(0))) + inAnsiSeq = false + + if (!inAnsiSeq) toWalk-- + wrapIdx++ } + + else { + cur = text[endIdx] + + if (cur == '\u001b') inAnsiSeq = true + + if (inAnsiSeq && Character.isLetter(cur.charAt(0))) + inAnsiSeq = false + + if (!inAnsiSeq) toWalk-- + endIdx++ } } + + if (wrapIdx == 0) return curAnsiPrefix + text[scrollIdx..