Files
Berry/home_page.py
2026-05-16 21:51:10 +10:00

108 lines
3.3 KiB
Python

from textual.containers import Center, Vertical, Horizontal
from textual.widgets import Rule, Static
from textual import on
from textualeffects.widgets import EffectLabel
from textualeffects.effects import effects
from terminaltexteffects.utils.graphics import Color
class HomePage(Vertical):
LOGO = r""" ______ ______ ______ ______ __ __
/\ == \ /\ ___\ /\ == \ /\ == \ /\ \_\ \
\ \ __< \ \ __\ \ \ __< \ \ __< \ \____ \
\ \_____\ \ \_____\ \ \_\ \_\ \ \_\ \_\ \/\_____\
\/_____/ \/_____/ \/_/ /_/ \/_/ /_/ \/_____/
"""
DEFAULT_CSS = """
HomePage {
content-align: center top;
Static {
text-align: center;
}
#banner {
height: 5; # probs will need to be updated
margin-bottom: 1;
Rule {
color: $surface-lighten-2;
height: 100%;
content-align: center middle;
margin: 0 3;
}
EffectLabel {
height: 100%;
}
}
#bindings {
Horizontal {
max-width: 50;
width: 50%;
margin-top: 1;
height: 1;
.bind-name {
width: 75%;
}
.bind-keys {
width: 25%;
}
Static {
text-align: left;
link-background: transparent;
link-color: $primary;
}
}
}
}
"""
@on(EffectLabel.EffectFinished)
def restart_effect(self):
self.banner_label.run_worker(self.banner_label.run_effect, exclusive=True)
def compose(self):
with Horizontal(id="banner"):
yield Rule()
self.banner_label = EffectLabel(self.LOGO, effect="Highlight", config={
"final_gradient_stops": [Color("#f263ff"), Color("#946ff2")],
"cycles": 0
})
yield self.banner_label
yield Rule()
yield Static("[dim]The text editor that no one asked for and didn't need.[/]")
# bindings
with Center(id="bindings"):
binds = self.app.bindings
with Horizontal():
yield Static("[b] New file[/]", classes="bind-name")
yield Static(f"[@click=app.new]{binds["new"]}[/]", classes="bind-keys")
with Horizontal():
yield Static("[b] Open file[/]", classes="bind-name")
yield Static(f"[@click=app.open]{binds["open"]}[/]", classes="bind-keys")
with Horizontal():
yield Static("[b] Open Folder[/]", classes="bind-name")
yield Static(f"[@click=app.open_folder]{binds["open-folder"]}[/]", classes="bind-keys")
with Horizontal():
yield Static("[b] Settings[/]", classes="bind-name")
yield Static(f"[@click=app.settings]{binds["settings"]}[/]", classes="bind-keys")