Repository navigation
Log and Output Windows
Turbo Pascal showed what a program printed in its Output window: white on black, to read, not to edit. turboframe.ui.editor has two such windows:
-
OutputWindow: a text you replace whole: a program's whole output, a rendered result, a report. -
LogWindow: lines that keep coming (a build, git, a web server), bounded, following the last one.
| Use it for | showing what a command printed, or a log as it grows |
| Import | from turboframe.ui.editor import LogWindow, OutputWindow |
| Needs | nothing beyond TurboFrame |
| Extend | subclass it (LIMIT, the title); feed it from turboframe.process
|
Both are TVWindows (see Windows and Lists) holding a read-only CodeEditor (window.view): the user scrolls, selects and copies, but cannot type. Their colours are the theme's output-* roles (output-bg, output-frame...; see Themes and Colors).
OutputWindow(title="", number=0): the title is "Output" (in the interface's language) when you give none. show(title, text) replaces the title and the whole text.
from textual import work
from turboframe import process
from turboframe.ui.app import DesktopApp
from turboframe.ui.editor import OutputWindow
class MyApp(DesktopApp):
@work
async def lint(self, path) -> None:
done = await process.communicate("ruff", "check", str(path), timeout=30)
window = OutputWindow(number=self.free_number())
self.insert_window(window)
window.show(f"Output: ruff {path.name}", done.text() + done.text("err"))LogWindow(title="", number=0) keeps at most LIMIT lines (2000): when more come, the oldest go. The cursor stays on the last line, so the window shows the end as lines arrive.
| Member | |
|---|---|
add(line) |
append a line (without its newline) |
set_lines(lines) |
replace every line: a log kept elsewhere |
lines |
the lines it holds |
LIMIT |
the most lines it keeps; a subclass (or an instance) sets another |
The window is repainted after the next refresh, so adding many lines at once costs one repaint.
from turboframe.ui.editor import LogWindow
class BuildLog(LogWindow):
LIMIT = 10_000
def __init__(self, number: int = 0) -> None:
super().__init__("Build", number=number)The Git menu's "Git" window is a LogWindow (see Git and Diffs).
turboframe.process runs a command so that it ends with your application (see Processes). Two ways fit these windows:
process.run gives you each line as it comes, both streams together. Its callbacks run on the application's event loop, so they can write the window directly:
from textual import work
from turboframe import process
from turboframe.ui.app import DesktopApp
from turboframe.ui.editor import LogWindow
class MyApp(DesktopApp):
@work(group="build")
async def build(self) -> None:
log = LogWindow("Build", number=self.free_number())
self.insert_window(log)
try:
result = await process.run(["make", "all"], cwd=self.folder, on_line=log.add,
on_progress=self.hint, timeout=900, env=process.quiet_env())
except TimeoutError: # an OSError too: catch it first
log.add("-- stopped after 15 minutes")
except OSError as error:
log.add(f"-- make could not start: {error}")
else:
log.add(f"-- exit code {result.code}")-
on_progressreceives the lines a command rewrites in place (Receiving objects: 45%), which would flood a log; the status line's hint suits them. - Cancelling the worker (Esc in a progress box, the application closing) kills the command.
process.communicate waits for the end and gives the whole output at once, standard output and standard error apart (Output.out, Output.err, as bytes; text("out"), text("err"), decoded). Show it in an OutputWindow. Out of time, the command is killed, timed_out is True, and out and err are empty.
A thread of your own (a library that blocks) must not touch the window: hand each line to the event loop with self.call_from_thread(log.add, line).
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links