Commit 35587ea6 authored by Jose Tiago Macara Coutinho's avatar Jose Tiago Macara Coutinho Committed by Jose Tiago Macara Coutinho
Browse files

shell: extensible REPL configuration to setup

parent a870a651
......@@ -32,7 +32,7 @@ from gevent import select
import time
import signal
import functools
from bliss.shell import initialize, ScanListener
from bliss.shell import initialize, ScanListener, REPL_CONFIGS
from bliss.config import static
class GeventEventLoop(EventLoop):
......@@ -226,6 +226,12 @@ def main():
finally:
CURRENT_TASK = None
repl._execute = patched_execute
for configure in REPL_CONFIGS:
try:
configure(repl)
except:
sys.excepthook(*sys.exc_info())
def stop_current_task(signum, frame, exception=gevent.GreenletExit):
if CURRENT_TASK:
......
......@@ -53,6 +53,32 @@ def initialize(*session_names):
return user_ns,sessions
REPL_CONFIGS = []
def repl_config(func):
"""
Register decorated function to be called by ptpython's configure.
Here is an example on how to do it in your setup file::
from bliss.shell import repl_config
@repl_config
def configure(repl):
# Use the classic prompt. (Display '>>>' instead of 'In [1]'.)
repl.prompt_style = 'classic' # 'classic' or 'ipython'
Args:
func (callable): a callable with one argument: the repl
Returns:
the same func callable
"""
global REPL_CONFIGS
if func not in REPL_CONFIGS:
REPL_CONFIGS.append(func)
return func
def _find_unit(obj):
try:
if hasattr(obj, 'unit'):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment