Skip to content

Commit

Permalink
wip - ui update modal filebrowser, prepare path query
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Aug 25, 2024
1 parent 837a407 commit 250f26b
Show file tree
Hide file tree
Showing 20 changed files with 303 additions and 151 deletions.
9 changes: 9 additions & 0 deletions lumni/src/apps/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ pub enum LumniError {
Runtime(RuntimeError),
Application(ApplicationError, Option<String>),
Invoke(ApplicationError, Option<String>),
Resource(ResourceError),
NotImplemented(String),
Message(String),
Any(String),
}

#[derive(Debug, Clone)]
pub enum ResourceError {
NotFound(String),
}

#[derive(Debug, Clone)]
pub enum RequestError {
QueryInvalid(String),
Expand Down Expand Up @@ -65,6 +71,9 @@ impl fmt::Display for LumniError {
LumniError::Invoke(app_err, Some(app_name)) => {
write!(f, "[{}]: {}", app_name, app_err)
}
LumniError::Resource(res_err) => {
write!(f, "ResourceError: {:?}", res_err)
}
LumniError::Invoke(app_err, None) => {
write!(f, "InvokeError: {}", app_err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ async fn handle_window_event(
app.get_conversation_id_for_active_session(),
)
.await?;
Ok(window_event)
// refresh at least once after opening modal
app.is_processing = true;
Ok(WindowEvent::Modal(ModalAction::Refresh))
}
ModalAction::Event(ref user_event) => {
handle_modal_user_event(app, user_event, db_conn).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use lumni::api::error::ApplicationError;
use super::key_event::KeyTrack;
use super::text_window_event::handle_text_window_event;
use super::{
AppUi, LineType, PromptAction, PromptWindow, TextWindowTrait, WindowEvent,
AppUi, LineType, PromptAction, TextArea, TextWindowTrait, WindowEvent,
};
use crate::apps::builtin::llm::prompt::src::tui::WindowKind;
pub use crate::external as lumni;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub fn handle_prompt_window_event(
return Ok(app_ui.set_prompt_window(true));
}
'+' => {
app_ui.set_primary_window(WindowKind::PromptWindow);
app_ui.set_primary_window(WindowKind::EditorWindow);
}
'-' => {
app_ui.set_primary_window(WindowKind::ResponseWindow);
Expand All @@ -110,7 +110,7 @@ pub fn handle_prompt_window_event(
handle_text_window_event(key_track, &mut app_ui.prompt, is_running)
}

fn is_closed_block(prompt_window: &mut PromptWindow) -> Option<bool> {
fn is_closed_block(prompt_window: &mut TextArea) -> Option<bool> {
// return None if not inside a block
// return Some(true) if block is closed, else return Some(false)
let code_block = prompt_window.current_code_block();
Expand All @@ -121,7 +121,7 @@ fn is_closed_block(prompt_window: &mut PromptWindow) -> Option<bool> {
}

fn ensure_closed_block(
prompt_window: &mut PromptWindow,
prompt_window: &mut TextArea,
) -> Result<(), ApplicationError> {
if let Some(closed_block) = is_closed_block(prompt_window) {
if !closed_block {
Expand All @@ -132,7 +132,7 @@ fn ensure_closed_block(
Ok(())
}

fn in_editing_block(prompt_window: &mut PromptWindow) -> bool {
fn in_editing_block(prompt_window: &mut TextArea) -> bool {
let line_type = prompt_window.current_line_type().unwrap_or(LineType::Text);
match line_type {
LineType::Code(block_line) => !block_line.is_end(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn handle_response_window_event(
app_ui.set_primary_window(WindowKind::ResponseWindow);
}
'-' => {
app_ui.set_primary_window(WindowKind::PromptWindow);
app_ui.set_primary_window(WindowKind::EditorWindow);
}
' ' => {
if let Some(prev) = key_track.previous_key_str() {
Expand Down
2 changes: 1 addition & 1 deletion lumni/src/apps/builtin/llm/prompt/src/tui/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::clipboard::ClipboardProvider;
use super::modals::{ModalAction, ModalWindowType};
use super::ui::AppUi;
use super::window::{
LineType, MoveCursor, PromptWindow, TextDocumentTrait, TextWindowTrait,
LineType, MoveCursor, TextArea, TextDocumentTrait, TextWindowTrait,
WindowKind,
};
use super::{ConversationDbHandler, NewConversation, ThreadedChatSession};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where

let kind = match window.get_kind() {
WindowKind::ResponseWindow => WindowEvent::ResponseWindow,
WindowKind::PromptWindow => WindowEvent::PromptWindow(None),
WindowKind::EditorWindow => WindowEvent::PromptWindow(None),
WindowKind::CommandLine => WindowEvent::CommandLine(None),
};
Ok(kind)
Expand Down Expand Up @@ -207,7 +207,7 @@ where
}
let kind = match window.get_kind() {
WindowKind::ResponseWindow => WindowEvent::ResponseWindow,
WindowKind::PromptWindow => WindowEvent::PromptWindow(None),
WindowKind::EditorWindow => WindowEvent::PromptWindow(None),
WindowKind::CommandLine => WindowEvent::CommandLine(None),
};
Ok(kind)
Expand Down
6 changes: 3 additions & 3 deletions lumni/src/apps/builtin/llm/prompt/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use lumni::api::error::ApplicationError;
pub use modals::{ModalAction, ModalWindowTrait, ModalWindowType};
pub use ui::AppUi;
pub use window::{
CommandLine, PromptWindow, ResponseWindow, SimpleString, TextLine,
TextSegment, TextWindowTrait, WindowKind,
CommandLine, ResponseWindow, SimpleString, TextArea, TextLine, TextSegment,
TextWindowTrait, WindowKind,
};

use super::chat::db::{
Conversation, ConversationDatabase, ConversationDbHandler, ConversationId,
ConversationStatus, MaskMode, ModelSpec, UserProfile, UserProfileDbHandler,
ConversationStatus, MaskMode, UserProfile, UserProfileDbHandler,
};
use super::chat::{
App, NewConversation, PromptInstruction, ThreadedChatSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use ratatui::widgets::{
use ratatui::Frame;

use super::{
ApplicationError, CommandLine, Conversation, ConversationDbHandler,
ConversationStatus, KeyTrack, ModalAction, ModalWindowTrait,
ModalWindowType, PromptInstruction, TextWindowTrait, ThreadedChatSession,
ApplicationError, Conversation, ConversationDbHandler, ConversationStatus,
KeyTrack, ModalAction, ModalWindowTrait, ModalWindowType,
PromptInstruction, TextArea, TextWindowTrait, ThreadedChatSession,
UserEvent, WindowEvent,
};
use crate::apps::builtin::llm::prompt::src::chat::db::ConversationId;
Expand All @@ -31,7 +31,7 @@ pub struct ConversationListModal<'a> {
conversations: Vec<Conversation>,
current_tab: ConversationStatus,
tab_indices: HashMap<ConversationStatus, usize>,
edit_name_line: Option<CommandLine<'a>>,
edit_name_line: Option<TextArea<'a>>,
editing_index: Option<usize>,
last_selected_conversation_id: Option<ConversationId>,
}
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a> ConversationListModal<'a> {

async fn edit_conversation_name(&mut self) -> Result<(), ApplicationError> {
if let Some(conversation) = self.get_current_conversation() {
let mut command_line = CommandLine::new();
let mut command_line = TextArea::new();
command_line.text_set(&conversation.name, None)?;
command_line.set_status_insert();
self.edit_name_line = Some(command_line);
Expand Down
Loading

0 comments on commit 250f26b

Please sign in to comment.