build out ui
This commit is contained in:
70
src/main.py
70
src/main.py
@@ -1,15 +1,77 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.binding import Binding
|
||||
|
||||
from textual.widgets import Footer
|
||||
from widgets.text_editor import TextEditor
|
||||
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
|
||||
|
||||
|
||||
class Berry(App):
|
||||
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()
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield TextEditor(language="python")
|
||||
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
|
||||
|
||||
yield Footer()
|
||||
|
||||
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()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Berry()
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
arg_parser.add_argument("path", default=".")
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
app = Berry(args.path)
|
||||
app.run()
|
||||
Reference in New Issue
Block a user