Skip to content
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

Fancy splash screen #120

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added 0.1.1
Empty file.
8 changes: 7 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

0.6.2 -
------------------

- Fancy splash screen using textualeffects.
[ggozad]

0.6.1 - 2024-09-24
------------------

Expand All @@ -13,7 +19,7 @@ Changelog
0.5.2 - 2024-09-06
------------------

- Fix crash when starting the app an existing db.
- Fix crash when starting the app without an existing db.
[ggozad]

0.5.1 - 2024-09-06
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies = [
"rich-pixels>=3.0.1",
"pillow>=10.4.0",
"ollama>=0.3.1",
"textualeffects>=0.1.2",
]

[project.urls]
Expand All @@ -50,6 +51,8 @@ dev-dependencies = [
"homebrew-pypi-poet>=0.10.0",
]

[tool.uv.sources]

[tool.ruff]
line-length = 88
# Enable Flake's "E" and "F" codes by default and "I" for sorting imports.
Expand Down
67 changes: 33 additions & 34 deletions src/oterm/app/oterm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import json
from typing import Iterable

Expand All @@ -9,7 +8,7 @@

from oterm.app.chat_edit import ChatEdit
from oterm.app.chat_export import ChatExport, slugify
from oterm.app.splash import SplashScreen
from oterm.app.splash import splash
from oterm.app.widgets.chat import ChatContainer
from oterm.config import appConfig
from oterm.store.store import Store
Expand Down Expand Up @@ -148,38 +147,38 @@ async def on_mount(self) -> None:
store = await Store.get_store()
self.dark = appConfig.get("theme") == "dark"
saved_chats = await store.get_chats()
await self.push_screen(SplashScreen())
await asyncio.sleep(1.0)
self.pop_screen()

if not saved_chats:
self.action_new_chat()
else:
tabs = self.query_one(TabbedContent)
for (
id,
name,
model,
system,
format,
parameters,
keep_alive,
tools,
) in saved_chats:
messages = await store.get_messages(id)
container = ChatContainer(
db_id=id,
chat_name=name,
model=model,
messages=messages,
system=system,
format=format,
parameters=parameters,
keep_alive=keep_alive,
tools=tools,
)
pane = TabPane(name, container, id=f"chat-{id}")
tabs.add_pane(pane)

async def on_splash_done(message) -> None:
if not saved_chats:
await self.action_new_chat()
else:
tabs = self.query_one(TabbedContent)
for (
id,
name,
model,
system,
format,
parameters,
keep_alive,
tools,
) in saved_chats:
messages = await store.get_messages(id)
container = ChatContainer(
db_id=id,
chat_name=name,
model=model,
messages=messages,
system=system,
format=format,
parameters=parameters,
keep_alive=keep_alive,
tools=tools,
)
pane = TabPane(name, container, id=f"chat-{id}")
tabs.add_pane(pane)

self.push_screen(splash, callback=on_splash_done)

@on(TabbedContent.TabActivated)
async def on_tab_activated(self, event: TabbedContent.TabActivated) -> None:
Expand Down
12 changes: 2 additions & 10 deletions src/oterm/app/oterm.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,9 @@ Notification {
height: 3;
}

#splash-container {
height: 100%;
width: 100%;
background: $panel;
}

#splash {
color: $secondary;
height: 100%;
width: 100%;
content-align: center middle;
TabbedContent {
layer: below;
}

MarkdownFence {
Expand Down
133 changes: 93 additions & 40 deletions src/oterm/app/splash.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,98 @@
from textual.app import ComposeResult
from textual.containers import Container
from textual.screen import ModalScreen
from textual.widgets import Footer, Header, Static
import random
from typing import Any, Tuple

from textualeffects.effects import EffectType
from textualeffects.widgets import SplashScreen

logo = """
-***- :+**=.
:%@@@@@%: #@@@@@@-
.@@@*.*@@@. %@@%.=@@@-
*@@% %@@# =@@@. *@@%
@@@= -@@@:=*#@@@@@%*=.%@@* :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@ @@@@
@@@@: :@@@@
*@@@ @@@*
@@@@ @@@@
#@@@@ @@@@#
%@@@@ @@@@@
#@@@@ @@@@#
@@@@ @@@@
@@@@= =@@@@
@@@@ @@@@
@@@@ @@@@
@@@@ @@@@
@. .@
"""

effects: list[Tuple[EffectType, dict[str, Any]]] = [
(
"Beams",
{
"beam_delay": 3,
"beam_gradient_steps": 2,
"beam_gradient_frames": 2,
"final_gradient_steps": 2,
"final_gradient_frames": 2,
"final_wipe_speed": 5,
},
),
(
"BouncyBalls",
{
"ball_delay": 1,
},
),
(
"Expand",
{
"movement_speed": 0.1,
},
),
(
"Pour",
{
"pour_speed": 3,
},
),
(
"Rain",
{},
),
(
"RandomSequence",
{},
),
(
"Scattered",
{},
),
(
"Slide",
{},
),
]

class SplashScreen(ModalScreen):

def compose(self) -> ComposeResult:
yield Header()
with Container(id="splash-container"):
yield Static(logo, id="splash")
yield Footer()
effect = random.choice(effects)
splash = SplashScreen(text=logo, effect=effect[0], config=effect[1])
Loading