tuitorial.app module#
Top-level package for tuitorial.
- class tuitorial.Chapter(title, code, steps)[source]#
Bases:
ContainerA chapter of a tutorial, containing multiple steps.
- can_focus: bool = False#
Widget may receive focus.
- can_focus_children: bool = True#
Widgetβs children may receive focus.
- class tuitorial.Focus(pattern, style=Style(color=Color('yellow', ColorType.STANDARD, number=3), bold=True), type=FocusType.LITERAL, extra=None)[source]#
Bases:
objectA pattern to focus on with its style.
-
style:
Style= Style(color=Color('yellow', ColorType.STANDARD, number=3), bold=True)#
-
type:
FocusType= 1#
- classmethod literal(text, style=Style(color=Color('yellow', ColorType.STANDARD, number=3), bold=True), *, word_boundary=False, match_index=None)[source]#
Create a focus for a literal string.
- Parameters:
text (
str) β The text to matchstyle (
Style) β The style to apply to the matched textword_boundary (
bool) β If True, only match the text when it appears as a wordmatch_index (
Union[int,list[int],None]) β If provided, only highlight the nth match (0-based) or matches specified by the list. If None, highlight all matches.
- Return type:
- classmethod regex(pattern, style=Style(color=Color('green', ColorType.STANDARD, number=2), bold=True), flags=re.MULTILINE)[source]#
Create a focus for a regular expression.
- Return type:
- classmethod line(line_number, style=Style(color=Color('cyan', ColorType.STANDARD, number=6), bold=True))[source]#
Create a focus for a line number.
- Return type:
- classmethod range(start, end, style=Style(color=Color('magenta', ColorType.STANDARD, number=5), bold=True))[source]#
Create a focus for a range of characters.
- Return type:
- classmethod startswith(text, style=Style(color=Color('blue', ColorType.STANDARD, number=4), bold=True), *, from_start_of_line=False)[source]#
Create a focus for text that starts with the given pattern.
- classmethod between(start_pattern, end_pattern, style=Style(color=Color('blue', ColorType.STANDARD, number=4), bold=True), *, inclusive=True, multiline=True, match_index=None, greedy=False)[source]#
Create a focus for text between two patterns.
- Parameters:
start_pattern (
str) β The pattern marking the start of the regionend_pattern (
str) β The pattern marking the end of the regionstyle (
Style) β The style to apply to the matched textinclusive (
bool) β If True, include the start and end patterns in the highlightingmultiline (
bool) β If True, match across multiple linesmatch_index (
Optional[int]) β If provided, only highlight the nth match (0-based). If None, highlight all matches.greedy (
bool) β If True, use greedy matching (matches longest possible string). If False, use non-greedy matching (matches shortest possible string).
- Return type:
- classmethod line_containing(pattern, style=Style(color=Color('yellow', ColorType.STANDARD, number=3), bold=True), *, lines_before=0, lines_after=0, regex=False, match_index=None)[source]#
Select the entire line containing a pattern and optionally surrounding lines.
- Parameters:
pattern (
str) β The text pattern to search for.style (
Style|str) β The style to apply to the matched lines.lines_before (
int) β Number of lines to include before the matched line.lines_after (
int) β Number of lines to include after the matched line.regex (
bool) β If True, treat pattern as a regular expression.match_index (
Optional[int]) β If provided, only highlight the nth match (0-based). If None, highlight all matches.
- Return type:
- classmethod syntax(lexer='python', *, theme=None, line_numbers=False, start_line=None, end_line=None)[source]#
Use Richβs syntax highlighting.
- Parameters:
lexer (
str) β The language to use for syntax highlighting (default: βpythonβ)theme (
Optional[str]) β The color theme to use (default: None, uses terminal colors)line_numbers (
bool) β Whether to show line numbersstart_line (
Optional[int]) β First line to highlight (0-based), if None highlight from startend_line (
Optional[int]) β Last line to highlight (0-based), if None highlight until end
- Return type:
-
style:
- class tuitorial.ImageStep(description, image, width=None, height=None, halign=None)[source]#
Bases:
objectA step that displays an image.
- class tuitorial.Step(description: str, focuses: list[Focus])[source]#
Bases:
NamedTupleA single step in a tutorial, containing a description and focus patterns.
- class tuitorial.TitleSlide(title, subtitle=None, font='ansi_shadow', gradient='lava')[source]#
Bases:
ContainerA title slide with ASCII art and centered text.
- can_focus: bool = False#
Widget may receive focus.
- can_focus_children: bool = True#
Widgetβs children may receive focus.
- class tuitorial.TuitorialApp(chapters, title_slide=None, initial_chapter=None, initial_step=0)[source]#
Bases:
AppA Textual app for presenting code tutorials.
- CSS: ClassVar[str] = '\n Tabs {\n dock: top;\n }\n\n TabPane {\n padding: 1 1;\n }\n\n CodeDisplay {\n height: auto;\n margin: 1;\n background: $surface;\n color: $text;\n border: solid $primary;\n padding: 1;\n }\n\n #description {\n height: auto;\n margin: 1;\n background: $surface-darken-1;\n color: $text;\n border: solid $primary;\n padding: 1;\n }\n\n ContentContainer {\n height: auto;\n }\n\n #image-container {\n align: center middle;\n height: auto;\n }\n\n #image {\n width: auto;\n height: auto;\n }\n\n #title-container {\n align: center middle;\n }\n\n #title-rich-log {\n overflow-y: auto;\n background: black 0%;\n width: auto;\n height: auto;\n /* When removing the border, the whole thing is gone? */\n border: solid green 0%;\n }\n\n #markdown-container {\n height: 1fr;\n }\n\n '#
Inline CSS, useful for quick scripts. This is loaded after CSS_PATH, and therefore takes priority in the event of a specificity clash.
-
BINDINGS:
ClassVar[list[Binding]] = [Binding(key='q', action='quit', description='Quit', show=True, key_display=None, priority=False, tooltip='', id=None, system=False), Binding(key='down', action='next_focus', description='Next Focus', show=True, key_display=None, priority=False, tooltip='', id=None, system=False), Binding(key='up', action='previous_focus', description='Previous Focus', show=True, key_display=None, priority=False, tooltip='', id=None, system=False), Binding(key='d', action='toggle_dim', description='Toggle Dim', show=True, key_display=None, priority=False, tooltip='', id=None, system=False), ('r', 'reset_focus', 'Reset Focus')]# The default key bindings.
- async set_chapter(chapter_index, *, nearest=False)[source]#
Set the current chapter and update the display.
- Return type: