about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-18 20:10:08 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-18 20:10:08 +0200
commit0bc76d47ac558896c9027727f9de0b4b262f6e24 (patch)
tree8538568acdbe01c487d743b820d0fd9de4523256 /src/utils/twtstr.nim
parent84a7c65b62e5ff322a23b91c2e80d517d41ed504 (diff)
downloadchawan-0bc76d47ac558896c9027727f9de0b4b262f6e24.tar.gz
lineedit: rewrite
The old lineedit system worked quite well in the original synchronous
model. However, because it needs access to the terminal, it has been
subtly broken ever since buffer updates are allowed while the user
is in line edit mode.

This is best observed in incremental search, where searching for a
bgcolor'ed text would result in the bgcolor bleeding into the line
editor box.

The new version is much simpler, and therefore less optimized. But
it can still take advantage of output optimization in the terminal
controller, and it is free of races (because we simply query the
current state from the pager and feed it into the main output grid).
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index f146b445..cd85d45c 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -1022,6 +1022,10 @@ func width*(s: seq[Rune]): int =
   for r in s:
     result += r.twidth(result)
 
+func notwidth*(s: string): int =
+  for r in s.runes:
+    result += r.width()
+
 func width*(s: seq[Rune], min, max: int): int =
   var i = min
   var mi = min(max, s.len)
@@ -1071,6 +1075,24 @@ func padToWidth*(str: string, size: int, schar = '$'): string =
         w += r.width
     result &= schar
 
+func deleteChars*(s: string, todel: set[char]): string =
+  var i = 0
+  block earlyret:
+    for j in 0 ..< s.len:
+      if s[j] in todel:
+        i = j
+        break earlyret
+    return s
+  var rs = newStringOfCap(s.len - 1)
+  for j in 0 ..< i:
+    rs[j] = s[j]
+  for j in i + 1 ..< s.len:
+    if s[j] in todel:
+      continue
+    rs[i] = s[j]
+    inc i
+  return rs
+
 #https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm
 proc makeCRLF*(s: string): string =
   result = newStringOfCap(s.len)