Last active
          April 21, 2025 15:35 
        
      - 
      
 - 
        
Save ddkasa/101adcd93ca340c3ee625df725cd450c to your computer and use it in GitHub Desktop.  
Revisions
- 
        
ddkasa revised this gist
Apr 21, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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 len(max(self.text, key=len)) return 0  - 
        
ddkasa revised this gist
Apr 21, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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, 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 max(self.text, key=len) return 0  - 
        
ddkasa revised this gist
Dec 25, 2024 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,31 +19,30 @@ class ChristmasWidget(Widget): ChristmasWidget { width: auto; height: auto; padding: 2 6; } """ 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.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.colors.rotate() return super().render_lines(crop) def render_line(self, y: int) -> Strip: try: 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, "banner", width=self.app.size.width).split("\n") return self def get_content_height(self, *_) -> int:  - 
        
ddkasa revised this gist
Dec 25, 2024 . 1 changed file with 29 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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.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 class ChristmasWidget(Widget): DEFAULT_CSS = """ ChristmasWidget { width: auto; height: auto; border: thick darkgreen; padding: 2 6; } """ 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.styles.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])]) 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") 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 Center(): yield ChristmasWidget().with_text("Merry Christmas!")  - 
        
ddkasa created this gist
Dec 24, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal 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()