Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## $(date +%Y-%m-%d) - [CLI Cursor UX Fix]
Comment thread
badMade marked this conversation as resolved.
**Learning:** This app is a Rust CLI, not a web frontend. Standard web accessibility rules (ARIA labels, DOM structure) do not apply. UX improvements here involve terminal manipulation (using `crossterm` for ANSI output, cursor hiding, colors, text alignment). Hiding the terminal cursor during a `Spinner` animation prevents the cursor from awkwardly jumping or rendering alongside spinner frames.
**Action:** When implementing CLI UX changes that modify terminal state (like hiding a cursor), ALWAYS implement a `Drop` trait to ensure the state (like cursor visibility) is predictably restored if the process is interrupted or panics.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __pycache__/
archive/
.omx/
.clawd-agents/
.port_sessions/

# Rust build artifacts (also in rust/.gitignore)
target/
Expand Down
2 changes: 0 additions & 2 deletions rust/.claw/sessions/session-1775386832313-0.jsonl

This file was deleted.

2 changes: 0 additions & 2 deletions rust/.claw/sessions/session-1775386842352-0.jsonl

This file was deleted.

2 changes: 0 additions & 2 deletions rust/.claw/sessions/session-1775386852257-0.jsonl

This file was deleted.

2 changes: 0 additions & 2 deletions rust/.claw/sessions/session-1775386853666-0.jsonl

This file was deleted.

83 changes: 76 additions & 7 deletions rust/crates/rusty-claude-cli/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Write as FmtWrite;
use std::io::{self, Write};
Comment thread
badMade marked this conversation as resolved.

use crossterm::cursor::{MoveToColumn, RestorePosition, SavePosition};
use crossterm::cursor::{Hide, MoveToColumn, RestorePosition, SavePosition, Show};
use crossterm::style::{Color, Print, ResetColor, SetForegroundColor, Stylize};
use crossterm::terminal::{Clear, ClearType};
use crossterm::{execute, queue};
Expand Down Expand Up @@ -47,6 +47,16 @@ impl Default for ColorTheme {
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Spinner {
frame_index: usize,
cursor_hidden: bool,
}

impl Drop for Spinner {
fn drop(&mut self) {
if self.cursor_hidden {
let mut out = io::stdout();
let _ = execute!(out, Show);
Comment thread
badMade marked this conversation as resolved.
Comment on lines +56 to +57

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore cursor using the spinner output writer

Spinner::drop always emits Show to io::stdout(), but tick hides the cursor on whichever writer the caller passed in. When a non-stdout writer is used (e.g., stderr or an in-memory writer in tests), the hide/show pair goes to different destinations, which can leave the terminal cursor hidden or inject unexpected ANSI into stdout.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot, make changes based on the above suggestion.

}
}
}
Comment thread
badMade marked this conversation as resolved.

Comment thread
badMade marked this conversation as resolved.
impl Spinner {
Expand All @@ -63,6 +73,10 @@ impl Spinner {
theme: &ColorTheme,
out: &mut impl Write,
) -> io::Result<()> {
if !self.cursor_hidden {
queue!(out, Hide)?;
self.cursor_hidden = true;
}
let frame = Self::FRAMES[self.frame_index % Self::FRAMES.len()];
self.frame_index += 1;
queue!(
Expand All @@ -85,14 +99,19 @@ impl Spinner {
out: &mut impl Write,
) -> io::Result<()> {
self.frame_index = 0;
execute!(
let show_result = execute!(
out,
MoveToColumn(0),
Clear(ClearType::CurrentLine),
SetForegroundColor(theme.spinner_done),
Print(format!("✔ {label}\n")),
ResetColor
)?;
ResetColor,
Show
);
if show_result.is_ok() {
self.cursor_hidden = false;
}
show_result?;
out.flush()
Comment thread
badMade marked this conversation as resolved.
}

Expand All @@ -103,14 +122,19 @@ impl Spinner {
out: &mut impl Write,
) -> io::Result<()> {
self.frame_index = 0;
execute!(
let show_result = execute!(
out,
MoveToColumn(0),
Clear(ClearType::CurrentLine),
SetForegroundColor(theme.spinner_failed),
Print(format!("✘ {label}\n")),
ResetColor
)?;
ResetColor,
Show
);
if show_result.is_ok() {
self.cursor_hidden = false;
}
show_result?;
out.flush()
}
Comment thread
badMade marked this conversation as resolved.
}
Expand Down Expand Up @@ -909,6 +933,7 @@ fn strip_ansi(input: &str) -> String {
#[cfg(test)]
mod tests {
use super::{strip_ansi, MarkdownStreamState, Spinner, TerminalRenderer};
use std::io::{self, Write};

#[test]
fn renders_markdown_with_styling_and_lists() {
Expand Down Expand Up @@ -1063,4 +1088,48 @@ mod tests {
let output = String::from_utf8_lossy(&out);
assert!(output.contains("Working"));
}

struct AlwaysFailWriter;

impl Write for AlwaysFailWriter {
fn write(&mut self, _buf: &[u8]) -> io::Result<usize> {
Err(io::Error::other("write failed"))
}

fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

#[test]
fn spinner_finish_error_keeps_cursor_hidden_for_drop_recovery() {
let terminal_renderer = TerminalRenderer::new();
let mut spinner = Spinner::new();
let mut out = Vec::new();
spinner
.tick("Working", terminal_renderer.color_theme(), &mut out)
.expect("tick succeeds");

let mut failing_out = AlwaysFailWriter;
let result = spinner.finish("Done", terminal_renderer.color_theme(), &mut failing_out);

assert!(result.is_err());
assert!(spinner.cursor_hidden);
}

#[test]
fn spinner_fail_error_keeps_cursor_hidden_for_drop_recovery() {
let terminal_renderer = TerminalRenderer::new();
let mut spinner = Spinner::new();
let mut out = Vec::new();
spinner
.tick("Working", terminal_renderer.color_theme(), &mut out)
.expect("tick succeeds");

let mut failing_out = AlwaysFailWriter;
let result = spinner.fail("Done", terminal_renderer.color_theme(), &mut failing_out);

assert!(result.is_err());
assert!(spinner.cursor_hidden);
}
}