diff options
author | kiranbaktha <sundarambaktha@hotmail.com> | 2018-09-24 13:08:20 -0500 |
---|---|---|
committer | kiranbaktha <sundarambaktha@hotmail.com> | 2018-09-24 13:08:20 -0500 |
commit | 6b69843edc55a6325e29719865eb4f922330d0c7 (patch) | |
tree | 5baa87dff4e86df8b4553bf13f823d33a16ff74e | |
parent | 964cb9232fec6daba09fef55054c2cad58367c58 (diff) |
Issue #126 and add clear console feature
-rw-r--r-- | http_prompt/cli.py | 2 | ||||
-rw-r--r-- | http_prompt/completion.py | 1 | ||||
-rw-r--r-- | http_prompt/execution.py | 7 | ||||
-rw-r--r-- | http_prompt/lexer.py | 3 | ||||
-rw-r--r-- | http_prompt/output.py | 3 |
5 files changed, 13 insertions, 3 deletions
diff --git a/http_prompt/cli.py b/http_prompt/cli.py index 795abdd..f80e54b 100644 --- a/http_prompt/cli.py +++ b/http_prompt/cli.py @@ -48,7 +48,7 @@ def update_cookies(base_value, cookies): cookie = SimpleCookie(base_value) for k, v in cookies.items(): cookie[k] = v - return cookie.output(header='', sep=';').lstrip() + return str(cookie.output(header='', sep=';').lstrip()) class ExecutionListener(object): diff --git a/http_prompt/completion.py b/http_prompt/completion.py index 96af094..71219a3 100644 --- a/http_prompt/completion.py +++ b/http_prompt/completion.py @@ -10,6 +10,7 @@ from . import options as opt ROOT_COMMANDS = OrderedDict([ ('cd', 'Change URL/path'), + ('clear', 'Clear console screen'), ('curl', 'Preview curl command'), ('env', 'Print environment'), ('exec', 'Clear and load environment from a file'), diff --git a/http_prompt/execution.py b/http_prompt/execution.py index 960e77f..b13845c 100644 --- a/http_prompt/execution.py +++ b/http_prompt/execution.py @@ -33,7 +33,7 @@ grammar = r""" command = mutation / immutation mutation = concat_mut+ / nonconcat_mut - immutation = preview / action / ls / env / help / exit / exec / source / _ + immutation = preview / action / ls / env / help / exit / exec / source / clear / _ concat_mut = option_mut / full_quoted_mut / value_quoted_mut / unquoted_mut nonconcat_mut = cd / rm @@ -43,6 +43,7 @@ grammar = r""" urlpath = (~r"https?://" unquoted_string) / (!concat_mut !redir_out string) + clear = _ "clear" _ help = _ "help" _ exit = _ "exit" _ ls = _ "ls" _ (urlpath _)? (redir_out)? @@ -358,6 +359,10 @@ class ExecutionVisitor(NodeVisitor): self.context.should_exit = True return node + def visit_clear(self, node, children): + self.output.clear() + return node + def visit_mutkey(self, node, children): if isinstance(children[0], list): return children[0][1] diff --git a/http_prompt/lexer.py b/http_prompt/lexer.py index 782abfb..60b5025 100644 --- a/http_prompt/lexer.py +++ b/http_prompt/lexer.py @@ -46,7 +46,8 @@ class HttpPromptLexer(RegexLexer): (words(HTTP_METHODS, prefix='(?i)', suffix='(?!\S)(\s*)'), bygroups(Keyword, Text), combined('redir_out', 'urlpath')), - + + (r'(clear)(\s*)', bygroups(Keyword, Text), 'end'), (r'(exit)(\s*)', bygroups(Keyword, Text), 'end'), (r'(help)(\s)*', bygroups(Keyword, Text), 'end'), (r'(env)(\s*)', bygroups(Keyword, Text), diff --git a/http_prompt/output.py b/http_prompt/output.py index 88ab745..f1b8773 100644 --- a/http_prompt/output.py +++ b/http_prompt/output.py @@ -27,6 +27,9 @@ class Printer(object): def fileno(self): return sys.stdout.fileno() + def clear(self): + click.clear() + class TextWriter(object): """Wrap a file-like object, opened with 'wb' or 'ab', so it accepts text |