Skip to content

Commit

Permalink
Merge pull request #2 from hlaaftana/master
Browse files Browse the repository at this point in the history
Add better checking for multiple value equality
  • Loading branch information
genotrance authored May 14, 2018
2 parents a4c8df1 + 7470661 commit 62bc6e0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/snip.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ Flags:
proc help() =
echo HELP

for mode in MODES.keys():
echo " --" & mode & "\t\t" & MODES[mode]["name"]
for modeName, mode in MODES:
echo " --", modeName, "\t\t", mode["name"]

proc parseCli() =
let params = commandLineParams()
for param in params:
if param == "--debug":
DEBUG = true
elif param in @["-h", "--help", "-?", "/?", "/h"]:
elif param in ["-h", "--help", "-?", "/?", "/h"]:
help()
quit()
elif param == "--map":
Expand All @@ -49,13 +49,13 @@ proc parseCli() =
quit()
elif param == "--act":
echo "ACTIONS:"
for en in ACTIONS.items():
echo " " & $en
for en in ACTIONS:
echo " ", en
quit()
elif param == "--key":
echo "KEYS:"
for en in KEYS.items():
echo " " & $en
for en in KEYS:
echo " ", en
quit()
elif param.replace("--", "") in toSeq(MODES.keys):
MODE = param.replace("--", "")
Expand Down
2 changes: 1 addition & 1 deletion src/snip/buildmap.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var BKEYMAP = initTable[string, KEYS]()
var i = 0
echo "Press ESC for key-combos that don't get detected\n"
for en in KEYS.items():
if en in @[CTRL_C, CTRL_Q, CTRL_S, CTRL_Z]:
if en in {CTRL_C, CTRL_Q, CTRL_S, CTRL_Z}:
continue

stdout.write "Enter " & $en & ": "
Expand Down
2 changes: 1 addition & 1 deletion src/snip/gist.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ proc adjustUrl(url: string): string =
if "raw" notin parsed.path:
parsed.path &= "/raw"

if parsed.hostname in @["github.com", "www.github.com"]:
if parsed.hostname in ["github.com", "www.github.com"]:
parsed.path = parsed.path.replace("/blob/", "/raw/")

return $parsed
Expand Down
8 changes: 5 additions & 3 deletions src/snip/key.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ proc getDialogKey*(max=1, nl=true): string =
if ready:
if KEYMAP.hasKey(code):
let key = KEYMAP[code]
if key in [ENTER, CTRL_ENTER]:
case key
of ENTER, CTRL_ENTER:
return
elif key == BACKSPACE:
of BACKSPACE:
if result.len() != 0:
result = result.substr(0, result.len()-2)
eraseLeftDialog()
elif key in [ESC, CTRL_C]:
of ESC, CTRL_C:
return ""
else: discard
else:
if result.len() < max:
let rcode = code.parseInt().char
Expand Down
8 changes: 5 additions & 3 deletions src/snip/ui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ iterator tokenizer(chunk: string): string {.inline.} =
var squote = false
for ch in chunk:
if ch == '"':
if quote == false:
if not quote:
if tok != "":
yield tok
tok = ""
Expand All @@ -93,7 +93,7 @@ iterator tokenizer(chunk: string): string {.inline.} =
yield tok
tok = ""
elif ch == '\'':
if squote == false:
if not squote:
if tok != "":
yield tok
tok = ""
Expand All @@ -106,7 +106,9 @@ iterator tokenizer(chunk: string): string {.inline.} =
tok = ""
elif quote or squote:
tok &= ch
elif ch in "`-=[];,/~!@#$%^&*()_+{}:<>? ":
elif ch in {'`', '-', '=', '[', ']', ';', ',', '/', '~', '!',
'@', '#', '$', '%', '^', '&', '*', '(', ')', '_',
'+', '{', '}', ':', '<', '>', '?', ' '}:
if tok != "":
yield tok
tok = ""
Expand Down

0 comments on commit 62bc6e0

Please sign in to comment.