Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Update tab-completion list after every command.
Browse files Browse the repository at this point in the history
This should make development easier.
  • Loading branch information
mgedmin committed Jan 28, 2012
1 parent 8094e75 commit 1e63f41
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion snakemud/interpreter.py
Expand Up @@ -7,7 +7,8 @@ class Interpreter(object):

@property
def command_list(self):
return sorted(name[3:] for name in dir(self) if name.startswith('do_'))
return sorted(name[3:] for name in dir(self) if name.startswith('do_')
and getattr(self, name).__doc__)

def interpret(self, command):
words = command.split()
Expand Down Expand Up @@ -36,6 +37,10 @@ def do_inventory(self, *args):
"""examine your inventory"""
return ("You're a snake! You're carrying nothing.")

def do_take(self, *args):
"""pick something up"""
return ("There's nothing here to take.")

def do_help(self, *args):
"""print help about available commands"""
return "\n".join([
Expand Down
6 changes: 6 additions & 0 deletions snakemud/static/js/jquery.terminal-0.4.6.js
Expand Up @@ -1910,6 +1910,12 @@ function get_stack(caller) {
name: function() {
return settings.name;
},
get_command_list: function(command_list) {
return interpreters.top().command_list;
},
set_command_list: function(command_list) {
interpreters.top().command_list = command_list;
},
push: function(_eval, options) {
if (!options.prompt || valid('prompt', options.prompt)) {
if (typeof _eval == 'string') {
Expand Down
1 change: 1 addition & 0 deletions snakemud/templates/index.mako
Expand Up @@ -14,6 +14,7 @@
$.post(${request.route_url("api_command")|js,n}, {c: command}, function(data){
term.echo(data.response);
term.echo('\n');
term.set_command_list(data.command_list);
});
}, {
greetings: ${greeting|js,n} + '\n\n',
Expand Down
3 changes: 2 additions & 1 deletion snakemud/views.py
Expand Up @@ -25,5 +25,6 @@ def command(request):
command = request.params.get('c')
response = interpreter.interpret(command)
request.session.save() # interpreter may have changed its state
return {'response': response}
return {'response': response,
'command_list': interpreter.command_list}

0 comments on commit 1e63f41

Please sign in to comment.