add edit command
This commit is contained in:
parent
7b7dd9d811
commit
d6a7eec735
1 changed files with 23 additions and 9 deletions
|
|
@ -1,14 +1,16 @@
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from textual.app import App, ComposeResult
|
import subprocess
|
||||||
from textual.css.query import NoMatches
|
import tempfile
|
||||||
from textual.widgets import Header, Footer
|
|
||||||
|
|
||||||
from textual.containers import Container
|
|
||||||
from textual.widgets import Button, Header, Footer, Static
|
|
||||||
|
|
||||||
from textual.reactive import reactive
|
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.containers import Container
|
||||||
|
from textual.css.query import NoMatches
|
||||||
|
from textual.reactive import reactive
|
||||||
|
from textual.widgets import Button, Footer, Header, Static
|
||||||
|
import tomlkit
|
||||||
|
|
||||||
|
|
||||||
class TimeDisplay(Static):
|
class TimeDisplay(Static):
|
||||||
"""A widget to display elapsed time."""
|
"""A widget to display elapsed time."""
|
||||||
|
|
@ -86,6 +88,7 @@ class StopwatchApp(App):
|
||||||
("j", "next", "Next"),
|
("j", "next", "Next"),
|
||||||
("k", "prev", "Prev"),
|
("k", "prev", "Prev"),
|
||||||
("space", "toggle", "Toggle"),
|
("space", "toggle", "Toggle"),
|
||||||
|
("e", "edit", "Edit"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def on_mount(self):
|
def on_mount(self):
|
||||||
|
|
@ -112,6 +115,16 @@ class StopwatchApp(App):
|
||||||
def action_prev(self):
|
def action_prev(self):
|
||||||
self.activate(-1)
|
self.activate(-1)
|
||||||
|
|
||||||
|
def action_edit(self):
|
||||||
|
prompt = {"prompt": "this is the prompt"}
|
||||||
|
editor = os.environ.get("EDITOR", "vim")
|
||||||
|
file = tempfile.NamedTemporaryFile(prefix="lockhart", suffix=".toml")
|
||||||
|
file.write(tomlkit.dumps(prompt).encode())
|
||||||
|
file.seek(0)
|
||||||
|
proc = subprocess.Popen([editor, file.name])
|
||||||
|
proc.wait()
|
||||||
|
self.refresh()
|
||||||
|
|
||||||
def action_toggle(self):
|
def action_toggle(self):
|
||||||
try:
|
try:
|
||||||
active = self.query_one("Stopwatch.active")
|
active = self.query_one("Stopwatch.active")
|
||||||
|
|
@ -170,10 +183,11 @@ class StopwatchApp(App):
|
||||||
|
|
||||||
def tui():
|
def tui():
|
||||||
|
|
||||||
from textual.features import parse_features
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from textual.features import parse_features
|
||||||
|
|
||||||
dev = "--dev" in sys.argv
|
dev = "--dev" in sys.argv
|
||||||
features = set(parse_features(os.environ.get("TEXTUAL", "")))
|
features = set(parse_features(os.environ.get("TEXTUAL", "")))
|
||||||
if dev:
|
if dev:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue