about summary refs log tree commit diff stats
path: root/src/main.nim
blob: c4b76f8d627859a490c01f95e2e2dd7dc09c00cc (plain) (blame)
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
import os
import terminal

when defined(profile):
  import nimprof

import client
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:
    -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
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
  of "-dump":
    dump = true
  elif param[0] == '-':
    help(1)
  else:
    pages.add(param)
  inc i

if params.len == 0:
  if stdin.isatty:
    help(1)

newClient().launchClient(pages, ctype, dump)