-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5485 from Textualize/textual-markup
Textual markup
- Loading branch information
Showing
94 changed files
with
4,918 additions
and
1,771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: "textual.content" | ||
--- | ||
|
||
::: textual.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: "textual.style" | ||
--- | ||
|
||
::: textual.style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Static | ||
|
||
TEXT1 = """\ | ||
Hello, [bold $text on $primary]World[/]! | ||
[@click=app.notify('Hello, World!')]Click me[/] | ||
""" | ||
|
||
TEXT2 = """\ | ||
Markup will [bold]not[/bold] be displayed. | ||
Tags will be left in the output. | ||
""" | ||
|
||
|
||
class ContentApp(App): | ||
CSS = """ | ||
Screen { | ||
Static { | ||
height: 1fr; | ||
} | ||
#text1 { background: $primary-muted; } | ||
#text2 { background: $error-muted; } | ||
} | ||
""" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Static(TEXT1, id="text1") | ||
yield Static(TEXT2, id="text2", markup=False) # (1)! | ||
|
||
|
||
if __name__ == "__main__": | ||
app = ContentApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from textual._markup_playground import MarkupPlayground | ||
|
||
if __name__ == "__main__": | ||
app = MarkupPlayground() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from rich.syntax import Syntax | ||
|
||
from textual.app import App, ComposeResult, RenderResult | ||
from textual.reactive import reactive | ||
from textual.widget import Widget | ||
|
||
|
||
class CodeView(Widget): | ||
"""Widget to display Python code.""" | ||
|
||
DEFAULT_CSS = """ | ||
CodeView { height: auto; } | ||
""" | ||
|
||
code = reactive("") | ||
|
||
def render(self) -> RenderResult: | ||
# Syntax is a Rich renderable that displays syntax highlighted code | ||
syntax = Syntax(self.code, "python", line_numbers=True, indent_guides=True) | ||
return syntax | ||
|
||
|
||
class CodeApp(App): | ||
"""App to demonstrate Rich renderables in Textual.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
with open(__file__) as self_file: | ||
code = self_file.read() | ||
code_view = CodeView() | ||
code_view.code = code | ||
yield code_view | ||
|
||
|
||
if __name__ == "__main__": | ||
app = CodeApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Static | ||
|
||
TEXT = """I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear.""" | ||
|
||
|
||
class WrapApp(App): | ||
CSS_PATH = "text_overflow.tcss" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Static(TEXT, id="static1") | ||
yield Static(TEXT, id="static2") | ||
yield Static(TEXT, id="static3") | ||
|
||
|
||
if __name__ == "__main__": | ||
app = WrapApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Static { | ||
height: 1fr; | ||
text-wrap: nowrap; | ||
} | ||
|
||
#static1 { | ||
text-overflow: clip; # Overflowing text is clipped | ||
background: red 20%; | ||
} | ||
#static2 { | ||
text-overflow: fold; # Overflowing text is folded on to the next line | ||
background: green 20%; | ||
} | ||
#static3 { | ||
text-overflow: ellipsis; # Overflowing text is truncated with an ellipsis | ||
background: blue 20%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Static | ||
|
||
TEXT = """I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear.""" | ||
|
||
|
||
class WrapApp(App): | ||
CSS_PATH = "text_wrap.tcss" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Static(TEXT, id="static1") | ||
yield Static(TEXT, id="static2") | ||
|
||
|
||
if __name__ == "__main__": | ||
app = WrapApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Static { | ||
height: 1fr; | ||
} | ||
|
||
#static1 { | ||
text-wrap: wrap; /* this is the default */ | ||
background: blue 20%; | ||
} | ||
#static2 { | ||
text-wrap: nowrap; /* disable wrapping */ | ||
background: green 20%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.