aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/config.nim14
-rw-r--r--src/layout/renderdocument.nim12
-rw-r--r--src/local/pager.nim2
-rw-r--r--src/local/select.nim4
-rw-r--r--src/local/term.nim30
-rw-r--r--src/types/cell.nim40
6 files changed, 45 insertions, 57 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index b22b532e..432f5875 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -460,13 +460,13 @@ proc parseConfigValue(ctx: var ConfigParser; x: var FormatMode; v: TomlValue;
let vv = v.a[i]
typeCheck(vv, VALUE_STRING, kk)
case vv.s
- of "bold": x.incl(FLAG_BOLD)
- of "italic": x.incl(FLAG_ITALIC)
- of "underline": x.incl(FLAG_UNDERLINE)
- of "reverse": x.incl(FLAG_REVERSE)
- of "strike": x.incl(FLAG_STRIKE)
- of "overline": x.incl(FLAG_OVERLINE)
- of "blink": x.incl(FLAG_BLINK)
+ of "bold": x.incl(ffBold)
+ of "italic": x.incl(ffItalic)
+ of "underline": x.incl(ffUnderline)
+ of "reverse": x.incl(ffReverse)
+ of "strike": x.incl(ffStrike)
+ of "overline": x.incl(ffOverline)
+ of "blink": x.incl(ffBlink)
else:
raise newException(ValueError, "unknown format mode '" & vv.s &
"' for key " & kk)
diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim
index ef82931d..2162776f 100644
--- a/src/layout/renderdocument.nim
+++ b/src/layout/renderdocument.nim
@@ -56,17 +56,17 @@ func toFormat(computed: CSSComputedValues): Format =
return Format()
var flags: set[FormatFlags]
if computed{"font-style"} in {FONT_STYLE_ITALIC, FONT_STYLE_OBLIQUE}:
- flags.incl(FLAG_ITALIC)
+ flags.incl(ffItalic)
if computed{"font-weight"} > 500:
- flags.incl(FLAG_BOLD)
+ flags.incl(ffBold)
if TEXT_DECORATION_UNDERLINE in computed{"text-decoration"}:
- flags.incl(FLAG_UNDERLINE)
+ flags.incl(ffUnderline)
if TEXT_DECORATION_OVERLINE in computed{"text-decoration"}:
- flags.incl(FLAG_OVERLINE)
+ flags.incl(ffOverline)
if TEXT_DECORATION_LINE_THROUGH in computed{"text-decoration"}:
- flags.incl(FLAG_STRIKE)
+ flags.incl(ffStrike)
if TEXT_DECORATION_BLINK in computed{"text-decoration"}:
- flags.incl(FLAG_BLINK)
+ flags.incl(ffBlink)
return Format(
fgcolor: computed{"color"},
flags: flags
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 3b75155c..98e29a39 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -371,7 +371,7 @@ proc refreshStatusMsg*(pager: Pager) =
pager.writeStatusMessage(pager.alerts[0])
pager.alerts.delete(0)
else:
- var format = Format(flags: {FLAG_REVERSE})
+ var format = Format(flags: {ffReverse})
pager.alertState = pasNormal
container.clearHover()
var msg = $(container.cursory + 1) & "/" & $container.numLines & " (" &
diff --git a/src/local/select.nim b/src/local/select.nim
index bfa3faf8..a02aa1a4 100644
--- a/src/local/select.nim
+++ b/src/local/select.nim
@@ -288,10 +288,10 @@ proc drawSelect*(select: Select, display: var FixedGrid) =
var x = sx
let dls = y * display.width
if k < select.selected.len and select.selected[k] == i:
- format.reverse = true
+ format.flags.incl(ffReverse)
inc k
else:
- format.reverse = false
+ format.flags.excl(ffReverse)
while j < select.options[i].len:
fastRuneAt(select.options[i], j, r)
let rw = r.twidth(x)
diff --git a/src/local/term.nim b/src/local/term.nim
index 996a8508..a5ae3567 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -219,17 +219,17 @@ proc startFormat(term: Terminal, flag: FormatFlags): string =
when termcap_found:
if term.isatty():
case flag
- of FLAG_BOLD: return term.cap md
- of FLAG_UNDERLINE: return term.cap us
- of FLAG_REVERSE: return term.cap mr
- of FLAG_BLINK: return term.cap mb
- of FLAG_ITALIC: return term.cap ZH
+ of ffBold: return term.cap md
+ of ffUnderline: return term.cap us
+ of ffReverse: return term.cap mr
+ of ffBlink: return term.cap mb
+ of ffItalic: return term.cap ZH
else: discard
return SGR(FormatCodes[flag].s)
proc endFormat(term: Terminal, flag: FormatFlags): string =
when termcap_found:
- if flag == FLAG_UNDERLINE and term.isatty():
+ if flag == ffUnderline and term.isatty():
return term.cap ue
return SGR(FormatCodes[flag].e)
@@ -503,21 +503,21 @@ proc showCursor*(term: Terminal) =
func emulateOverline(term: Terminal): bool =
term.config.display.emulate_overline and
- FLAG_OVERLINE notin term.formatmode and FLAG_UNDERLINE in term.formatmode
+ ffOverline notin term.formatmode and ffUnderline in term.formatmode
proc writeGrid*(term: Terminal, grid: FixedGrid, x = 0, y = 0) =
for ly in y ..< y + grid.height:
for lx in x ..< x + grid.width:
let i = ly * term.canvas.width + lx
term.canvas[i] = grid[(ly - y) * grid.width + (lx - x)]
- let isol = FLAG_OVERLINE in term.canvas[i].format.flags
+ let isol = ffOverline in term.canvas[i].format.flags
if i >= term.canvas.width and isol and term.emulateOverline:
let w = grid[(ly - y) * grid.width + (lx - x)].width()
let s = i - term.canvas.width
var j = s
while j < term.canvas.len and j < s + w:
let cell = addr term.canvas[j]
- cell.format.flags.incl(FLAG_UNDERLINE)
+ cell.format.flags.incl(ffUnderline)
if cell.str == "":
cell.str = " "
if cell.str == " ":
@@ -821,7 +821,7 @@ proc detectTermAttributes(term: Terminal, windowOnly: bool): TermStartResult =
if qaRGB in r.attrs:
term.colormode = TRUE_COLOR
# just assume the terminal doesn't choke on these.
- term.formatmode = {FLAG_STRIKE, FLAG_OVERLINE}
+ term.formatmode = {ffStrike, ffOverline}
if r.bgcolor.isSome:
term.defaultBackground = r.bgcolor.get
if r.fgcolor.isSome:
@@ -841,15 +841,15 @@ proc detectTermAttributes(term: Terminal, windowOnly: bool): TermStartResult =
if term.tc != nil:
term.smcup = term.hascap ti
if term.hascap(ZH):
- term.formatmode.incl(FLAG_ITALIC)
+ term.formatmode.incl(ffItalic)
if term.hascap(us):
- term.formatmode.incl(FLAG_UNDERLINE)
+ term.formatmode.incl(ffUnderline)
if term.hascap(md):
- term.formatmode.incl(FLAG_BOLD)
+ term.formatmode.incl(ffBold)
if term.hascap(mr):
- term.formatmode.incl(FLAG_REVERSE)
+ term.formatmode.incl(ffReverse)
if term.hascap(mb):
- term.formatmode.incl(FLAG_BLINK)
+ term.formatmode.incl(ffBlink)
else:
term.smcup = true
term.formatmode = {low(FormatFlags)..high(FormatFlags)}
diff --git a/src/types/cell.nim b/src/types/cell.nim
index d66743c0..cca9618b 100644
--- a/src/types/cell.nim
+++ b/src/types/cell.nim
@@ -3,13 +3,13 @@ import utils/strwidth
type
FormatFlags* = enum
- FLAG_BOLD
- FLAG_ITALIC
- FLAG_UNDERLINE
- FLAG_REVERSE
- FLAG_STRIKE
- FLAG_OVERLINE
- FLAG_BLINK
+ ffBold
+ ffItalic
+ ffUnderline
+ ffReverse
+ ffStrike
+ ffOverline
+ ffBlink
Format* = object
fgcolor*: CellColor
@@ -46,27 +46,15 @@ proc len*(grid: FixedGrid): int = grid.cells.len
proc high*(grid: FixedGrid): int = grid.cells.high
const FormatCodes*: array[FormatFlags, tuple[s, e: uint8]] = [
- FLAG_BOLD: (1u8, 22u8),
- FLAG_ITALIC: (3u8, 23u8),
- FLAG_UNDERLINE: (4u8, 24u8),
- FLAG_REVERSE: (7u8, 27u8),
- FLAG_STRIKE: (9u8, 29u8),
- FLAG_OVERLINE: (53u8, 55u8),
- FLAG_BLINK: (5u8, 25u8),
+ ffBold: (1u8, 22u8),
+ ffItalic: (3u8, 23u8),
+ ffUnderline: (4u8, 24u8),
+ ffReverse: (7u8, 27u8),
+ ffStrike: (9u8, 29u8),
+ ffOverline: (53u8, 55u8),
+ ffBlink: (5u8, 25u8),
]
-template flag_template(format: Format, val: bool, flag: FormatFlags) =
- if val: format.flags.incl(flag)
- else: format.flags.excl(flag)
-
-template `italic=`*(f: var Format, b: bool) = flag_template f, b, FLAG_ITALIC
-template `bold=`*(f: var Format, b: bool) = flag_template f, b, FLAG_BOLD
-template `underline=`*(f: var Format, b: bool) = flag_template f, b, FLAG_UNDERLINE
-template `reverse=`*(f: var Format, b: bool) = flag_template f, b, FLAG_REVERSE
-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
-
func newFixedGrid*(w: int, h: int = 1): FixedGrid =
return FixedGrid(width: w, height: h, cells: newSeq[FixedCell](w * h))