-
Notifications
You must be signed in to change notification settings - Fork 18
Draft: Implement command widgets to textual CLI #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
67d139f
a6b4280
bb57f01
f72c635
79f739f
e87cc09
c00a1e3
1b650d1
d9d7315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,9 @@ venv.bak/ | |
.dmypy.json | ||
dmypy.json | ||
|
||
# Pycharm | ||
.idea/ | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,3 @@ repos: | |
rev: 23.3.0 | ||
hooks: | ||
- id: black | ||
language_version: python3.7 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import random | ||
from statistics import mean | ||
|
||
from textual.app import ComposeResult | ||
from textual.containers import Container, Center, Middle | ||
from textual.widgets import ( | ||
DirectoryTree, | ||
Footer, | ||
Header, | ||
Input, | ||
Label, | ||
ListView, | ||
ListItem, | ||
LoadingIndicator, | ||
Sparkline, | ||
Static, | ||
Tree, | ||
ProgressBar, | ||
TabbedContent, | ||
TabPane, | ||
Markdown, | ||
Tabs, | ||
) | ||
|
||
from .button import button_example | ||
from .checkbox import checkbox_example | ||
from .content_switcher import content_switcher_example | ||
from .data_table import data_table_example | ||
from .markdown import markdown_viewer_example, markdown_example | ||
from .option_list import option_list_example | ||
from .placeholder import placeholder_example | ||
from .pretty import pretty_example | ||
from .radio import radio_button_example, radio_set_example | ||
from .select import select_example, selection_list_example | ||
from .switch import switch_example | ||
|
||
# from .text_log import text_log_example | ||
|
||
|
||
def directory_tree_example(id: str) -> ComposeResult: | ||
yield Container(DirectoryTree("./"), id=id) | ||
|
||
|
||
def footer_example(id: str) -> ComposeResult: | ||
yield Container(Footer(), id=id) | ||
|
||
|
||
def header_example(id: str) -> ComposeResult: | ||
yield Container(Header(), id=id) | ||
|
||
|
||
def input_example(id: str) -> ComposeResult: | ||
yield Container( | ||
Input(placeholder="First Name"), Input(placeholder="Last Name"), id=id | ||
) | ||
|
||
|
||
def label_example(id: str) -> ComposeResult: | ||
yield Container(Label("Hello, world!"), id=id) | ||
|
||
|
||
def list_item_example(id: str) -> ComposeResult: | ||
yield Container( | ||
ListView( | ||
ListItem(Label("One")), | ||
ListItem(Label("Two")), | ||
ListItem(Label("Three")), | ||
), | ||
id=id, | ||
) | ||
|
||
yield Footer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this footer here? Is it showing any relevant bindings? |
||
|
||
|
||
def loading_example(id: str) -> ComposeResult: | ||
yield Container(LoadingIndicator(), id=id) | ||
|
||
|
||
def sparkline_example(id: str) -> ComposeResult: | ||
data = [random.expovariate(1 / 3) for _ in range(1000)] | ||
|
||
yield Container( | ||
Sparkline(data, summary_function=max), | ||
Sparkline(data, summary_function=mean), | ||
Sparkline(data, summary_function=min), | ||
id=id, | ||
) | ||
|
||
|
||
def static_example(id: str) -> ComposeResult: | ||
yield Container(Static("Hello, world!"), id=id) | ||
|
||
|
||
def tree_example(id: str) -> ComposeResult: | ||
tree: Tree[dict] = Tree("Dune") | ||
tree.root.expand() | ||
characters = tree.root.add("Characters", expand=True) | ||
characters.add_leaf("Paul") | ||
characters.add_leaf("Jessica") | ||
characters.add_leaf("Chani") | ||
yield Container(tree, id=id) | ||
|
||
|
||
def progress_bar_example(id: str) -> ComposeResult: | ||
bar = ProgressBar(total=100, show_eta=False) | ||
bar.advance(50) | ||
yield Container(Center(Middle(bar)), id=id) | ||
Comment on lines
+105
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the progress bar is static, which makes sense, maybe create it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I understand it correctly that you want to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
|
||
|
||
def tabbed_content_example(id: str): | ||
content = TabbedContent() | ||
content._tab_content = [ | ||
TabPane("Leto", Markdown("# Leto"), id="leto"), | ||
TabPane("Jessica", Markdown("# Jessica"), id="jessica"), | ||
TabPane("Paul", Markdown("# Paul"), id="paulo"), | ||
] | ||
# This does not work, reason why I used _tab_content above | ||
# content.add_pane(TabPane("Leto", Markdown("#Leto"), id="letoo")) | ||
# content.add_pane(TabPane("Jessica", Markdown(""), id="jessicoa")) | ||
# content.add_pane(TabPane("Paul", Markdown(""), id="paulo")) | ||
|
||
yield Container(content, id=id) | ||
|
||
|
||
def tabs_example(id: str): | ||
yield Container(Tabs("First tab", "Second tab", "Third tab"), id=id) | ||
|
||
|
||
__all__ = [ | ||
"button_example", | ||
"checkbox_example", | ||
"content_switcher_example", | ||
"data_table_example", | ||
"directory_tree_example", | ||
"footer_example", | ||
"header_example", | ||
"input_example", | ||
"label_example", | ||
"list_item_example", | ||
"loading_example", | ||
"markdown_viewer_example", | ||
"markdown_example", | ||
"option_list_example", | ||
"placeholder_example", | ||
"pretty_example", | ||
"progress_bar_example", | ||
"radio_button_example", | ||
"radio_set_example", | ||
"select_example", | ||
"selection_list_example", | ||
"sparkline_example", | ||
"static_example", | ||
"switch_example", | ||
"tabbed_content_example", | ||
"tabs_example", | ||
"tree_example", | ||
# "text_log_example", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from textual.app import ComposeResult | ||
from textual.containers import Horizontal, VerticalScroll | ||
from textual.widgets import Static, Button | ||
|
||
|
||
def button_example(id: str) -> ComposeResult: | ||
yield Horizontal( | ||
VerticalScroll( | ||
Static("Standard Buttons", classes="header"), | ||
Button("Default"), | ||
Button("Primary!", variant="primary"), | ||
Button.success("Success!"), | ||
Button.warning("Warning!"), | ||
Button.error("Error!"), | ||
), | ||
VerticalScroll( | ||
Static("Disabled Buttons", classes="header"), | ||
Button("Default", disabled=True), | ||
Button("Primary!", variant="primary", disabled=True), | ||
Button.success("Success!", disabled=True), | ||
Button.warning("Warning!", disabled=True), | ||
Button.error("Error!", disabled=True), | ||
), | ||
id=id, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from textual.app import ComposeResult | ||
from textual.containers import VerticalScroll, Container | ||
from textual.widgets import Checkbox | ||
|
||
|
||
def checkbox_example(id: str) -> ComposeResult: | ||
yield Container( | ||
VerticalScroll( | ||
Checkbox("Arrakis :sweat:"), | ||
Checkbox("Caladan"), | ||
Checkbox("Chusuk"), | ||
Checkbox("[b]Giedi Prime[/b]"), | ||
Checkbox("[magenta]Ginaz[/]"), | ||
Checkbox("Grumman", True), | ||
Checkbox("Kaitain", id="initial_focus"), | ||
Checkbox("Novebruns", True), | ||
), | ||
id=id, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from textual.app import ComposeResult | ||
from textual.containers import VerticalScroll, Container, Horizontal | ||
from textual.widgets import Button, ContentSwitcher, DataTable, Markdown | ||
|
||
MARKDOWN_EXAMPLE = """# Three Flavours Cornetto | ||
|
||
The Three Flavours Cornetto trilogy is an anthology series of British | ||
comedic genre films directed by Edgar Wright. | ||
|
||
## Shaun of the Dead | ||
|
||
| Flavour | UK Release Date | Director | | ||
| -- | -- | -- | | ||
| Strawberry | 2004-04-09 | Edgar Wright | | ||
|
||
## Hot Fuzz | ||
|
||
| Flavour | UK Release Date | Director | | ||
| -- | -- | -- | | ||
| Classico | 2007-02-17 | Edgar Wright | | ||
|
||
## The World's End | ||
|
||
| Flavour | UK Release Date | Director | | ||
| -- | -- | -- | | ||
| Mint | 2013-07-19 | Edgar Wright | | ||
""" | ||
|
||
|
||
def content_switcher_example(id: str) -> ComposeResult: | ||
table: DataTable = DataTable(id="data-table") | ||
table.add_columns("Book", "Year") | ||
table.add_rows( | ||
[ | ||
(title.ljust(35), year) | ||
for title, year in ( | ||
("Dune", 1965), | ||
("Dune Messiah", 1969), | ||
("Children of Dune", 1976), | ||
("God Emperor of Dune", 1981), | ||
("Heretics of Dune", 1984), | ||
("Chapterhouse: Dune", 1985), | ||
) | ||
] | ||
) | ||
|
||
yield Container( | ||
Horizontal( | ||
Button("DataTable", id="data-table"), | ||
Button("Markdown", id="markdown"), | ||
id="buttons", | ||
), | ||
ContentSwitcher( | ||
table, | ||
VerticalScroll(Markdown(MARKDOWN_EXAMPLE), id="markdown"), | ||
initial="data-table", | ||
id="content-switcher-example", | ||
), | ||
id=id, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from textual.containers import Container | ||
from textual.app import ComposeResult | ||
from textual.widgets import DataTable | ||
|
||
ROWS = [ | ||
("lane", "swimmer", "country", "time"), | ||
(4, "Joseph Schooling", "Singapore", 50.39), | ||
(2, "Michael Phelps", "United States", 51.14), | ||
(5, "Chad le Clos", "South Africa", 51.14), | ||
(6, "László Cseh", "Hungary", 51.14), | ||
(3, "Li Zhuhao", "China", 51.26), | ||
(8, "Mehdy Metella", "France", 51.58), | ||
(7, "Tom Shields", "United States", 51.73), | ||
(1, "Aleksandr Sadovnikov", "Russia", 51.84), | ||
(10, "Darren Burns", "Scotland", 51.84), | ||
] | ||
|
||
|
||
def data_table_example(id: str) -> ComposeResult: | ||
table: DataTable = DataTable() | ||
table.add_columns(*ROWS[0]) | ||
table.add_rows(ROWS[1:]) | ||
|
||
yield Container(table, id=id) |
Uh oh!
There was an error while loading. Please reload this page.