|
|
|
@ -1,13 +1,37 @@ |
|
|
|
|
''' Interactive Python interpreter ''' |
|
|
|
|
|
|
|
|
|
from typing import MutableMapping, Any |
|
|
|
|
from typing import MutableMapping, Any, Callable, ContextManager, Dict, Optional |
|
|
|
|
|
|
|
|
|
import builtins |
|
|
|
|
import asyncio |
|
|
|
|
import ptpython.repl |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
from ptpython.repl import PythonRepl |
|
|
|
|
from prompt_toolkit.patch_stdout import patch_stdout as patch_stdout_context |
|
|
|
|
|
|
|
|
|
import zasd.config as config |
|
|
|
|
|
|
|
|
|
@asyncio.coroutine |
|
|
|
|
async def repl(): |
|
|
|
|
_globals = dict( |
|
|
|
|
config = DictObject(config.reference(), 'config')) |
|
|
|
|
|
|
|
|
|
_locals = dict(a = 'b') |
|
|
|
|
|
|
|
|
|
# Create REPL. |
|
|
|
|
_repl = PythonRepl( |
|
|
|
|
get_globals=lambda: _globals, |
|
|
|
|
get_locals=lambda: _locals, |
|
|
|
|
vi_mode=True) |
|
|
|
|
_repl.confirm_exit = False |
|
|
|
|
_repl.highlight_matching_parenthesis = True |
|
|
|
|
_repl.insert_blank_line_after_output = False |
|
|
|
|
try: |
|
|
|
|
with patch_stdout_context(): |
|
|
|
|
await _repl.run_async() |
|
|
|
|
except EOFError: |
|
|
|
|
quit() |
|
|
|
|
|
|
|
|
|
class DictObject: |
|
|
|
|
def __init__(self, dictionary: MutableMapping[str, Any], name): |
|
|
|
|
DictObject._dictionary = dictionary |
|
|
|
@ -47,16 +71,3 @@ class DictObject: |
|
|
|
|
obj[key], name, level + 1, path = path + [key]) |
|
|
|
|
strs.append(value) |
|
|
|
|
return '\n'.join(strs) |
|
|
|
|
|
|
|
|
|
@asyncio.coroutine |
|
|
|
|
def repl(): |
|
|
|
|
_globals = dict( |
|
|
|
|
config = DictObject(config.reference(), 'config') |
|
|
|
|
) |
|
|
|
|
_locals = dict() |
|
|
|
|
try: |
|
|
|
|
yield from ptpython.repl.embed( |
|
|
|
|
globals=_globals, locals=_locals, return_asyncio_coroutine=True, |
|
|
|
|
patch_stdout=True, vi_mode=True) |
|
|
|
|
except EOFError: |
|
|
|
|
asyncio.get_event_loop().stop() |