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/io/cell.nim | |
parent | 4360d3839bbb3303e82aabbe188805cb82c87eca (diff) | |
download | chawan-46ed9f5a9640bee2bcd54eaa6cb4646f2446e768.tar.gz |
Use bit fields in cell formatting
Diffstat (limited to 'src/io/cell.nim')
-rw-r--r-- | src/io/cell.nim | 54 |
1 files changed, 47 insertions, 7 deletions
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: |