about summary refs log tree commit diff stats
path: root/src/io/cell.nim
blob: 50094e8844f6940925ce6ea5328c6907777be016 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unicode

import types/color
import utils/twtstr

type
  Cell* = object of RootObj
    fgcolor*: CellColor
    bgcolor*: CellColor
    italic*: bool
    bold*: bool
    underline*: bool
    strike*: bool
    overline*: bool

  FlexibleCell* = object of Cell
    rune*: Rune

  FlexibleLine* = seq[FlexibleCell]

  FlexibleGrid* = seq[FlexibleLine]

  FixedCell* = object of Cell
    runes*: seq[Rune]

  FixedGrid* = seq[FixedCell]

proc setText*(grid: var FlexibleGrid, x: int, y: int, text: seq[Rune]) =
  while grid.len <= y:
    grid.add(newSeq[FlexibleCell]())

  while grid[y].len < x + text.len:
    grid[y].add(FlexibleCell())
  
  var i = 0
  while i < text.len:
    grid[y][i].rune = text[i]
    inc i

func newFixedGrid*(w: int, h: int = 1): FixedGrid =
  return newSeq[FixedCell](w * h)

func width*(line: FlexibleLine): int =
  for c in line:
    result += c.rune.width()