-
Notifications
You must be signed in to change notification settings - Fork 0
/
grepo.coffee
71 lines (55 loc) · 1.64 KB
/
grepo.coffee
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
grepo = window.grepo ||= {}
grepo.greetings =
[ " ___ ___ ___ ___ ___ "
, "| . | _| -_| . | . |"
, "|_ |_| |___| _|___|"
, "|___| |_| "
, " "
, "Search for projects in your favourite language which need *your* help!"
, " "
].join "\n"
grepo.match = (language) ->
if language is ""
grepo.LANGUAGES[0]
else
regex = new RegExp("^#{language}")
for candidate in grepo.LANGUAGES
return candidate if regex.test candidate
language
grepo.complete = (event, term) ->
if event.keyCode is 9 # Try to auto-complete on TAB.
command = term.get_command()
[command..., key, value] = command.split /\s+/
if key[0] isnt "-"
command.push key
# seems like we have a -fBAR case.
if value[0] is "-"
[key, value] = [value.substring(0, 2), value.substring(2)]
# okay, complete keyword
else
# query the server for the closest matching tag.
return
# complete an argument.
switch key
when "-n"
value = parseInt(value or "10", 10) * 2
when "-l"
value = grepo.match(value)
command.push key
command.push value
term.set_command command.join(" ")
return no
grepo.dispatch = (command, term) ->
[name, argv...] = command.split(/\s+/)
if name isnt "grepo"
term.error "command not found: #{name}"
else
$.getJSON "/opster/", argv: argv, (xhr) ->
term.error(xhr.stderr) if xhr.stderr
term.echo (xhr.stdout) if xhr.stdout
$ ->
$("body").terminal grepo.dispatch,
greetings: grepo.greetings
prompt: "$"
exit: false
keydown: grepo.complete