diff options
author | bptato <nincsnevem662@gmail.com> | 2021-12-15 14:30:02 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-12-15 14:30:02 +0100 |
commit | 46ed9f5a9640bee2bcd54eaa6cb4646f2446e768 (patch) | |
tree | 8f6123fcb6bf57dc0a582146817d39f42b1aecdf /src | |
parent | 4360d3839bbb3303e82aabbe188805cb82c87eca (diff) | |
download | chawan-46ed9f5a9640bee2bcd54eaa6cb4646f2446e768.tar.gz |
Use bit fields in cell formatting
Diffstat (limited to 'src')
-rw-r--r-- | src/io/buffer.nim | 15 | ||||
-rw-r--r-- | src/io/cell.nim | 54 |
2 files changed, 52 insertions, 17 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 785945d5..cf81f66f 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -590,15 +590,15 @@ proc refreshTermAttrs*(buffer: Buffer): bool = func formatFromLine(line: CSSRowBox): Formatting = result.fgcolor = line.color.cellColor() if line.fontstyle in { FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE }: - result.italic = true + result.italic_on if line.fontweight > 500: - result.bold = true + result.bold_on if line.textdecoration == TEXT_DECORATION_UNDERLINE: - result.underline = true + result.underline_on if line.textdecoration == TEXT_DECORATION_OVERLINE: - result.overline = true + result.overline_on if line.textdecoration == TEXT_DECORATION_LINE_THROUGH: - result.strike = true + result.strike_on proc setRowBox(buffer: Buffer, line: CSSRowBox) = var r: Rune @@ -655,9 +655,6 @@ proc updateCursor(buffer: Buffer) = if buffer.lines.len == 0: buffer.cursory = 0 -#TODO this works, but reshape rearranges all CSS boxes which is a *very* -#resource-intensive operation, and a significant restructuring of the layout -#engine is needed to avoid this proc updateHover(buffer: Buffer) = let nodes = buffer.currentCell().nodes if nodes != buffer.prevnodes: @@ -754,8 +751,6 @@ proc renderDocument*(buffer: Buffer) = buffer.updateCursor() proc reshapeBuffer*(buffer: Buffer) = - #TODO - #buffer.statusmsg = newFixedGrid(buffer.width) if buffer.showsource: buffer.renderPlainText(buffer.source) else: diff --git a/src/io/cell.nim b/src/io/cell.nim index 0b991a0a..d4e67196 100644 --- a/src/io/cell.nim +++ b/src/io/cell.nim @@ -8,14 +8,17 @@ import utils/twtstr import html/dom type + FormatFlags* = enum + FLAG_ITALIC + FLAG_BOLD + FLAG_UNDERLINE + FLAG_STRIKE + FLAG_OVERLINE + Formatting* = object fgcolor*: CellColor bgcolor*: CellColor - italic*: bool - bold*: bool - underline*: bool - strike*: bool - overline*: bool + flags: set[FormatFlags] Cell* = object of RootObj formatting*: Formatting @@ -36,6 +39,43 @@ type FixedGrid* = seq[FixedCell] +func italic(formatting: Formatting): bool = FLAG_ITALIC in formatting.flags +func bold(formatting: Formatting): bool = FLAG_BOLD in formatting.flags +func underline(formatting: Formatting): bool = FLAG_UNDERLINE in formatting.flags +func strike(formatting: Formatting): bool = FLAG_STRIKE in formatting.flags +func overline(formatting: Formatting): bool = FLAG_OVERLINE in formatting.flags + +proc italic_on*(formatting: var Formatting) = formatting.flags.incl(FLAG_ITALIC) +proc italic_off*(formatting: var Formatting) = formatting.flags.excl(FLAG_ITALIC) + +proc bold_on*(formatting: var Formatting) = formatting.flags.incl(FLAG_BOLD) +proc bold_off*(formatting: var Formatting) = formatting.flags.excl(FLAG_BOLD) + +proc underline_on*(formatting: var Formatting) = formatting.flags.incl(FLAG_UNDERLINE) +proc underline_off*(formatting: var Formatting) = formatting.flags.excl(FLAG_UNDERLINE) + +proc strike_on*(formatting: var Formatting) = formatting.flags.incl(FLAG_STRIKE) +proc strike_off*(formatting: var Formatting) = formatting.flags.excl(FLAG_STRIKE) + +proc overline_on*(formatting: var Formatting) = formatting.flags.incl(FLAG_OVERLINE) +proc overline_off*(formatting: var Formatting) = formatting.flags.excl(FLAG_OVERLINE) + +proc `bold=`*(formatting: var Formatting, b: bool) = + if b: formatting.flags.incl(FLAG_BOLD) + else: formatting.flags.excl(FLAG_BOLD) + +proc `underline=`*(formatting: var Formatting, b: bool) = + if b: formatting.flags.incl(FLAG_UNDERLINE) + else: formatting.flags.excl(FLAG_UNDERLINE) + +proc `strike=`*(formatting: var Formatting, b: bool) = + if b: formatting.flags.incl(FLAG_STRIKE) + else: formatting.flags.excl(FLAG_STRIKE) + +proc `overline=`*(formatting: var Formatting, b: bool) = + if b: formatting.flags.incl(FLAG_OVERLINE) + else: formatting.flags.excl(FLAG_OVERLINE) + #TODO ????? func `==`*(a: FixedCell, b: FixedCell): bool = return a.formatting == b.formatting and @@ -175,7 +215,7 @@ proc parseAnsiCode*(formatting: var Formatting, buf: string, fi: int): int = of 1: formatting.bold = true of 3: - formatting.italic = true + formatting.italic_on of 4: formatting.underline = true of 9: @@ -183,7 +223,7 @@ proc parseAnsiCode*(formatting: var Formatting, buf: string, fi: int): int = of 22: formatting.bold = false of 23: - formatting.italic = false + formatting.italic_off of 29: formatting.strike = false of 30..37: |