|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
import inspect
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import socket
|
|
|
|
|
import tempfile
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from textwrap import dedent
|
|
|
|
|
|
|
|
|
|
from rich.align import Align
|
|
|
|
|
from rich.box import SQUARE
|
|
|
|
|
from rich.console import RenderGroup
|
|
|
|
|
from rich.layout import Layout
|
|
|
|
|
from rich.markdown import Markdown
|
|
|
|
@ -21,6 +21,10 @@ SPIEL = "[Spiel](https://github.com/JoshKarpel/spiel)"
|
|
|
|
|
RICH = "[Rich](https://rich.readthedocs.io/)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECK = Deck(name=f"Spiel Demo Deck (v{__version__})")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DECK.slide(title="What is Spiel?")
|
|
|
|
|
def what():
|
|
|
|
|
left_markup = dedent(
|
|
|
|
|
f"""\
|
|
|
|
@ -64,9 +68,10 @@ def what():
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return Slide(root, title="What is Spiel?")
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DECK.slide(title="Decks and Slides")
|
|
|
|
|
def code():
|
|
|
|
|
markup = dedent(
|
|
|
|
|
f"""\
|
|
|
|
@ -76,7 +81,7 @@ def code():
|
|
|
|
|
|
|
|
|
|
The source code is pulled directly from the definitions via [`inspect.getsource`](https://docs.python.org/3/library/inspect.html#inspect.getsource).
|
|
|
|
|
|
|
|
|
|
(Because {RICH} supports syntax highlighting, so does {SPIEL}!)
|
|
|
|
|
({RICH} supports syntax highlighting, so {SPIEL} does too!)
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
root = Layout()
|
|
|
|
@ -84,73 +89,78 @@ def code():
|
|
|
|
|
lower = Layout()
|
|
|
|
|
root.split_column(upper, lower)
|
|
|
|
|
|
|
|
|
|
lower.split_row(
|
|
|
|
|
Layout(
|
|
|
|
|
def make_code_panel(obj):
|
|
|
|
|
lines, line_number = inspect.getsourcelines(obj)
|
|
|
|
|
return Panel(
|
|
|
|
|
Syntax(
|
|
|
|
|
inspect.getsource(Deck),
|
|
|
|
|
"".join(lines),
|
|
|
|
|
lexer_name="python",
|
|
|
|
|
line_numbers=True,
|
|
|
|
|
start_line=line_number,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Layout(
|
|
|
|
|
Syntax(
|
|
|
|
|
inspect.getsource(Slide),
|
|
|
|
|
lexer_name="python",
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
box=SQUARE,
|
|
|
|
|
border_style=Style(dim=True),
|
|
|
|
|
height=len(lines) + 2,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
lower.split_row(
|
|
|
|
|
Layout(make_code_panel(Deck)),
|
|
|
|
|
Layout(make_code_panel(Slide)),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return Slide(root, title="Decks and Slides")
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DECK.slide(title="Dynamic Content", from_function=True)
|
|
|
|
|
def dynamic():
|
|
|
|
|
tmp_dir = tempfile.gettempdir()
|
|
|
|
|
home = Path.home()
|
|
|
|
|
width = shutil.get_terminal_size().columns
|
|
|
|
|
return Slide(
|
|
|
|
|
RenderGroup(
|
|
|
|
|
Align(
|
|
|
|
|
Text(
|
|
|
|
|
f"Your slides can have very dynamic content, like this!",
|
|
|
|
|
style=Style(color="bright_magenta", bold=True, italic=True),
|
|
|
|
|
),
|
|
|
|
|
align="center",
|
|
|
|
|
width_limit = 80
|
|
|
|
|
return RenderGroup(
|
|
|
|
|
Align(
|
|
|
|
|
Text(
|
|
|
|
|
f"Slides can have dynamic content!",
|
|
|
|
|
style=Style(color="bright_magenta", bold=True, italic=True),
|
|
|
|
|
justify="center",
|
|
|
|
|
),
|
|
|
|
|
Align(
|
|
|
|
|
Panel(
|
|
|
|
|
Text(
|
|
|
|
|
f"The time on this computer, {socket.gethostname()}, is {datetime.now()}",
|
|
|
|
|
style=Style(color="bright_cyan", bold=True, italic=True),
|
|
|
|
|
justify="center",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
align="center",
|
|
|
|
|
align="center",
|
|
|
|
|
),
|
|
|
|
|
Align(
|
|
|
|
|
Panel(
|
|
|
|
|
Text(
|
|
|
|
|
f"Your terminal is {width} characters wide."
|
|
|
|
|
if width > width_limit
|
|
|
|
|
else f"Your terminal is only {width} characters wide! Get a bigger monitor!",
|
|
|
|
|
style=Style(color="green1" if width > width_limit else "red"),
|
|
|
|
|
justify="center",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
Align(
|
|
|
|
|
Panel(
|
|
|
|
|
Text(
|
|
|
|
|
f"Your terminal is {width} characters wide."
|
|
|
|
|
if width > 80
|
|
|
|
|
else f"Your terminal is only {width} characters wide! Get a bigger monitor!",
|
|
|
|
|
style=Style(color="green1" if width > 80 else "red"),
|
|
|
|
|
justify="center",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
align="center",
|
|
|
|
|
align="center",
|
|
|
|
|
),
|
|
|
|
|
Align(
|
|
|
|
|
Panel(
|
|
|
|
|
Text(
|
|
|
|
|
f"The time on this computer, {socket.gethostname()}, is {datetime.now()}",
|
|
|
|
|
style=Style(color="bright_cyan", bold=True, italic=True),
|
|
|
|
|
justify="center",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
Align(
|
|
|
|
|
Panel(
|
|
|
|
|
Text(
|
|
|
|
|
f"There are {len(os.listdir(tmp_dir))} entries under {tmp_dir} right now.",
|
|
|
|
|
style=Style(color="yellow"),
|
|
|
|
|
justify="center",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
align="center",
|
|
|
|
|
align="center",
|
|
|
|
|
),
|
|
|
|
|
Align(
|
|
|
|
|
Panel(
|
|
|
|
|
Text(
|
|
|
|
|
f"There are {len([f for f in home.iterdir() if f.is_file()])} files in {home} right now.",
|
|
|
|
|
style=Style(color="yellow"),
|
|
|
|
|
justify="center",
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
align="center",
|
|
|
|
|
),
|
|
|
|
|
title="Dynamic Content",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DECK.slide(title="Views")
|
|
|
|
|
def grid():
|
|
|
|
|
markup = dedent(
|
|
|
|
|
"""\
|
|
|
|
@ -160,30 +170,22 @@ def grid():
|
|
|
|
|
Press 's' to go back to "slide" view.
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
return Slide(Markdown(markup, justify="center"), title="Views")
|
|
|
|
|
return Markdown(markup, justify="center")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DECK.slide(title="Watch Mode")
|
|
|
|
|
def watch():
|
|
|
|
|
markup = dedent(
|
|
|
|
|
f"""\
|
|
|
|
|
## Developing a Deck
|
|
|
|
|
|
|
|
|
|
{SPIEL} can reload your deck as you edit it if you add the `--watch` option to `display`:
|
|
|
|
|
{SPIEL} can reload your deck as you edit it if you add the `--watch` option to `present`:
|
|
|
|
|
|
|
|
|
|
`$ spiel display examples/demo.py --watch`
|
|
|
|
|
`$ spiel present examples/demo.py --watch`
|
|
|
|
|
|
|
|
|
|
If you're on a system without inotify support (e.g., Windows Subsystem for Linux), you may need to use the `--poll` option instead.
|
|
|
|
|
|
|
|
|
|
When you're ready to present your deck for real, just drop the `--watch` option.
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
return Slide(Markdown(markup, justify="center"), title="Watch Mode")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECK = Deck(name=f"Spiel Demo Deck (v{__version__})").add_slides(
|
|
|
|
|
what(),
|
|
|
|
|
code(),
|
|
|
|
|
dynamic,
|
|
|
|
|
grid(),
|
|
|
|
|
watch(),
|
|
|
|
|
)
|
|
|
|
|
return Markdown(markup, justify="center")
|
|
|
|
|