Skip to content

Commit

Permalink
add option to override internal repl theme (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: brian crabtree <tehn@monome.org>
  • Loading branch information
daveriedstra and tehn authored Jun 22, 2021
1 parent ba1e640 commit 2a44381
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/druid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def clearscript():

@cli.command()
@click.argument("filename", type=click.Path(exists=True), required=False)
def repl(filename):
@click.option("--theme/--no-theme", default=True, show_default=True,
help="Whether to use the internal color theme.")
def repl(filename, theme):
""" Start interactive terminal """
druid_repl.main(filename)
druid_repl.main(filename, theme)
31 changes: 18 additions & 13 deletions src/druid/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
last_script = ''

class DruidUi:
def __init__(self):
def __init__(self, use_theme):
self.statusbar = Window(
height=1,
char='/',
Expand Down Expand Up @@ -82,14 +82,18 @@ def __init__(self):
def quit_druid(event):
event.app.exit()

self.style = Style([
('capture-field', '#747369'),
('output-field', '#d3d0c8'),
('input-field', '#f2f0ec'),
('line', '#747369'),
('scrollbar.background', 'bg:#000000'),
('scrollbar.button', 'bg:#747369'),
])
if use_theme:
self.style = Style([
('capture-field', '#747369'),
('output-field', '#d3d0c8'),
('input-field', '#f2f0ec'),
('line', '#747369'),
('scrollbar.background', 'bg:#000000'),
('scrollbar.button', 'bg:#747369'),
])
else:
self.style = Style([])

self.layout = Layout(self.container)

self.app = Application(
Expand Down Expand Up @@ -338,9 +342,9 @@ def pagedown(self, event, field):


class Druid:
def __init__(self, crow):
def __init__(self, crow, use_theme):
self.crow = crow
self.ui = DruidUi()
self.ui = DruidUi(use_theme)
self.repl = DruidRepl(ui=self.ui, crow=crow)

self.ui.add_page('repl', self.repl)
Expand Down Expand Up @@ -390,7 +394,7 @@ async def background(self):
},
}

def main(script=None):
def main(script=None, use_theme=True):
try:
logging.config.dictConfig(log_config)
except ValueError:
Expand All @@ -400,7 +404,8 @@ def main(script=None):
use_asyncio_event_loop()
with patch_stdout():
with Crow() as crow:
shell = Druid(crow)
shell = Druid(crow, use_theme)

server = DruidServer(shell.repl, 'localhost', 6666)
crow.reconnect(err_event=True)
background_task = asyncio.gather(
Expand Down

0 comments on commit 2a44381

Please sign in to comment.