about summary refs log tree commit diff stats
path: root/src/render
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-12-26 22:17:24 +0100
committerbptato <nincsnevem662@gmail.com>2021-12-26 22:17:24 +0100
commit647089a99e3c44c4115274a8822ca0a4dd947d67 (patch)
tree1fa85f4e12676ef8532ff2c9eaaa065a0bcd263a /src/render
parent9c688a75adcd647723a993f04cb964d62e7f05a4 (diff)
downloadchawan-647089a99e3c44c4115274a8822ca0a4dd947d67.tar.gz
Proper URL handling
Diffstat (limited to 'src/render')
-rw-r--r--src/render/rendertext.nim58
1 files changed, 42 insertions, 16 deletions
diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim
index a421f509..4c6b56ec 100644
--- a/src/render/rendertext.nim
+++ b/src/render/rendertext.nim
@@ -1,3 +1,5 @@
+import streams
+
 import io/cell
 import utils/twtstr
 
@@ -6,35 +8,59 @@ proc renderPlainText*(text: string): FlexibleGrid =
   template add_format() =
     if af:
       af = false
-      result.addFormat(y, result[y].str.len, format)
+      result.addFormat(result.high, result[^1].str.len, format)
 
+  result.addLine()
   var i = 0
-  var x = 0
-  var y = 0
   var af = false
   while i < text.len:
-    if text[i] == '\n':
+    case text[i]
+    of '\n':
       if i != text.len - 1:
         add_format
         result.addLine()
-        inc y
-        x = 0
-      inc i
-    elif text[i] == '\r':
-      inc i
-    elif text[i] == '\t':
+    of '\r': discard
+    of '\t':
       add_format
       for i in 0..8:
         result[^1].str &= ' '
-      inc i
-    elif text[i] == '\e':
+    of '\e':
       i = format.parseAnsiCode(text, i)
       af = true
     elif text[i].isControlChar():
       add_format
-      result[y].str &= '^' & text[i].getControlLetter()
-      inc i
+      result[^1].str &= '^' & text[i].getControlLetter()
+    else:
+      add_format
+      result[^1].str &= text[i]
+    inc i
+
+proc renderStream*(stream: Stream): FlexibleGrid =
+  var format = newFormatting()
+  template add_format() =
+    if af:
+      af = false
+      result.addFormat(result.high, result[^1].str.len, format)
+
+  result.addLine()
+  var af = false
+  while not stream.atEnd():
+    let c = stream.readChar()
+    case c
+    of '\n':
+      add_format
+      result.addLine()
+    of '\r': discard
+    of '\t':
+      add_format
+      for i in 0..8:
+        result[^1].str &= ' '
+    of '\e':
+      format.parseAnsiCode(stream)
+      af = true
+    elif c.isControlChar():
+      add_format
+      result[^1].str &= '^' & c.getControlLetter()
     else:
       add_format
-      result[y].str &= text[i]
-      inc i
+      result[^1].str &= c