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

Creating a draft of future UI #976

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Editor settings
.vscode

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
83 changes: 83 additions & 0 deletions interpreter/experimental_tui/start_tui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Type
from textual.app import App, ComposeResult
from textual import events, on
from textual.driver import Driver
from textual.reactive import reactive
from textual.widget import AwaitMount
from textual.widgets import Header, Footer, TextArea, Placeholder, Static, Button, ListView, ListItem, Label
from textual.containers import Container, Horizontal, VerticalScroll
from pathlib import Path
import json

import re
import appdirs

def get_chat_conversations():
# Use appdirs to get the user configuration directory for "conversations"
path = Path(appdirs.user_config_dir("Open Interpreter") + "/conversations")

# Initialize an empty dictionary
conversations = {}

# Ensure the path exists and is a directory
if not path.is_dir():
print(f"The path {path} is not a directory.")
return conversations

# Regular expression to match the initial part of the filename before the date
pattern = re.compile(r"^(.*?)__")

# Iterate over each file in the directory
for file_path in path.iterdir():
# Match only files
if file_path.is_file():
# Extract the filename as a string
filename = file_path.name
# Check if the file matches the expected pattern
match = pattern.match(filename)
if match:
# Extract the part of the filename before the date
extracted_name = match.group(1)
# Replace underscores with spaces to form the key
key = extracted_name.replace('_', ' ')
# Use the file_path as the value
conversations[key] = str(file_path)

return conversations

class Open_Interpreter_App(App):
"""A Textual app for a chat interface."""

BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
CSS_PATH = "style.tcss"

def compose(self) -> ComposeResult:
yield Header()

with Horizontal(id="main"):
with VerticalScroll(id="sidebar"):
conversations = get_chat_conversations()
for key in conversations:
yield Button(label=key, classes="conversation-button", name=conversations[key])

with Container():
with VerticalScroll():
for message in range(10):
yield Placeholder()
#@on(Button.Pressed)
def on_button_pressed(self, events: Button.Pressed) -> None:
print(events.button.name)

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark


# Additional methods for handling chat interactions can be added here

def main():
app = Open_Interpreter_App()
app.run()

if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions interpreter/experimental_tui/style.tcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#sidebar {
dock: left;
width: 20%;
height: 100%;
}

#sidebar-content {
width: 100%;
height: 100%;
color: #0f2b41;
background: $background-darken-3;
}

.conversation-button {
width: 100%;
text-align: left;
}