Skip to content

Commit e459fde

Browse files
committed
fix: Rework history and message view
1 parent 18103ff commit e459fde

File tree

8 files changed

+287
-137
lines changed

8 files changed

+287
-137
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ratatui = "0.29.0"
5252
color-eyre = "0.6.3"
5353
tui-textarea = "0.7.0"
5454
tui-tree-widget = "0.23.0"
55-
tui-widget-list = "0.13.2"
55+
tui-widget-list = { git = "https://github.com/preiter93/tui-widget-list.git", branch = "main" }
5656
textwrap = "0.16.0"
5757
throbber-widgets-tui = "0.8.0"
5858
tui-popup = "0.6.0"

src/agent/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl Agent {
346346

347347
match stream.next().await {
348348
Some(result) => {
349-
tracing::trace!("Received response from model: {:?}", result);
349+
//tracing::trace!("Received response from model: {:?}", result);
350350

351351
match result {
352352
Ok(AssistantContent::Text(text)) => {

src/tui/app.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl App<'_> {
368368
if focus == 0 {
369369
focus = FocusedComponent::Terminal as u8;
370370
} else {
371-
focus = focus - 1;
371+
focus -= 1;
372372
}
373373
self.ui.focus = focus.into();
374374
}
@@ -379,10 +379,10 @@ impl App<'_> {
379379
if key_event.modifiers == KeyModifiers::ALT =>
380380
{
381381
match key_event.code {
382-
KeyCode::Char('1') => self.ui.focus = FocusedComponent::Input.into(),
383-
KeyCode::Char('2') => self.ui.focus = FocusedComponent::History.into(),
384-
KeyCode::Char('3') => self.ui.focus = FocusedComponent::Tree.into(),
385-
KeyCode::Char('4') => self.ui.focus = FocusedComponent::Terminal.into(),
382+
KeyCode::Char('1') => self.ui.focus = FocusedComponent::Input,
383+
KeyCode::Char('2') => self.ui.focus = FocusedComponent::History,
384+
KeyCode::Char('3') => self.ui.focus = FocusedComponent::Tree,
385+
KeyCode::Char('4') => self.ui.focus = FocusedComponent::Terminal,
386386
_ => {}
387387
};
388388
}

src/tui/mod.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,78 @@ mod widgets;
99
pub use app::App;
1010
pub use theme::Theme;
1111
pub use widgets::*;
12+
13+
pub(crate) fn split_think_tags(text: &str) -> Vec<(String, bool)> {
14+
let mut result = vec![];
15+
let mut current_string = String::new();
16+
let mut tag_name = String::new();
17+
let mut is_tag_content = false;
18+
for ch in text.chars() {
19+
if ch == '<' {
20+
is_tag_content = true;
21+
if !tag_name.is_empty()
22+
&& tag_name != "think"
23+
&& tag_name != "thinking"
24+
&& tag_name != "/think"
25+
&& tag_name != "/thinking"
26+
{
27+
current_string.push_str(&format!("<{}", tag_name));
28+
}
29+
tag_name.clear();
30+
} else if ch == '>' && is_tag_content {
31+
is_tag_content = false;
32+
// start think tag
33+
if (tag_name == "think" || tag_name == "thinking") && !current_string.is_empty() {
34+
result.push((current_string.clone(), false));
35+
current_string.clear();
36+
}
37+
if tag_name == "/think" || tag_name == "/thinking" && !current_string.is_empty() {
38+
result.push((current_string.clone(), true));
39+
current_string.clear();
40+
}
41+
} else if is_tag_content {
42+
tag_name.push(ch);
43+
} else {
44+
current_string.push(ch);
45+
}
46+
}
47+
if tag_name != "think"
48+
&& tag_name != "thinking"
49+
&& tag_name != "/think"
50+
&& tag_name != "/thinking"
51+
{
52+
current_string.push_str(&format!("<{}", tag_name));
53+
tag_name.clear();
54+
}
55+
56+
if !current_string.is_empty() {
57+
result.push((
58+
current_string.clone(),
59+
tag_name == "think" || tag_name == "thinking",
60+
));
61+
}
62+
result
63+
}
64+
65+
#[cfg(test)]
66+
mod tests {
67+
use super::*;
68+
69+
#[test]
70+
fn test_split_think_tags() {
71+
let text =
72+
"test <think>hello <- test </think> world -> test <- test <thinking>foo -> test</thinking> bar <think>baz";
73+
let pairs = split_think_tags(text);
74+
assert_eq!(
75+
pairs,
76+
vec![
77+
("test ".to_string(), false),
78+
("hello <- test ".to_string(), true),
79+
(" world -> test <- test ".to_string(), false),
80+
("foo -> test".to_string(), true),
81+
(" bar ".to_string(), false),
82+
("baz".to_string(), true)
83+
]
84+
);
85+
}
86+
}

src/tui/theme.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ impl Theme {
106106
inactive: Color::DarkGray,
107107
status: Color::DarkGray,
108108
border: Color::Indexed(236),
109-
assistant: Color::from_u32(0x2196F3),
110-
user: Color::from_u32(0x4CAF50),
109+
assistant: Color::Indexed(75),
110+
user: Color::Indexed(113),
111111
}
112112
}
113113

0 commit comments

Comments
 (0)