Repository navigation
API turboframe.ui.editor
Source: turboframe/ui/editor.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.
The editor: a Textual TextArea with syntax colours, in a Turbo Vision window.
CodeEditor is a TextArea as a selectable Turbo Vision view: the current palette's colours (Options > Colors), Borland's block selection drawn over the syntax colours, Enter that keeps the indentation, Esc that stays in the editor, and the cursor revealed with its line in the middle. Over the syntax it draws a language server's diagnostics and the application's marks; in the gutter, git's changed lines and a debugger's breakpoints and current line. It hosts the completion list, a call's signature, a completion's documentation and a hover (turboframe.ui.completion), asking the application for them.
EditorWindow owns one file: the text it was read with (saved_text), the stamp of the file on disk (turboframe.files), and its editor. It is dirty while the editor's text differs from the saved one; its bottom border shows * 12:5. A window without a file is untitled (NONAME01). OutputWindow shows text read-only in Turbo Pascal's Output colours. LogWindow is an Output window that follows a log: the last LIMIT lines, the cursor at the end.
Textual's tree-sitter grammars colour the languages it knows when textual[syntax] is installed; their capture names are TurboFrame's token kinds (themes.treesitter_tokens).
EDITOR, OUTPUT, SELECTION, MARGIN_MARKS, COMPLETE_KEYS, LANGUAGES, theme_name, editor_theme, output_theme, all_themes, language_for, CodeEditor, EditorWindow, OutputWindow, LogWindow
'editor'
'output'
'turboframe.selection'
{'add': '+', 'del': '-', 'mod': '~'}
('ctrl+space', 'ctrl+@', 'ctrl+n')
dict (19 entries)
def theme_name(palette: themes.Palette, kind: str = 'editor') -> strdef editor_theme(p: themes.Palette) -> TextAreaThemeThe editor of a palette: Borland's yellow on blue in the Borland themes.
def output_theme(p: themes.Palette) -> TextAreaThemeTurbo Pascal's Output window: white on black in the Borland themes; plain text, but for the token kinds whose prefix is in OUTPUT_TOKENS.
def all_themes() -> list[TextAreaTheme]Every palette's editor and output themes (made once per colour mode).
def language_for(path: Path | None, languages: dict[str, str | None] = {'.py': 'python', '.xml': 'xml', '.js': 'javascript', '.css': 'css', '.json': 'json', '.md': 'markdown', '.yml': 'yaml', '.yaml': 'yaml', '.toml': 'toml', '.sql': 'sql', '.sh': 'bash', '.html': 'html', '.htm': 'html', '.go': 'go', '.rs': 'rust', '.java': 'java', '.rst': None, '.csv': None, '.txt': None}) -> str | NoneTextual's language for path's suffix (None: plain text).
class CodeEditor(TextArea, TVViewMixin)
CodeEditor(text: str, *, path: Path | None = None, read_only: bool = False, kind: str = 'editor', show_line_numbers: bool = True, classes: str | None = None)One file's text, highlighted, as a selectable Turbo Vision view.
What an application says about its languages are class attributes: LANGUAGES (a file's suffix to Textual's language name), SMART_LANGUAGES (the languages a language server knows: completion, signatures, hovers, Ctrl+click), NAVIGABLE (others where Ctrl+click still goes to a definition), BREAKPOINT_LANGUAGES (a click on a line number toggles a breakpoint) and INDENT_AFTER (a line ending in one of these indents the next one more: ":" for Python). register_languages() adds grammars Textual does not have.
The application gives the language server's answers through methods the editor looks for on it: lsp_complete(editor, explicit), lsp_document(editor, item), lsp_signature_changed(editor), lsp_go_to_definition(editor) and toggle_breakpoint_at(editor, row). Without them the editor is a plain one.
kind is EDITOR or OUTPUT (Turbo Pascal's Output window: its own colours).
-
path(property): The file this editor shows (its window's). -
intelligent(property): A language server knows this text: one ofSMART_LANGUAGES, editable. -
register_languages() -> None: Register the grammars Textual does not have (register_language); none by default. -
apply_palette() -> None: The colours of the current palette (Options > Colors). -
usable_language(language: str | None) -> str | None:language, or CSS for SCSS when the CSS grammar could not be registered asscss. -
set_path(path: Path | None) -> None: The file was renamed or moved (or saved as another): its language may change with it. -
set_diagnostics(diagnostics: list) -> None: The language server's errors and warnings (start,endoffsets andseverity), drawn over the syntax colours (diag.error,diag.warning). -
set_marks(marks: list[tuple[int, int, str]]) -> None: The application's marks:(start, end, token kind)offsets drawn over the syntax colours (a blamed line, a step of a trace). The kind is a registered token (themes.token). -
diagnostic_at(row: int, column: int): The diagnostic under (row, column), else the first one of the row. -
action_complete() -> None: Ctrl+Space, Ctrl+N or Edit > Complete: the list now, or a message saying why there is none. -
update_completion(explicit: bool = False) -> None: Asked to the language server; the answer comes back in show_completion. show_completion(result: CompletionResult | None, explicit: bool) -> Nonehide_completion() -> None-
show_signature(lines: list[str], mark: tuple[int, int, int] | None) -> None: Over the cursor's line (under it when there is no room above). hide_signature() -> None-
show_doc(lines: list[str]) -> None: Beside the completion list (on its left when there is no room on its right). -
show_hover(lines: list[str]) -> None: Under the cursor's line (over it when there is no room below); any key or move closes it. hide_hover() -> Nonehide_doc() -> Noneaccept_completion() -> None-
on_click(event: events.Click) -> None: Ctrl+click goes to the definition, after the click has placed the cursor (where the terminal reports the Ctrl key with the mouse: F12 always does the same). A click on a line number toggles the line's breakpoint (Ctrl+F8 does the same at the cursor). -
set_change_marks(rows: dict[int, str]) -> None: git's marks in the gutter: the line number on green (added), brown (changed) or red (lines removed just above). -
set_debug_marks(breakpoints: set[int], execution: int | None) -> None: The debugger's bars: the breakpoints' rows in red, the row about to run in cyan (0-based rows). -
reveal_cursor() -> None: The cursor in view with its line in the middle, and sideways only as far as needed. -
on_resize() -> None: A new size (the window zoomed, the desktop resized) right after a reveal, untouched since: reveal again, so that the line is in the middle of the size it ended with. Before, a reveal that ran before a zoom's layout centred on the old height (#68). -
go_to(row: int, column: int = 0, length: int = 0) -> None: Put the cursor at (row, column), selectinglengthcharacters on that line, and show it.
class EditorWindow(TVWindow)
EditorWindow(source: SourceFile | None = None, *, root: Path | None = None, number: int = 0, untitled: int = 0, read_only: bool = False)An editor for one file (source), or an untitled one (no source). The bottom border shows * 12:5 (modified, line:column).
EDITOR is the editor's class (an application's CodeEditor). root names the file relative to it in the title.
LF (False by default: the text is the file's, newlines included) set True makes the editor hold \n text whatever the file uses, and its save write the file's own newlines back (newline): an application whose offsets count \n newlines (a lexer, an outline) sets it. read(path) reads a file as it says. The application hears editor_changed(window) and cursor_moved(window), and the close icon asks it request_close(window) (to ask about unsaved changes), when it has them.
-
read(cls, path: Path) -> SourceFile:pathread for this window: as it is, or (LF) with\nnewlines and the file's innewline. refresh_indicator() -> Nonerelabel() -> None-
moved(path: Path) -> None: The file was renamed or moved (or an untitled one saved): the window follows it. -
saved(source: SourceFile) -> None: The file was written: what is on disk is now the editor's text.
class OutputWindow(TVWindow)
OutputWindow(title: str = '', number: int = 0)Text to read, not to edit (what a program printed, a rendered result), in the Output window's colours. show(title, text) replaces it.
show(title: str, text: str) -> None
class LogWindow(OutputWindow)
LogWindow(title: str = '', number: int = 0)What a program said, line by line (git, a package manager, a web server): read only, in the Output window's colours, at most LIMIT lines (the oldest go), the cursor on the last one. add(line) appends a line; set_lines(lines) replaces them all (a log kept elsewhere).
add(line: str) -> Noneset_lines(lines) -> None
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