1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
import os
import terminal
when defined(profile):
import nimprof
import client
import config/config
import utils/twtstr
readConfig()
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"""
if i == 0:
echo s
else:
eprint s
quit(i)
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
of "-v", "--version":
echo "Chawan browser v0.1 ",
when defined(debug): "(debug)" else: "(release)"
quit(0)
of "-T":
inc i
if i < params.len:
ctype = params[i]
else:
help(1)
of "-":
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 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)
|