Skip to content

Commit

Permalink
Add save tape command
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Rider committed Mar 18, 2021
1 parent af9e1f3 commit 0263a49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ Commands
- ``lookup``: enters ``LOOKUP`` mode
- ``output``: toggles Plover output on/off
- ``reset``: reconnects current ``machine``
- ``tape``: toggles paper tape display
- ``suggestions``: toggles suggestions display
- ``tape``: toggles paper tape display
- ``savetape``: saves content of tape to a file
- ``dictionaries``: configure dictionaries

- ``add``: add a dictionary by its file path
Expand Down
22 changes: 20 additions & 2 deletions plover_console_ui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@ def handle(self, words=None):
self.add_translation()
return True

class SaveTape(Command):
"""<filename> save contents of tape"""

def __init__(self, output, tape_buffer):
self.tape_buffer = tape_buffer
super().__init__("savetape", output)

def handle(self, words=None):
if not words:
self.output("Filename must be provided")
return True
else:
filename = normalize_path(' '.join(words))
with open(filename, 'a') as f:
f.write(self.tape_buffer.text)
self.output(f"Saved tape to {filename}")
return True

def build_commands(engine, layout):
output = layout.output_to_console
Expand All @@ -542,16 +559,17 @@ def build_commands(engine, layout):
Lookup(output, engine),
Output(output, engine),
ResetMachine(output, engine.reset_machine),
Tape(output, layout.toggle_tape, engine),
Suggestions(output, layout.toggle_suggestions, engine),
Tape(output, layout.toggle_tape, engine),
SaveTape(output, layout.tape.body.buffer),
Dictionaries(output, engine),
Machine(output, engine),
System(output, engine),
Configure(output, engine),
Command(
"colors",
output,
[
[
SetForegroundColor(output, engine),
SetBackgroundColor(output, engine),
],
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = plover_console_ui
version = 1.0.0
version = 1.1.0
description = Text User Interface for Plover
long_description = file: README.rst
author = Seth Rider
Expand Down

0 comments on commit 0263a49

Please sign in to comment.