2026-07-23 14:53:57 +10:00
|
|
|
from textual.app import App, ComposeResult
|
2026-07-27 20:51:13 +10:00
|
|
|
from textual.binding import Binding
|
2026-07-23 14:53:57 +10:00
|
|
|
|
2026-07-27 20:51:13 +10:00
|
|
|
from textual.widgets import Header, Footer, TabPane, TabbedContent
|
|
|
|
|
from textual.containers import Vertical
|
|
|
|
|
from widgets.text_editor import TextEditor, TextArea
|
|
|
|
|
from widgets.file_tabs import FileTabs
|
|
|
|
|
from widgets.directory_tree_custom import CustomDirectoryTree
|
|
|
|
|
|
|
|
|
|
import sys, os
|
|
|
|
|
import argparse
|
|
|
|
|
import pathlib
|
2026-07-23 14:53:57 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Berry(App):
|
2026-07-27 20:51:13 +10:00
|
|
|
DEFAULT_CSS = """
|
|
|
|
|
Berry {
|
|
|
|
|
#main {
|
|
|
|
|
padding: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
bind_keys = {
|
|
|
|
|
"new": "ctrl+n",
|
|
|
|
|
"open": "ctrl+o",
|
|
|
|
|
"open-folder": "ctrl+shift+o",
|
|
|
|
|
"save": "ctrl+s",
|
|
|
|
|
"save-as": "ctrl+shift+s",
|
|
|
|
|
"settings": "ctrl+f1",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, path: str):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.open_tab = None
|
|
|
|
|
self.path = pathlib.Path(path)
|
|
|
|
|
|
|
|
|
|
self.BINDINGS = (
|
|
|
|
|
Binding(self.bind_keys['new'], "new", "New file"),
|
|
|
|
|
Binding(self.bind_keys['open'], "open_file", "Open file"),
|
|
|
|
|
Binding(self.bind_keys['open-folder'], "open_folder", "Open directory"),
|
|
|
|
|
Binding(self.bind_keys['save'], "save", "Save"),
|
|
|
|
|
Binding(self.bind_keys['save-as'], "save_as", "Save as...")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for bind in self.BINDINGS:
|
|
|
|
|
self._bindings._add_binding(bind)
|
|
|
|
|
self.refresh_bindings()
|
|
|
|
|
|
2026-07-23 14:53:57 +10:00
|
|
|
def compose(self) -> ComposeResult:
|
2026-07-27 20:51:13 +10:00
|
|
|
yield Header()
|
|
|
|
|
with Vertical(id="main"):
|
|
|
|
|
|
|
|
|
|
yield CustomDirectoryTree(self.path.parent if self.path.is_file() else self.path)
|
|
|
|
|
|
|
|
|
|
self.file_tabs = FileTabs()
|
|
|
|
|
yield self.file_tabs
|
|
|
|
|
|
2026-07-23 14:53:57 +10:00
|
|
|
yield Footer()
|
|
|
|
|
|
2026-07-27 20:51:13 +10:00
|
|
|
async def on_ready(self) -> None:
|
|
|
|
|
if self.path.is_file():
|
|
|
|
|
await self.file_tabs.open_file(self.path)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
await self.file_tabs.open_home()
|
|
|
|
|
|
2026-07-23 14:53:57 +10:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-07-27 20:51:13 +10:00
|
|
|
arg_parser = argparse.ArgumentParser()
|
|
|
|
|
arg_parser.add_argument("path", default=".")
|
|
|
|
|
args = arg_parser.parse_args()
|
|
|
|
|
|
|
|
|
|
app = Berry(args.path)
|
2026-07-23 14:53:57 +10:00
|
|
|
app.run()
|