Skip to content

Commit

Permalink
convert back to modal style menu
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Sep 10, 2024
1 parent e326dff commit 7edbf3e
Show file tree
Hide file tree
Showing 14 changed files with 897 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub async fn prompt_app<B: Backend>(
ContentDisplayMode::Conversation(_) => {
WindowMode::Conversation(Some(ConversationEvent::PromptRead))
}
ContentDisplayMode::FileBrowser(_) => WindowMode::FileBrowser(None),
};

let mut widget_poll_tick = interval(Duration::from_millis(10));
Expand Down
4 changes: 1 addition & 3 deletions lumni/src/apps/builtin/llm/prompt/src/chat/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ impl App<'_> {
.reload_conversation_text(conversation_text);
} else {
// If there's no conversation text, ensure we're in Conversation mode with an empty conversation
if let ContentDisplayMode::FileBrowser(_) = self.ui.selected_mode {
self.ui.switch_to_conversation_mode();
}
self.ui.switch_to_conversation_mode();
}

Ok(())
Expand Down
53 changes: 12 additions & 41 deletions lumni/src/apps/builtin/llm/prompt/src/tui/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ impl Conversations {
tab_indices.insert(ConversationStatus::Archived, 0);
tab_indices.insert(ConversationStatus::Deleted, 0);

let list_widget =
ListWidget::new(Vec::new(), "Conversations".to_string())
.normal_style(
Style::default().bg(Color::Rgb(24, 32, 40)).fg(Color::Gray),
)
.selected_style(
Style::default().bg(Color::Rgb(32, 40, 48)).fg(Color::Cyan),
)
.highlight_symbol("► ".to_string())
.show_borders(false);
let list_widget = ListWidget::new(Vec::new())
.title("Conversations")
.normal_style(
Style::default().bg(Color::Rgb(24, 32, 40)).fg(Color::Gray),
)
.selected_style(
Style::default().bg(Color::Rgb(32, 40, 48)).fg(Color::Cyan),
)
.highlight_symbol("► ".to_string())
.show_borders(false);

Self {
conversations,
Expand Down Expand Up @@ -152,18 +152,6 @@ impl Conversations {
])
}

pub fn move_selection(&mut self, offset: i32) {
self.list_widget
.move_selection(&mut self.list_widget_state, offset);
*self.tab_indices.get_mut(&self.current_tab).unwrap() =
self.list_widget_state.selected_index;
}

pub fn get_selected_conversation(&self) -> Option<&Conversation> {
self.conversations_in_current_tab()
.nth(self.list_widget_state.selected_index)
}

fn get_current_conversation(&self) -> Option<&Conversation> {
let index = *self.tab_indices.get(&self.current_tab).unwrap_or(&0);
self.conversations_in_current_tab().nth(index)
Expand Down Expand Up @@ -219,23 +207,6 @@ impl Conversations {
Ok(())
}

fn update_list_widget(&mut self) {
let items: Vec<Text<'static>> = self
.conversations_in_current_tab()
.enumerate()
.map(|(index, conversation)| {
self.create_conversation_list_item(conversation, index)
})
.collect();

self.list_widget = ListWidget::new(items, "Conversations".to_string())
.normal_style(Style::default().bg(Color::Black).fg(Color::Cyan))
.selected_style(
Style::default().bg(Color::Rgb(40, 40, 40)).fg(Color::White),
)
.highlight_symbol(">> ".to_string());
}

fn conversations_in_tab(
&self,
status: ConversationStatus,
Expand Down Expand Up @@ -318,9 +289,7 @@ impl Conversations {
}
Ok(())
}
}

impl Conversations {
fn move_selection_up(&mut self) {
self.list_widget
.move_selection(&mut self.list_widget_state, -1);
Expand Down Expand Up @@ -481,7 +450,9 @@ impl Conversations {
Some(ConversationSelectEvent::ReloadConversation),
))))
}
}

impl Conversations {
pub async fn handle_key_event(
&mut self,
key_event: &mut KeyTrack,
Expand Down
125 changes: 10 additions & 115 deletions lumni/src/apps/builtin/llm/prompt/src/tui/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ use ratatui::style::{Color, Modifier, Style};
use ratatui::widgets::{Block, Borders, Tabs};
use ratatui::{Frame, Terminal};

use super::ui::{ContentDisplayMode, ConversationUi};
use super::widgets::FileBrowser;
use super::ui::ConversationUi;
use super::{App, TextWindowTrait, WindowMode, Workspaces};

pub async fn draw_ui<B: Backend>(
terminal: &mut Terminal<B>,
window_mode: &WindowMode,
_window_mode: &WindowMode,
app: &mut App<'_>,
) -> Result<(), io::Error> {
terminal.draw(|frame| {
let terminal_area = frame.size();
const LIST_PANE_WIDTH: u16 = 32;
const LIST_TAB_HEIGHT: u16 = 2;
const WORKSPACE_NAV_HEIGHT: u16 = 2;

// Default background
Expand All @@ -37,67 +34,18 @@ pub async fn draw_ui<B: Backend>(
.split(terminal_area);

let workspace_nav_area = main_layout[0];
let content_area = main_layout[1];
let content_pane = main_layout[1];

render_workspace_nav::<B>(
frame,
workspace_nav_area,
&app.ui.workspaces,
);

// Sub-layout for list pane and content pane
let sub_layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(LIST_PANE_WIDTH),
Constraint::Min(0),
])
.split(content_area);

let list_pane = sub_layout[0];
let content_pane = sub_layout[1];
// List pane styling
let list_block = Block::default()
.borders(Borders::NONE)
.style(Style::default().bg(Color::Rgb(0, 0, 0)))
.style(Style::default().bg(Color::Rgb(16, 24, 32)));
frame.render_widget(list_block, list_pane);

// Content pane styling
let content_block = Block::default()
.borders(Borders::LEFT)
.border_style(Style::default().fg(Color::DarkGray));
let content_block = Block::default();
frame.render_widget(content_block, content_pane);

// Navigation layout
let nav_layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(LIST_TAB_HEIGHT),
Constraint::Min(0),
])
.split(list_pane);

let list_tab_area = nav_layout[0];
let nav_content_area = nav_layout[1];

// Render navigation tabs
render_list_tabs::<B>(frame, list_tab_area, &app.ui.selected_mode);

// Render navigation pane content
match &mut app.ui.selected_mode {
ContentDisplayMode::Conversation(_) => {
if let Some(conversations) =
app.ui.workspaces.current_conversations_mut()
{
conversations.render(frame, nav_content_area);
}
}
ContentDisplayMode::FileBrowser(filebrowser) => {
render_file_nav::<B>(frame, nav_content_area, filebrowser);
}
}

// Render conversation mode
let content_inner = content_pane.inner(Margin {
vertical: 0,
Expand All @@ -111,8 +59,7 @@ pub async fn draw_ui<B: Backend>(

// Render modals if any
if let Some(modal) = &mut app.ui.modal {
let area = modal_area(terminal_area);
modal.render_on_frame(frame, area);
modal.render_on_frame(frame, terminal_area);
}
})?;
Ok(())
Expand All @@ -123,61 +70,23 @@ fn render_workspace_nav<B: Backend>(
area: Rect,
workspaces: &Workspaces,
) {
let workspace_names: Vec<&str> = workspaces
.workspaces
.iter()
.map(|w| w.name.as_str())
.collect();
let workspace_names: Vec<String> = [].to_vec();

let tabs = Tabs::new(workspace_names)
.block(Block::default().borders(Borders::BOTTOM))
.select(workspaces.current_workspace_index)
.style(Style::default().fg(Color::White))
.highlight_style(
Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
);

frame.render_widget(tabs, area);
}

fn render_list_tabs<B: Backend>(
frame: &mut Frame,
area: Rect,
selected_mode: &ContentDisplayMode,
) {
let tabs = vec!["💬 Conversations", "📁 Files"];
let tab_index = match selected_mode {
ContentDisplayMode::Conversation(_) => 0,
ContentDisplayMode::FileBrowser(_) => 1,
};
let tabs = Tabs::new(tabs)
.block(
Block::default()
.borders(Borders::BOTTOM)
.borders(Borders::NONE)
.border_style(Style::default().fg(Color::DarkGray)),
)
.select(tab_index)
.style(Style::default().fg(Color::Gray))
.select(workspaces.current_workspace_index)
.style(Style::default().fg(Color::DarkGray).bg(Color::Black))
.highlight_style(
Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
);
frame.render_widget(tabs, area);
}

fn render_file_nav<B: Backend>(
frame: &mut Frame,
area: Rect,
file_browser: &mut FileBrowser,
) {
frame.render_stateful_widget(
&file_browser.widget,
area,
&mut file_browser.state,
);
frame.render_widget(tabs, area);
}

fn render_conversation_mode<B: Backend>(
Expand Down Expand Up @@ -206,17 +115,3 @@ fn render_conversation_mode<B: Backend>(
frame.render_widget(conv_ui.prompt.widget(&prompt_area), prompt_area);
frame.render_widget(conv_ui.response.widget(&response_area), response_area);
}

fn modal_area(area: Rect) -> Rect {
Rect::new(
area.x + 2,
area.y + 1,
area.width.saturating_sub(3),
area.height.saturating_sub(4),
)
}

fn window_hint() -> Option<String> {
// TODO: implement window hint for main window
None
}
Loading

0 comments on commit 7edbf3e

Please sign in to comment.