147 lines
4.2 KiB
Python
147 lines
4.2 KiB
Python
"""
|
|
Custom footer widget with three sections: left, right, and status.
|
|
|
|
This module provides a custom footer that divides the footer into three sections:
|
|
- Left: Items added from the left side of the screen
|
|
- Right: Items added from the right side of the screen
|
|
- Status: Right edge section separated by a vertical line
|
|
"""
|
|
|
|
from textual.app import ComposeResult
|
|
from textual.containers import Horizontal
|
|
from textual.widgets import Static
|
|
from textual.widget import Widget
|
|
|
|
|
|
class CustomFooter(Widget):
|
|
"""
|
|
A custom footer widget with three sections.
|
|
|
|
Layout: [Left items] [spacer] [Right items] | [Status]
|
|
"""
|
|
|
|
DEFAULT_CSS = """
|
|
CustomFooter {
|
|
background: $surface;
|
|
color: $text;
|
|
dock: bottom;
|
|
height: 1;
|
|
padding: 0 1;
|
|
width: 100%;
|
|
}
|
|
|
|
CustomFooter > Horizontal {
|
|
height: 1;
|
|
width: 100%;
|
|
align: left middle;
|
|
}
|
|
|
|
.footer-left {
|
|
width: auto;
|
|
text-align: left;
|
|
text-style: dim;
|
|
height: 1;
|
|
content-align: left middle;
|
|
}
|
|
|
|
.footer-spacer {
|
|
width: 1fr;
|
|
height: 1;
|
|
}
|
|
|
|
.footer-right {
|
|
width: auto;
|
|
text-align: right;
|
|
text-style: dim;
|
|
height: 1;
|
|
content-align: right middle;
|
|
}
|
|
|
|
.footer-separator {
|
|
width: auto;
|
|
color: $primary;
|
|
text-style: dim;
|
|
height: 1;
|
|
content-align: center middle;
|
|
}
|
|
|
|
.footer-status {
|
|
width: auto;
|
|
text-align: right;
|
|
color: $accent;
|
|
text-style: bold;
|
|
height: 1;
|
|
content-align: right middle;
|
|
}
|
|
"""
|
|
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
self._left_items = []
|
|
self._right_items = []
|
|
self._status_text = ""
|
|
|
|
def compose(self) -> ComposeResult:
|
|
"""Create the footer layout."""
|
|
with Horizontal():
|
|
yield Static("", id="footer-left", classes="footer-left")
|
|
yield Static("", id="footer-spacer", classes="footer-spacer")
|
|
yield Static("", id="footer-right", classes="footer-right")
|
|
yield Static(" │ ", id="footer-separator", classes="footer-separator")
|
|
yield Static("", id="footer-status", classes="footer-status")
|
|
|
|
def add_left_item(self, item: str) -> None:
|
|
"""Add an item to the left section."""
|
|
self._left_items.append(item)
|
|
self._update_left_section()
|
|
|
|
def add_right_item(self, item: str) -> None:
|
|
"""Add an item to the right section."""
|
|
self._right_items.append(item)
|
|
self._update_right_section()
|
|
|
|
def clear_left_items(self) -> None:
|
|
"""Clear all items from the left section."""
|
|
self._left_items.clear()
|
|
self._update_left_section()
|
|
|
|
def clear_right_items(self) -> None:
|
|
"""Clear all items from the right section."""
|
|
self._right_items.clear()
|
|
self._update_right_section()
|
|
|
|
def set_status(self, status: str) -> None:
|
|
"""Set the status text."""
|
|
self._status_text = status
|
|
self._update_status_section()
|
|
|
|
def _update_left_section(self) -> None:
|
|
"""Update the left section display."""
|
|
try:
|
|
left_static = self.query_one("#footer-left", Static)
|
|
left_static.update(" ".join(self._left_items))
|
|
except Exception:
|
|
pass # Widget not ready yet
|
|
|
|
def _update_right_section(self) -> None:
|
|
"""Update the right section display."""
|
|
try:
|
|
right_static = self.query_one("#footer-right", Static)
|
|
right_static.update(" ".join(self._right_items))
|
|
except Exception:
|
|
pass # Widget not ready yet
|
|
|
|
def _update_status_section(self) -> None:
|
|
"""Update the status section display."""
|
|
try:
|
|
status_static = self.query_one("#footer-status", Static)
|
|
status_static.update(self._status_text)
|
|
except Exception:
|
|
pass # Widget not ready yet
|
|
|
|
def on_mount(self) -> None:
|
|
"""Called when the widget is mounted."""
|
|
# Initialize all sections
|
|
self._update_left_section()
|
|
self._update_right_section()
|
|
self._update_status_section()
|