about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-08-02 21:36:57 +0200
committerbptato <nincsnevem662@gmail.com>2022-08-02 22:14:14 +0200
commit7de898bd05fd54f216009ebc3775a007fd92c417 (patch)
tree8ea375792a27977a79b5932bf6bc786b19b3ec5f /src/io
parent8f7eb1f7d0ec0cac610c5dcc73188fdbe1577def (diff)
downloadchawan-7de898bd05fd54f216009ebc3775a007fd92c417.tar.gz
Fix renderdocument setText etc.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/buffer.nim7
-rw-r--r--src/io/cell.nim47
2 files changed, 15 insertions, 39 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 4f434e5d..15853da7 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -1215,15 +1215,14 @@ proc drawBuffer*(buffer: Buffer) =
   var format = newFormat()
   for line in buffer.lines:
     if line.formats.len == 0:
-      print(line.str & "\r\n")
+      print(line.str & "\n")
     else:
       var x = 0
       var i = 0
       for f in line.formats:
         var outstr = ""
-        #TODO TODO TODO renderhtml has broken format outputting
         #assert f.pos < line.str.width(), "fpos " & $f.pos & "\nstr" & line.str & "\n"
-        while x < f.pos and i < line.str.len: #TODO x < f.pos should be enough
+        while x < f.pos:
           var r: Rune
           fastRuneAt(line.str, i, r)
           outstr &= r
@@ -1232,7 +1231,7 @@ proc drawBuffer*(buffer: Buffer) =
         print(format.processFormat(f.format))
       print(line.str.substr(i))
       print(format.processFormat(newFormat()))
-      print("\r\n")
+      print("\n")
 
 proc refreshBuffer*(buffer: Buffer, peek = false) =
   buffer.title = buffer.getTitle()
diff --git a/src/io/cell.nim b/src/io/cell.nim
index d8f3d23b..2faced78 100644
--- a/src/io/cell.nim
+++ b/src/io/cell.nim
@@ -28,6 +28,8 @@ type
     format*: Format
     node*: StyledNode
 
+  # A FormatCell *starts* a new terminal formatting context.
+  # If no FormatCell exists before a given cell, the default formatting is used.
   FormatCell* = object of Cell
     pos*: int
     computed*: ComputedFormat
@@ -71,7 +73,6 @@ template `strike=`*(f: var Format, b: bool) = flag_template f, b, FLAG_STRIKE
 template `overline=`*(f: var Format, b: bool) = flag_template f, b, FLAG_OVERLINE
 template `blink=`*(f: var Format, b: bool) = flag_template f, b, FLAG_BLINK
 
-#TODO ?????
 func `==`*(a: FixedCell, b: FixedCell): bool =
   return a.format == b.format and
     a.runes == b.runes and
@@ -89,6 +90,7 @@ func width*(cell: FixedCell): int =
 func newFormat*(): Format =
   return Format(fgcolor: defaultColor, bgcolor: defaultColor)
 
+# Get the first format cell after pos, if any.
 func findFormatN*(line: FlexibleLine, pos: int): int =
   var i = 0
   while i < line.formats.len:
@@ -111,46 +113,21 @@ func findNextFormat*(line: FlexibleLine, pos: int): FormatCell =
   else:
     result.pos = -1
 
-func subformats*(formats: seq[FormatCell], pos: int): seq[FormatCell] =
-  var i = 0
-  while i < formats.len:
-    if formats[i].pos >= pos:
-      if result.len == 0 and i > 0:
-        var f = formats[i - 1]
-        f.pos = 0
-        result.add(f)
-      var f = formats[i]
-      f.pos -= pos
-      result.add(f)
-    inc i
-
-  if result.len == 0 and i > 0:
-    var f = formats[i - 1]
-    f.pos = 0
-    result.add(f)
-
-proc setLen*(line: var FlexibleLine, len: int) =
-  for i in 0 ..< line.formats.len:
-    if line.formats[i].pos >= len:
-      line.formats.setLen(i)
-      break
-  line.str.setLen(len)
-  #line.formats = line.formats.filter((x) => x.pos < len)
-
-proc add*(a: var FlexibleLine, b: FlexibleLine) =
-  let l = a.str.len
-  a.formats.add(b.formats.map((x) => FormatCell(format: x.format, node: x.node, pos: l + x.pos)))
-  a.str &= b.str
-
 proc addLine*(grid: var FlexibleGrid) =
   grid.add(FlexibleLine())
 
+proc insertFormat*(line: var FlexibleLine, pos, i: int, format: Format, computed: ComputedFormat = nil) =
+  if computed == nil:
+    line.formats.insert(FormatCell(format: format, pos: pos), i)
+  else:
+    line.formats.insert(FormatCell(format: format, computed: computed, node: computed.node, pos: pos), i)
+
 proc addFormat*(line: var FlexibleLine, pos: int, format: Format) =
-  line.formats.add(FormatCell(format: format, pos: line.str.len))
+  line.formats.add(FormatCell(format: format, pos: pos))
 
 proc addFormat*(line: var FlexibleLine, pos: int, format: Format, computed: ComputedFormat) =
-  if computed != nil and line.formats.len > 0 and line.formats[^1].computed == computed and line.formats[^1].format.bgcolor != format.bgcolor:
-    return
+  #if computed != nil and line.formats.len > 0 and line.formats[^1].computed == computed and line.formats[^1].format.bgcolor != format.bgcolor:
+  #  return
   if computed == nil:
     line.formats.add(FormatCell(format: format, pos: pos))
   else: