From 781ac333e503b72d5d6070af02269164806cc597 Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 14 Mar 2024 13:20:38 +0100 Subject: twtstr: fix deleteChars, do not remove space in replaceControls --- src/display/term.nim | 6 +----- src/utils/twtstr.nim | 12 ++++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/display/term.nim b/src/display/term.nim index 6358535f..cb96a385 100644 --- a/src/display/term.nim +++ b/src/display/term.nim @@ -407,11 +407,7 @@ proc processFormat*(term: Terminal, format: var Format, cellf: Format): string = proc setTitle*(term: Terminal, title: string) = if term.set_title: - let title = if Controls in title: - title.replaceControls() - else: - title - term.outfile.write(XTERM_TITLE(title)) + term.outfile.write(XTERM_TITLE(title.replaceControls())) proc enableMouse*(term: Terminal) = term.write(XTSHIFTESCAPE & SGRMOUSEBTNON) diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index fb77c807..6f40ae7b 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -611,28 +611,28 @@ proc expandPath*(path: string): string = return $p.pw_dir / path.substr(usr.len) return path -func deleteChars*(s: string, todel: set[char]): string = +func deleteChars*(s: string; todel: set[char]): string = var i = 0 block earlyret: - for j in 0 ..< s.len: - if s[j] in todel: + for j, c in s: + if c in todel: i = j break earlyret return s var rs = newStringOfCap(s.len - 1) for j in 0 ..< i: - rs[j] = s[j] + rs &= s[j] for j in i + 1 ..< s.len: if s[j] in todel: continue - rs[i] = s[j] + rs &= s[j] inc i return rs func replaceControls*(s: string): string = result = newStringOfCap(s.len) for c in s: - if c in Controls: + if c in Controls - {' '}: result &= '^' result &= c.getControlLetter() else: -- cgit 1.4.1-2-gfad0