diff options
author | bptato <nincsnevem662@gmail.com> | 2024-07-28 20:50:51 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-07-28 21:06:28 +0200 |
commit | 9653c35fb9a4398942ecb305835a95fbd87c433a (patch) | |
tree | 2db576e71cd89557592715d64ecb4fb4a46f8c66 /src/config | |
parent | dbf2e0e831ebaf8a0e6f375a8f423f87280e7862 (diff) | |
download | chawan-9653c35fb9a4398942ecb305835a95fbd87c433a.tar.gz |
buffer, pager, config: add meta-refresh + misc fixes
* buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/config.nim | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index 3d4a0217..3c733bc5 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -30,12 +30,20 @@ import utils/twtstr type ColorMode* = enum - cmMonochrome, cmANSI, cmEightBit, cmTrueColor + cmMonochrome = "monochrome" + cmANSI = "ansi" + cmEightBit = "eight-bit" + cmTrueColor = "true-color" - FormatMode* = set[FormatFlags] + MetaRefresh* = enum + mrNever = "never" + mrAlways = "always" + mrAsk = "ask" ImageMode* = enum - imNone = "none", imSixel = "sixel", imKitty = "kitty" + imNone = "none" + imSixel = "sixel" + imKitty = "kitty" ChaPathResolved* = distinct string @@ -65,6 +73,7 @@ type default_headers*: TableRef[string, string] insecure_ssl_no_verify*: Option[bool] autofocus*: Option[bool] + meta_refresh*: Option[MetaRefresh] OmniRule* = ref object match*: Regex @@ -116,8 +125,8 @@ type DisplayConfig = object color_mode* {.jsgetset.}: Option[ColorMode] - format_mode* {.jsgetset.}: Option[FormatMode] - no_format_mode* {.jsgetset.}: FormatMode + format_mode* {.jsgetset.}: Option[set[FormatFlag]] + no_format_mode* {.jsgetset.}: set[FormatFlag] image_mode* {.jsgetset.}: Option[ImageMode] alt_screen* {.jsgetset.}: Option[bool] highlight_color* {.jsgetset.}: ARGBColor @@ -148,6 +157,7 @@ type cookie* {.jsgetset.}: bool referer_from* {.jsgetset.}: bool autofocus* {.jsgetset.}: bool + meta_refresh* {.jsgetset.}: MetaRefresh Config* = ref object jsctx: JSContext @@ -326,11 +336,9 @@ proc parseConfigValue(ctx: var ConfigParser; x: var int32; v: TomlValue; k: string) proc parseConfigValue(ctx: var ConfigParser; x: var int64; v: TomlValue; k: string) -proc parseConfigValue(ctx: var ConfigParser; x: var Option[ColorMode]; - v: TomlValue; k: string) -proc parseConfigValue(ctx: var ConfigParser; x: var Option[FormatMode]; - v: TomlValue; k: string) -proc parseConfigValue(ctx: var ConfigParser; x: var FormatMode; v: TomlValue; +proc parseConfigValue(ctx: var ConfigParser; x: var ColorMode; v: TomlValue; + k: string) +proc parseConfigValue[T](ctx: var ConfigParser; x: var Option[T]; v: TomlValue; k: string) proc parseConfigValue(ctx: var ConfigParser; x: var ARGBColor; v: TomlValue; k: string) @@ -466,48 +474,21 @@ proc parseConfigValue(ctx: var ConfigParser; x: var int64; v: TomlValue; typeCheck(v, tvtInteger, k) x = v.i -proc parseConfigValue(ctx: var ConfigParser; x: var Option[ColorMode]; - v: TomlValue; k: string) = +proc parseConfigValue(ctx: var ConfigParser; x: var ColorMode; v: TomlValue; + k: string) = typeCheck(v, tvtString, k) - case v.s - of "auto": x = none(ColorMode) - of "monochrome": x = some(cmMonochrome) - of "ansi": x = some(cmANSI) - of "8bit", "eight-bit": x = some(cmEightBit) - of "24bit", "true-color": x = some(cmTrueColor) + let y = strictParseEnum[ColorMode](v.s) + if y.isSome: + x = y.get + # backwards compat + elif v.s == "8bit": + x = cmEightBit + elif v.s == "24bit": + x = cmTrueColor else: raise newException(ValueError, "unknown color mode '" & v.s & "' for key " & k) -proc parseConfigValue(ctx: var ConfigParser; x: var Option[FormatMode]; - v: TomlValue; k: string) = - typeCheck(v, {tvtString, tvtArray}, k) - if v.t == tvtString and v.s == "auto": - x = none(FormatMode) - else: - var y: FormatMode - ctx.parseConfigValue(y, v, k) - x = some(y) - -proc parseConfigValue(ctx: var ConfigParser; x: var FormatMode; v: TomlValue; - k: string) = - typeCheck(v, tvtArray, k) - for i in 0 ..< v.a.len: - let kk = k & "[" & $i & "]" - let vv = v.a[i] - typeCheck(vv, tvtString, kk) - case vv.s - 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) - proc parseConfigValue(ctx: var ConfigParser; x: var ARGBColor; v: TomlValue; k: string) = typeCheck(v, tvtString, k) @@ -560,14 +541,14 @@ proc parseConfigValue[T](ctx: var ConfigParser; x: var set[T]; v: TomlValue; typeCheck(v, {tvtString, tvtArray}, k) if v.t == tvtString: var xx: T - xx.parseConfigValue(v, k) + ctx.parseConfigValue(xx, v, k) x = {xx} else: x = {} for i in 0 ..< v.a.len: let kk = k & "[" & $i & "]" var xx: T - xx.parseConfigValue(v.a[i], kk) + ctx.parseConfigValue(xx, v.a[i], kk) x.incl(xx) proc parseConfigValue(ctx: var ConfigParser; x: var CSSConfig; v: TomlValue; |