Skip to content

Instantly share code, notes, and snippets.

@ddkasa
Last active April 21, 2025 15:35
Show Gist options
  • Save ddkasa/101adcd93ca340c3ee625df725cd450c to your computer and use it in GitHub Desktop.
Save ddkasa/101adcd93ca340c3ee625df725cd450c to your computer and use it in GitHub Desktop.

Revisions

  1. ddkasa revised this gist Apr 21, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.py
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ def get_content_height(self, *_) -> int:

    def get_content_width(self, *_) -> int:
    if self.text:
    return max(self.text, key=len)
    return len(max(self.text, key=len))
    return 0


  2. ddkasa revised this gist Apr 21, 2025. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ class ChristmasWidget(Widget):
    """

    colors: deque[Style] = deque()
    text: reactive[list[str]] = reactive(list, init=False)
    text: reactive[list[str]] = reactive(list, init=False, layout=True)

    def on_mount(self) -> None:
    for color in ("#165B33", "#146B3A", "#F8B229", "#EA4630", "#BB2528"):
    @@ -50,7 +50,7 @@ def get_content_height(self, *_) -> int:

    def get_content_width(self, *_) -> int:
    if self.text:
    return len(self.text[0])
    return max(self.text, key=len)
    return 0


  3. ddkasa revised this gist Dec 25, 2024. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -19,31 +19,30 @@ class ChristmasWidget(Widget):
    ChristmasWidget {
    width: auto;
    height: auto;
    border: thick darkgreen;
    padding: 2 6;
    }
    """

    styles: deque[Style] = deque()
    colors: deque[Style] = deque()
    text: reactive[list[str]] = reactive(list, init=False)

    def on_mount(self) -> None:
    for color in ("#165B33", "#146B3A", "#F8B229", "#EA4630", "#BB2528"):
    self.styles.append(Style(color=Color.parse(color)))
    self.colors.append(Style(color=Color.parse(color)))
    self.clock = self.set_interval(0.2, self.refresh)

    def render_lines(self, crop: Region) -> list[Strip]:
    self.styles.rotate()
    self.colors.rotate()
    return super().render_lines(crop)

    def render_line(self, y: int) -> Strip:
    try:
    return Strip([Segment(self.text[y], style=self.styles[y % 5])])
    return Strip([Segment(self.text[y], style=self.colors[y % 5])])
    except IndexError:
    return Strip.blank(self.size.width)

    def with_text(self, text: str) -> Self:
    self.text = figlet_format(text, "doom", width=self.app.size.width).split("\n")
    self.text = figlet_format(text, "banner", width=self.app.size.width).split("\n")
    return self

    def get_content_height(self, *_) -> int:
  4. ddkasa revised this gist Dec 25, 2024. 1 changed file with 29 additions and 20 deletions.
    49 changes: 29 additions & 20 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -1,67 +1,76 @@
    from collections import deque
    from typing import Self

    from pyfiglet import figlet_format
    from rich.color import Color
    from rich.style import Style
    from rich.segment import Segment
    from rich.style import Style
    from textual.app import App, ComposeResult
    from textual.containers import Center
    from textual.geometry import Region
    from textual.reactive import reactive
    from textual.strip import Strip
    from textual.widget import Widget
    from textual.widgets import Header
    from textual.containers import Container
    from pyfiglet import figlet_format


    class ChristmasWidget(Widget):
    DEFAULT_CSS = """
    ChristmasWidget {
    width: 100%;
    height: 100%;
    background: $panel-darken-2;
    padding: 10 25;
    width: auto;
    height: auto;
    border: thick darkgreen;
    padding: 2 6;
    }
    """

    colors: deque[str] = deque(["#165B33", "#146B3A", "#F8B229", "#EA4630", "#BB2528"])
    styles: deque[Style] = deque()
    text: reactive[list[str]] = reactive(list, init=False)

    def on_mount(self) -> None:
    for color in ("#165B33", "#146B3A", "#F8B229", "#EA4630", "#BB2528"):
    self.styles.append(Style(color=Color.parse(color)))
    self.clock = self.set_interval(0.2, self.refresh)

    def render_lines(self, crop: Region) -> list[Strip]:
    self.colors.rotate()
    self.styles.rotate()
    return super().render_lines(crop)

    def render_line(self, y: int) -> Strip:
    try:
    return Strip(
    [
    Segment(
    self.text[y],
    style=Style(color=Color.parse(self.colors[y % 4])),
    )
    ]
    )
    return Strip([Segment(self.text[y], style=self.styles[y % 5])])
    except IndexError:
    return Strip.blank(self.size.width)

    def with_text(self, text: str) -> Self:
    self.text = figlet_format(text, "slant", width=self.app.size.width).split("\n")
    self.text = figlet_format(text, "doom", width=self.app.size.width).split("\n")
    return self

    def get_content_height(self, *_) -> int:
    return len(self.text)

    def get_content_width(self, *_) -> int:
    if self.text:
    return len(self.text[0])
    return 0


    class ChristmasApp(App):
    TITLE = "Merry Christmas"

    CSS = """
    ChristmasApp {
    background: $panel-darken-2;
    }
    Center {
    height: 100%;
    align: center middle;
    }
    """

    def compose(self) -> ComposeResult:
    yield Header(show_clock=True)
    with Container():
    with Center():
    yield ChristmasWidget().with_text("Merry Christmas!")


  5. ddkasa created this gist Dec 24, 2024.
    69 changes: 69 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    from collections import deque
    from typing import Self

    from rich.color import Color
    from rich.style import Style
    from rich.segment import Segment
    from textual.app import App, ComposeResult
    from textual.geometry import Region
    from textual.reactive import reactive
    from textual.strip import Strip
    from textual.widget import Widget
    from textual.widgets import Header
    from textual.containers import Container
    from pyfiglet import figlet_format


    class ChristmasWidget(Widget):
    DEFAULT_CSS = """
    ChristmasWidget {
    width: 100%;
    height: 100%;
    background: $panel-darken-2;
    padding: 10 25;
    }
    """

    colors: deque[str] = deque(["#165B33", "#146B3A", "#F8B229", "#EA4630", "#BB2528"])
    text: reactive[list[str]] = reactive(list, init=False)

    def on_mount(self) -> None:
    self.clock = self.set_interval(0.2, self.refresh)

    def render_lines(self, crop: Region) -> list[Strip]:
    self.colors.rotate()
    return super().render_lines(crop)

    def render_line(self, y: int) -> Strip:
    try:
    return Strip(
    [
    Segment(
    self.text[y],
    style=Style(color=Color.parse(self.colors[y % 4])),
    )
    ]
    )
    except IndexError:
    return Strip.blank(self.size.width)

    def with_text(self, text: str) -> Self:
    self.text = figlet_format(text, "slant", width=self.app.size.width).split("\n")
    return self

    def get_content_height(self, *_) -> int:
    return len(self.text)


    class ChristmasApp(App):
    TITLE = "Merry Christmas"

    def compose(self) -> ComposeResult:
    yield Header(show_clock=True)
    with Container():
    yield ChristmasWidget().with_text("Merry Christmas!")


    if __name__ == "__main__":
    ChristmasApp().run()