Skip to content

Commit

Permalink
refactor text_buffer, text_display
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Aug 5, 2024
1 parent 88c31b8 commit 1e89b17
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 611 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn handle_prompt_window_event(
return Ok(Some(app_ui.set_response_window()));
}
}
},
}
KeyCode::Tab => {
if !in_editing_block(&mut app_ui.prompt) {
return Ok(Some(app_ui.prompt.next_window_status()));
Expand Down Expand Up @@ -99,7 +99,9 @@ pub fn handle_prompt_window_event(
if let Some(prev) = key_track.previous_key_str() {
if prev == " " {
// change to insert mode if double space
return Ok(Some(app_ui.set_prompt_window(true)));
return Ok(Some(
app_ui.set_prompt_window(true),
));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn handle_response_window_event(
// jump from response window to prompt window
return Ok(Some(app_ui.set_prompt_window(true)));
}
},
}
KeyCode::Tab => {
return Ok(Some(app_ui.set_prompt_window(false)));
}
Expand Down Expand Up @@ -60,7 +60,9 @@ pub fn handle_response_window_event(
if let Some(prev) = key_track.previous_key_str() {
if prev == " " {
// change to insert mode if double space
return Ok(Some(app_ui.set_prompt_window(true)));
return Ok(Some(
app_ui.set_prompt_window(true),
));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,11 @@ where
window.move_cursor(MoveCursor::EndOfFile);
}
'j' => {
let lines_to_move =
key_track.take_numeric_input().unwrap_or(1);
let lines_to_move = key_track.take_numeric_input().unwrap_or(1);
window.move_cursor(MoveCursor::Down(lines_to_move));
}
'k' => {
let lines_to_move =
key_track.take_numeric_input().unwrap_or(1);
let lines_to_move = key_track.take_numeric_input().unwrap_or(1);
window.move_cursor(MoveCursor::Up(lines_to_move));
}
'v' => {
Expand Down
2 changes: 1 addition & 1 deletion lumni/src/apps/builtin/llm/prompt/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ pub use super::chat::{
pub use super::server::{
ModelServer, ServerManager, ServerTrait, SUPPORTED_MODEL_ENDPOINTS,
};
pub use crate::external as lumni;
use crate::external as lumni;
46 changes: 26 additions & 20 deletions lumni/src/apps/builtin/llm/prompt/src/tui/window/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{text_document::TextLine, TextDocumentTrait};
use super::text_document::TextLine;
use super::TextDocumentTrait;

#[derive(Debug, Clone)]
pub enum MoveCursor {
Expand All @@ -17,8 +18,8 @@ pub enum MoveCursor {
pub struct Cursor {
pub col: usize,
pub row: usize,
anchor_col: usize, // column for anchor, start of selection
anchor_row: usize, // row for anchor, start of selection
anchor_col: usize, // column for anchor, start of selection
anchor_row: usize, // row for anchor, start of selection
show_cursor: bool, // show current cursor position
selection_enabled: bool,
desired_col: usize, // Desired column position, independent of actual line length
Expand Down Expand Up @@ -182,23 +183,28 @@ impl Cursor {
}

pub fn get_selection_bounds(&self) -> (usize, usize, usize, usize) {
// Determine the correct order for start and end positions
if self.row < self.anchor_row
|| (self.row == self.anchor_row && self.col < self.anchor_col)
{
(
self.row as usize,
self.col as usize,
self.anchor_row as usize,
self.anchor_col as usize,
)
// Get the bounds of selected text, position based on unwrapped lines
// (start_row, start_col, end_row, end_col)
if self.selection_enabled() {
if self.row < self.anchor_row
|| (self.row == self.anchor_row && self.col < self.anchor_col)
{
(
self.row as usize,
self.col as usize,
self.anchor_row as usize,
self.anchor_col as usize,
)
} else {
(
self.anchor_row as usize,
self.anchor_col as usize,
self.row as usize,
self.col as usize,
)
}
} else {
(
self.anchor_row as usize,
self.anchor_col as usize,
self.row as usize,
self.col as usize,
)
(usize::MAX, usize::MAX, usize::MIN, usize::MIN) // No highlighting
}
}

Expand Down Expand Up @@ -240,4 +246,4 @@ impl Cursor {
}
self.real_position = position;
}
}
}
14 changes: 6 additions & 8 deletions lumni/src/apps/builtin/llm/prompt/src/tui/window/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod cursor;
mod scroller;
mod text_buffer;
mod text_display;
mod text_document;
mod text_render;
mod text_window;
mod window_config;

Expand All @@ -13,16 +11,17 @@ use lumni::api::error::ApplicationError;
use ratatui::layout::Rect;
use ratatui::style::{Color, Style};
pub use scroller::Scroller;
pub use text_buffer::TextBuffer;
pub use text_display::LineType;
pub use text_document::{
ReadDocument, ReadWriteDocument, TextDocumentTrait, TextLine, TextSegment,
};
pub use text_window::{TextWindow, TextWindowTrait};
pub use window_config::{WindowConfig, WindowKind, WindowStatus, WindowContent};
pub use super::events::WindowEvent;
pub use super::events::KeyTrack;
pub use crate::external as lumni;
pub use window_config::{
WindowConfig, WindowContent, WindowKind, WindowStatus,
};

use super::events::{KeyTrack, WindowEvent};
use crate::external as lumni;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RectArea {
Expand Down Expand Up @@ -108,7 +107,6 @@ impl PromptWindow<'_> {

self.set_window_status(next_status);
return WindowEvent::PromptWindow(None);

}
}

Expand Down
173 changes: 0 additions & 173 deletions lumni/src/apps/builtin/llm/prompt/src/tui/window/text_display.rs

This file was deleted.

Loading

0 comments on commit 1e89b17

Please sign in to comment.