diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config/config.nim | 13 | ||||
-rw-r--r-- | src/io/buffer.nim | 4 | ||||
-rw-r--r-- | src/main.nim | 29 |
3 files changed, 37 insertions, 9 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index 6a3fcd62..43e661c3 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -134,6 +134,7 @@ proc parseConfig(config: var Config, dir: string, t: TomlValue) = if "page" in t: for k, v in t["page"].pairs: config.nmap[getRealKey(k)] = getAction(v.s) + if "line" in t: for k, v in t["line"].pairs: config.lemap[getRealKey(k)] = getLineAction(v.s) if "css" in t: @@ -150,8 +151,14 @@ proc parseConfig(config: var Config, dir: string, t: TomlValue) = if "inline" in css: config.stylesheet &= css["inline"].s +proc parseConfig(config: var Config, dir: string, stream: Stream) = + config.parseConfig(dir, parseToml(stream)) + +proc parseConfig*(config: var Config, dir: string, s: string) = + config.parseConfig(dir, newStringStream(s)) + proc staticReadConfig(): Config = - result.parseConfig("res", parseToml(newStringStream(staticRead"res/config.toml"))) + result.parseConfig("res", staticRead"res/config.toml") const defaultConfig = staticReadConfig() var gconfig* = defaultConfig @@ -159,7 +166,7 @@ var gconfig* = defaultConfig proc readConfig(dir: string) = let fs = newFileStream(dir / "config.toml") if fs != nil: - gconfig.parseConfig(dir, parseToml(fs)) + gconfig.parseConfig(dir, fs) proc getNormalAction*(s: string): TwtAction = if gconfig.nmap.hasKey(s): @@ -175,5 +182,3 @@ proc readConfig*() = when defined(debug): readConfig(getCurrentDir() / "res") readConfig(getConfigDir() / "chawan") - gconfig.nmap = constructActionTable(gconfig.nmap) - gconfig.lemap = constructActionTable(gconfig.lemap) diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 370e8209..67859b4a 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -318,7 +318,9 @@ proc refreshDisplay(buffer: Buffer) = inc y proc setCursorXB(buffer: Buffer, byte: int) = + assert byte < buffer.currentLine.len var b = buffer.currentCursorBytes() + assert b < buffer.currentLine.len, $buffer.cursory & " " & $b & " " & $buffer.currentLine.len var w = buffer.fromx + buffer.cursorx if b < byte: while b < byte: @@ -794,7 +796,7 @@ proc setStatusMessage*(buffer: Buffer, str: string) = buffer.nostatus = true proc lineInfo*(buffer: Buffer) = - buffer.setStatusMessage("line " & $(buffer.cursory + 1) & "/" & $buffer.numLines & " col " & $(buffer.cursorx + 1) & "/" & $buffer.currentLineWidth() & " cell width: " & $buffer.currentDisplayCell().width()) + buffer.setStatusMessage("line " & $(buffer.cursory + 1) & "/" & $buffer.numLines & " col " & $(buffer.cursorx + 1) & "/" & $buffer.currentLineWidth() & " x: " & $buffer.currentCursorBytes()) proc displayBufferSwapOutput(buffer: Buffer) = print(buffer.generateSwapOutput()) diff --git a/src/main.nim b/src/main.nim index c4b76f8d..1f895231 100644 --- a/src/main.nim +++ b/src/main.nim @@ -9,13 +9,15 @@ import config/config import utils/twtstr readConfig() -width_table = makewidthtable(gconfig.ambiguous_double) let params = commandLineParams() proc help(i: int) = let s = """ Usage: cha [options] [URL(s) or file(s)...] Options: + -d, --dump Print page to stdout + -c, --css <stylesheet> Pass stylesheet (e.g. -c 'a{color: blue}') + -o, --opt <config> Pass config options (e.g. -o 'page.q="QUIT"') -T, --type <type> Specify content mime type -v, --version Print version information -h, --help Print this page""" @@ -29,6 +31,8 @@ var i = 0 var ctype = "" var pages: seq[string] var dump = false +var opt_str = "" +var css_str = "" while i < params.len: let param = params[i] case param @@ -43,17 +47,34 @@ while i < params.len: else: help(1) of "-": - discard - of "-dump": + discard # emulate programs that accept - as stdin + of "-d", "--dump": dump = true + of "-c", "--css": + inc i + if i < params.len: + gconfig.stylesheet &= params[i] + else: + help(1) + of "-o", "--opt": + inc i + if i < params.len: + gconfig.parseConfig(getCurrentDir(), params[i]) + else: + help(1) elif param[0] == '-': help(1) else: pages.add(param) inc i -if params.len == 0: +if pages.len == 0: if stdin.isatty: help(1) +gconfig.nmap = constructActionTable(gconfig.nmap) +gconfig.lemap = constructActionTable(gconfig.lemap) + +width_table = makewidthtable(gconfig.ambiguous_double) + newClient().launchClient(pages, ctype, dump) |