Skip to content

Commit 1d2fbee

Browse files
committed
feat: soft world wrap in promt field, layou fixes
1 parent 73c9263 commit 1d2fbee

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
rig-core = { git = "https://github.com/kosz78/rig.git", branch = "mcp", features = ["mcp"] }
7+
rig-core = { git = "https://github.com/kosz78/rig.git", branch = "mcp", features = [
8+
"mcp",
9+
] }
810
mcp-core = { version = "0.1.50", features = ["sse"] }
911
# memory related
1012
rig-fastembed = { git = "https://github.com/kosz78/rig.git", branch = "mcp" }
@@ -14,7 +16,11 @@ indicium = "0.6.5"
1416

1517
tokio = { version = "1.34.0", features = ["full"] }
1618
serde = { version = "1.0", features = ["derive"] }
17-
reqwest = { version = "0.12.12", default-features = false, features = ["json", "stream", "rustls-tls"] }
19+
reqwest = { version = "0.12.12", default-features = false, features = [
20+
"json",
21+
"stream",
22+
"rustls-tls",
23+
] }
1824
anyhow = "1.0"
1925
schemars = "0.8.16"
2026
async-stream = "0.3.6"
@@ -51,11 +57,11 @@ headless_chrome = "1.0.17"
5157
crossterm = { version = "0.28.1", features = ["event-stream"] }
5258
ratatui = "0.29.0"
5359
color-eyre = "0.6.3"
54-
tui-textarea = "0.7.0"
60+
tui-textarea = { git = "https://github.com/kosz78/tui-textarea.git", branch = "main" }
5561
tui-tree-widget = "0.23.0"
5662
tui-widget-list = { git = "https://github.com/preiter93/tui-widget-list.git", branch = "main" }
5763
textwrap = "0.16.0"
5864
throbber-widgets-tui = "0.8.0"
5965
tui-popup = "0.6.0"
6066
format_num = "0.1.0"
61-
termimad = "0.31.3"
67+
termimad = "0.31.3"

src/tui/widgets.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ struct LayoutRects {
4040
shortcuts_area: Rect,
4141
}
4242

43-
fn build_layout(area: Rect, errors: &Option<String>) -> LayoutRects {
43+
fn build_layout(
44+
area: Rect,
45+
errors: &Option<String>,
46+
textarea: &tui_textarea::TextArea,
47+
) -> LayoutRects {
4448
let main_layout = Layout::default()
4549
.direction(Direction::Vertical)
4650
.constraints([
@@ -69,27 +73,32 @@ fn build_layout(area: Rect, errors: &Option<String>) -> LayoutRects {
6973
.map(|s| textwrap::wrap(s, left_area.width as usize - 5).len())
7074
.unwrap_or(0);
7175

76+
let input_text_lines_count = textarea
77+
.lines()
78+
.iter()
79+
.map(|s| textwrap::wrap(s, left_area.width as usize - 5).len())
80+
.sum::<usize>() as u16;
7281
// Left panel (chat history + input)
7382
let (task_area, chat_area, error_area, status_area, input_area) = if error_lines_count > 0 {
7483
let rects = Layout::default()
7584
.direction(Direction::Vertical)
7685
.constraints([
77-
Constraint::Length(4), // Task panel
78-
Constraint::Fill(3), // Chat history
79-
Constraint::Max(u16::min(10, error_lines_count as u16)), // Error message
80-
Constraint::Length(1), // Task progress status
81-
Constraint::Length(3), // Input field
86+
Constraint::Length(4), // Task panel
87+
Constraint::Fill(3), // Chat history
88+
Constraint::Max(10.min(error_lines_count as u16)), // Error message
89+
Constraint::Length(1), // Task progress status
90+
Constraint::Length(6.min(input_text_lines_count) + 1), // Input field
8291
])
8392
.split(left_area);
8493
(rects[0], rects[1], rects[2], rects[3], rects[4])
8594
} else {
8695
let rects = Layout::default()
8796
.direction(Direction::Vertical)
8897
.constraints([
89-
Constraint::Length(4), // Task panel
90-
Constraint::Min(3), // Chat history
91-
Constraint::Length(1), // Task progress status
92-
Constraint::Length(3), // Input field
98+
Constraint::Length(4), // Task panel
99+
Constraint::Min(3), // Chat history
100+
Constraint::Length(1), // Task progress status
101+
Constraint::Length(6.min(input_text_lines_count) + 1), // Input field
93102
])
94103
.split(left_area);
95104
(rects[0], rects[1], Rect::default(), rects[2], rects[3])
@@ -126,7 +135,7 @@ impl Widget for &mut App<'_> {
126135

127136
buf.set_style(area, Style::default().bg(theme.background).fg(theme.text));
128137

129-
let layout = build_layout(area, &self.model.last_error);
138+
let layout = build_layout(area, &self.model.last_error, &self.ui.textarea);
130139

131140
ToolbarWidget.render(layout.toolbar_area, buf, &theme, &self.config);
132141

@@ -265,6 +274,8 @@ impl Widget for &mut App<'_> {
265274
// Create a TextArea with the App's input text
266275
self.ui.textarea.set_block(input_block);
267276
self.ui.textarea.set_style(theme.text_style());
277+
self.ui.textarea.set_wrap(true);
278+
self.ui.textarea.set_cursor_line_style(theme.text_style());
268279
self.ui
269280
.textarea
270281
.set_placeholder_style(theme.inactive_style());

0 commit comments

Comments
 (0)