Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent-tui): align the working row with the idle input prompt

Akarshan Biswas92d2f56e4ad4
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index 1b510bf51..4b332f07d 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -23401,6 +23401,18 @@ fn working_row(app: &App, width: u16) -> Line<'static> {
)
.remove(0)
.spans;
+ // Pad to the longest synonym so the hint stays in one column as the word
+ // rotates, and lead with the same `> ` as every other input state so the
+ // word sits where typed text will.
+ let longest = WORKING_WORDS
+ .iter()
+ .chain(THINKING_WORDS.iter())
+ .map(|w| w.chars().count())
+ .max()
+ .unwrap_or(0);
+ let pad = (longest + 1).saturating_sub(word.chars().count() + 1);
+ spans.push(Span::raw(" ".repeat(pad)));
+ spans.splice(0..0, empty_prompt_prefix());
if let Some(count) = bg_shells_count(app) {
let room = (width as usize).saturating_sub(spans_width(&spans));
if count.chars().count() <= room {
@@ -23411,6 +23423,17 @@ fn working_row(app: &App, width: u16) -> Line<'static> {
Line::from(spans)
}
+/// The `> ` prompt and the fixed block cursor that open an empty input row.
+/// Shared by the idle placeholder and the working row so their text starts in
+/// the same column.
+fn empty_prompt_prefix() -> [Span<'static>; 3] {
+ [
+ Span::styled("> ", Style::new().fg(theme::accent()).bold()),
+ Span::styled(" ", Style::new().add_modifier(Modifier::REVERSED)),
+ Span::raw(" "),
+ ]
+}
+
/// Append the longest of `hints` that still fits `width` beside `spans`, or
/// none, so an input-row hint is dropped whole rather than clipped mid-word.
fn push_fitting_hint(spans: &mut Vec<Span<'static>>, hints: &[&'static str], width: u16) {
@@ -23586,12 +23609,8 @@ fn input_box(app: &App, width: u16) -> Paragraph<'static> {
} else {
"Type here to chat with agent"
};
- let cursor_spans: Vec<Span<'static>> = vec![
- Span::styled("> ", Style::new().fg(theme::accent()).bold()),
- Span::styled(" ", Style::new().add_modifier(Modifier::REVERSED)),
- Span::raw(" "),
- Span::styled(placeholder, Style::new().dim().italic()),
- ];
+ let mut cursor_spans: Vec<Span<'static>> = empty_prompt_prefix().into();
+ cursor_spans.push(Span::styled(placeholder, Style::new().dim().italic()));
Paragraph::new(Line::from(cursor_spans)).block(block)
} else {
Paragraph::new(input_content_lines(&app.input, app.cursor))
@@ -37359,6 +37378,44 @@ mod tests {
);
}
+ /// The idle placeholder, the working row and the thinking row open with the
+ /// same `> ` + cursor cell, so their text starts in one column, and the
+ /// working/thinking hint stays in one column whatever the rotating word.
+ #[test]
+ fn idle_working_and_thinking_rows_align() {
+ use unicode_width::UnicodeWidthStr;
+ let col = |row: &str, needle: &str| row.find(needle).map(|i| row[..i].width());
+ let mut app = test_app();
+ let idle = render_rows(&mut app, 80, 12)
+ .into_iter()
+ .find(|r| r.contains("Type here to chat"))
+ .expect("idle placeholder");
+ let idle_text = col(&idle, "Type here").unwrap();
+
+ app.submit_user("go".into());
+ let mut hint_cols = Vec::new();
+ for think in [false, true] {
+ if think {
+ app.apply(StreamEvent::Token {
+ text: "<think>ponder".into(),
+ });
+ }
+ for step in 0..12 {
+ app.spinner_frame = step * super::WORD_ROTATE_FRAMES;
+ let row = render_rows(&mut app, 80, 12)
+ .into_iter()
+ .find(|r| r.contains("(Esc to cancel, type to steer"))
+ .expect("running row");
+ assert!(row.starts_with("> "), "{row:?}");
+ let words = if think { &THINKING_WORDS } else { &WORKING_WORDS };
+ let word = words.iter().find(|w| row.contains(*w)).expect("word");
+ assert_eq!(col(&row, word), Some(idle_text), "{row:?}");
+ hint_cols.push(col(&row, "(Esc").unwrap());
+ }
+ }
+ assert!(hint_cols.windows(2).all(|w| w[0] == w[1]), "{hint_cols:?}");
+ }
+
/// Thinking synonyms are coloured orange so the active reasoning state
/// stands out from the quiet working rows.
#[test]
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_diff_ansi16.snap b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_diff_ansi16.snap
index be68edf10..9645058dd 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_diff_ansi16.snap
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_diff_ansi16.snap
@@ -21,7 +21,7 @@ expression: render_snapshot(buf)
|│ Allow always (this thread) │|
|│ Deny │|
|╰────────────────────────────────────────────────────────────────────╯|
-|working… (Esc to cancel, type to steer the agent) |
+|> working… (Esc to cancel, type to steer the agent) |
| |
| ↑/↓ select Enter confirm Esc deny Ctrl-C cancel |
@@ -63,7 +63,10 @@ expression: render_snapshot(buf)
17 0..1 fg=Yellow
17 69..70 fg=Yellow
18 0..70 fg=Yellow
-19 0..49 mod=DIM | ITALIC
+19 0..2 fg=Cyan mod=BOLD
+19 2..3 mod=REVERSED
+19 4..12 mod=DIM | ITALIC
+19 18..59 mod=DIM | ITALIC
21 1..4 fg=Yellow mod=BOLD
21 4..11 mod=DIM
21 14..19 fg=Yellow mod=BOLD
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_exec.snap b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_exec.snap
index 9e5aa5b3d..0ce3e4526 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_exec.snap
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_exec.snap
@@ -19,7 +19,7 @@ expression: render_snapshot(buf)
|│ Allow all 'cargo', 'git' commands (this thread) │|
|│ Deny │|
|╰──────────────────────────────────────────────────────────────────────────────╯|
-|working… (Esc to cancel, type to steer the agent) |
+|> working… (Esc to cancel, type to steer the agent) |
| |
|📂 /snapshot/repo ↑/↓ select Enter confirm Esc deny Ctrl-C cancel|
@@ -47,7 +47,10 @@ expression: render_snapshot(buf)
15 0..1 fg=#E5C07B
15 79..80 fg=#E5C07B
16 0..80 fg=#E5C07B
-17 0..49 mod=DIM | ITALIC
+17 0..2 fg=#56B6C2 mod=BOLD
+17 2..3 mod=REVERSED
+17 4..12 mod=DIM | ITALIC
+17 18..59 mod=DIM | ITALIC
19 0..1 fg=#808080
19 2..17 fg=#808080
19 27..30 fg=#E5C07B mod=BOLD
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_subagent_queued.snap b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_subagent_queued.snap
index 7105f40db..58cd24c02 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_subagent_queued.snap
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/permission_prompt_subagent_queued.snap
@@ -17,7 +17,7 @@ expression: render_snapshot(buf)
|│ ▶ Allow once │|
|│ Deny │|
|╰──────────────────────────────────────────────────────────────────────╯|
-|working… (Esc to cancel, type to steer the agent) |
+|> working… (Esc to cancel, type to steer the agent) |
| |
| ↑/↓ select Enter confirm Esc deny Ctrl-C cancel |
@@ -48,7 +48,10 @@ expression: render_snapshot(buf)
13 0..1 fg=#E5C07B
13 71..72 fg=#E5C07B
14 0..72 fg=#E5C07B
-15 0..49 mod=DIM | ITALIC
+15 0..2 fg=#56B6C2 mod=BOLD
+15 2..3 mod=REVERSED
+15 4..12 mod=DIM | ITALIC
+15 18..59 mod=DIM | ITALIC
17 1..4 fg=#E5C07B mod=BOLD
17 4..11 mod=DIM
17 14..19 fg=#E5C07B mod=BOLD
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_single_phase.snap b/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_single_phase.snap
index d1285138a..eb4761fe9 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_single_phase.snap
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_single_phase.snap
@@ -1,6 +1,5 @@
---
source: src/core/cli/tui/tests/snapshot.rs
-assertion_line: 162
expression: render_snapshot(buf)
---
| 👋 gpt-5-mini effort medium ctx 0K/128K fallback ◉ [working] |
@@ -16,7 +15,7 @@ expression: render_snapshot(buf)
| ☐ write the docs |
| ☒ support windows xp |
|────────────────────────────────────────────────────────────────────────────────|
-|working… (Esc to cancel, type to steer the agent) |
+|> working… (Esc to cancel, type to steer the agent) |
| |
|📂 /snapshot/repo Esc/Ctrl-C cancel PgUp/PgDn scroll Ctrl-O expand all|
@@ -38,7 +37,10 @@ expression: render_snapshot(buf)
9 1..18 fg=#56B6C2
10 1..17 mod=DIM
11 1..21 fg=Red mod=CROSSED_OUT
-13 0..49 mod=DIM | ITALIC
+13 0..2 fg=#56B6C2 mod=BOLD
+13 2..3 mod=REVERSED
+13 4..12 mod=DIM | ITALIC
+13 18..59 mod=DIM | ITALIC
15 0..1 fg=#808080
15 2..17 fg=#808080
15 24..34 fg=#56B6C2 mod=BOLD
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_split_with_agents.snap b/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_split_with_agents.snap
index 82698c1aa..83400a35d 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_split_with_agents.snap
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_split_with_agents.snap
@@ -1,6 +1,5 @@
---
source: src/core/cli/tui/tests/snapshot.rs
-assertion_line: 162
expression: render_snapshot(buf)
---
| 👋 gpt-5-mini effort medium ctx 0K/128K fallback ◉ [working] |
@@ -18,7 +17,7 @@ expression: render_snapshot(buf)
| ☐ routes │ review the file |
| ☐ auth │ Read mod_5.rs |
|────────────────────────────────────────────────────────────────────────────────────────────────────|
-|working… (Esc to cancel, type to steer the agent) |
+|> working… (Esc to cancel, type to steer the agent) |
| |
|📂 /snapshot/repo Esc/Ctrl-C cancel PgUp/PgDn scroll Ctrl-O expand all|
@@ -51,7 +50,10 @@ expression: render_snapshot(buf)
13 1..7 mod=DIM
13 48..51 fg=#808080
13 54..67 fg=#808080
-15 0..49 mod=DIM | ITALIC
+15 0..2 fg=#56B6C2 mod=BOLD
+15 2..3 mod=REVERSED
+15 4..12 mod=DIM | ITALIC
+15 18..59 mod=DIM | ITALIC
17 0..1 fg=#808080
17 2..17 fg=#808080
17 44..54 fg=#56B6C2 mod=BOLD
diff --git a/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_stacked_narrow.snap b/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_stacked_narrow.snap
index d56849050..89e5ce976 100644
--- a/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_stacked_narrow.snap
+++ b/src-tauri/src/core/cli/tui/tests/snapshots/todo_panel_stacked_narrow.snap
@@ -1,6 +1,5 @@
---
source: src/core/cli/tui/tests/snapshot.rs
-assertion_line: 162
expression: render_snapshot(buf)
---
| 👋 gpt-5-mini effort medium ctx 0K/128K fallback ◉ [wo|
@@ -18,7 +17,7 @@ expression: render_snapshot(buf)
| review the file |
| Read mod_1.rs |
|────────────────────────────────────────────────────────────|
-|working… (Esc to cancel, type to steer the agent) |
+|> working… (Esc to cancel, type to steer the agent) |
| |
| Esc/Ctrl-C cancel PgUp/PgDn scroll Ctrl-O expand all |
@@ -45,7 +44,10 @@ expression: render_snapshot(buf)
11 14..21 fg=#808080
12 3..18 mod=DIM | ITALIC
13 3..16 fg=#808080
-15 0..49 mod=DIM | ITALIC
+15 0..2 fg=#56B6C2 mod=BOLD
+15 2..3 mod=REVERSED
+15 4..12 mod=DIM | ITALIC
+15 18..59 mod=DIM | ITALIC
17 1..11 fg=#56B6C2 mod=BOLD
17 11..18 mod=DIM
17 21..30 fg=#56B6C2 mod=BOLD