Honor system reduced-motion preferences in the TUI (#44666)

## Why

The TUI should respect the host's accessibility preference even when `tui.animations` is enabled.

## What changed

- Read the system motion preference once at launch on macOS, Windows, and Linux. Changes to that preference require restarting the TUI.
- Suppress animations when reduced motion is requested without changing saved configuration. Preserve configured behavior when detection is unavailable, and limit the Linux portal query to 250 ms.
- Use the effective animation setting for voice controls and transcripts, and honor system reduced motion in the startup composer.

## Testing

Add tests for animation preference resolution and preservation of saved settings, plus composer snapshots without sparkles at widths of 40 and 80 columns.

GitOrigin-RevId: 3ea4e721ae23220a040a06123a27286a8c8f1c7c
This commit is contained in:
Ian MacLeod authored and copyberry committed 2026-09-10 22:55:04 +00:00
1 parent 84ed5744d9
commit 78600239a1
15 files changed
+240 -21

No files matched your search

+2 -2
View File
@@ -1193,7 +1193,7 @@ impl ChatWidget {
.wrapping_add(/*rhs*/ 1);
self.realtime_conversation.transcript_input_generation =
Some(self.realtime_conversation.input_generation);
if interrupted && self.config.animations {
if interrupted && self.local_settings.tui.animations {
self.realtime_conversation.interruption_acknowledged_until =
Some(Instant::now() + INTERRUPTION_ACKNOWLEDGMENT);
}
@@ -1273,7 +1273,7 @@ impl ChatWidget {
&self.realtime_conversation.transcript,
previous,
discarded_prefix_bytes,
MotionMode::from_animations_enabled(self.config.animations),
MotionMode::from_animations_enabled(self.local_settings.tui.animations),
self.frame_requester.clone(),
);
self.realtime_conversation.live_transcript_cell = Some(Box::new(live_cell));
@@ -268,7 +268,7 @@ impl ChatWidget {
.map(|(_, speaker)| *speaker)
.collect(),
activity,
animations: self.config.animations,
animations: self.local_settings.tui.animations,
}));
}
}
@@ -120,7 +120,7 @@ async fn voice_composer_preserves_normal_colors_across_microphone_states() {
assert_eq!(marker.fg, Color::Red);
assert_ne!(marker.bg, Color::Red);
}
if recording && chat.config.animations {
if recording && chat.local_settings.tui.animations {
let rows = buffer
.content
.chunks(/*chunk_size*/ 47)
@@ -159,7 +159,7 @@ async fn voice_composer_preserves_normal_colors_across_microphone_states() {
.unwrap()
};
let foreground = check(&mut chat, /*recording*/ true);
chat.config.animations = false;
chat.local_settings.tui.animations = false;
assert_eq!(check(&mut chat, /*recording*/ true), foreground);
chat.realtime_conversation.microphone_muted = true;
assert_eq!(check(&mut chat, /*recording*/ false), foreground);
@@ -188,7 +188,7 @@ async fn voice_preserves_the_normal_composer_prompt() {
}
for (muted, animations) in [(true, true), (false, false), (false, true)] {
chat.realtime_conversation.microphone_muted = muted;
chat.config.animations = animations;
chat.local_settings.tui.animations = animations;
assert_eq!(prompt(&mut chat), Some('›'));
}
chat.thread_id = Some(ThreadId::new());
@@ -356,7 +356,7 @@ async fn voice_footer_renders_the_main_conversation_states() {
"Hello there",
),
] {
chat.config.animations = label != "connecting";
chat.local_settings.tui.animations = label != "connecting";
chat.realtime_conversation.phase = phase;
chat.realtime_conversation.microphone_muted = muted;
chat.realtime_conversation.microphone_level = level;
@@ -402,7 +402,7 @@ async fn voice_footer_renders_the_main_conversation_states() {
#[tokio::test]
async fn narrow_voice_footer_keeps_the_stop_control_before_meters() {
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = true;
chat.local_settings.tui.animations = true;
activate_voice(&mut chat);
chat.realtime_conversation.speaker_active_until =
Some(std::time::Instant::now() + super::super::SPEAKER_ACTIVITY_HOLD);
@@ -474,7 +474,7 @@ async fn narrow_voice_footer_keeps_the_stop_control_before_meters() {
#[tokio::test]
async fn voice_acknowledges_only_a_real_interruption_once() {
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = true;
chat.local_settings.tui.animations = true;
activate_voice(&mut chat);
chat.on_realtime_transcript_delta("user".to_string(), "hello".to_string());
@@ -503,7 +503,7 @@ async fn voice_acknowledges_only_a_real_interruption_once() {
.is_none()
);
chat.config.animations = false;
chat.local_settings.tui.animations = false;
chat.realtime_conversation.speaker_level = 3;
chat.on_realtime_transcript_delta("user".to_string(), "stop".to_string());
assert!(
@@ -619,7 +619,7 @@ async fn clipped_voice_composer_keeps_the_draft_and_cursor_visible() {
use ratatui::prelude::Rect;
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = false;
chat.local_settings.tui.animations = false;
activate_voice(&mut chat);
chat.bottom_pane
.set_composer_text("typed".to_string(), Vec::new(), Vec::new());
@@ -666,7 +666,7 @@ async fn clipped_voice_composer_keeps_the_draft_and_cursor_visible() {
#[tokio::test]
async fn compact_voice_meters_keep_real_speaker_history_when_the_microphone_is_muted() {
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = false;
chat.local_settings.tui.animations = false;
let thread_id = activate_voice(&mut chat);
chat.realtime_conversation.audio_meter_history = [
(0, 255),
@@ -327,7 +327,7 @@ async fn captioned_voice_answer_does_not_duplicate_on_close() {
#[tokio::test]
async fn restored_partial_caption_accepts_late_completion_without_duplicate_history() {
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = false;
chat.local_settings.tui.animations = false;
chat.restore_realtime_transcript_cells(VecDeque::from([
super::super::RealtimeTranscriptRecord {
role: "user".into(),
@@ -194,7 +194,7 @@ async fn transcript_deltas_track_the_current_speaker() {
#[tokio::test]
async fn voice_transcripts_stream_in_the_conversation_instead_of_the_footer() {
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = false;
chat.local_settings.tui.animations = false;
activate_voice(&mut chat);
chat.update_realtime_footer();
@@ -427,7 +427,7 @@ async fn direct_reset_preserves_both_partial_speakers_for_replay() {
async fn stopping_voice_preserves_the_live_transcript_once() {
for command in ["/voice", "/voice stop"] {
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = true;
chat.local_settings.tui.animations = true;
activate_voice(&mut chat);
chat.on_realtime_transcript_done("user".to_string(), "Earlier question".to_string());
chat.on_realtime_transcript_done("assistant".to_string(), "Earlier answer".to_string());
@@ -526,7 +526,7 @@ async fn transcript_completion_waits_for_normal_agent_stream_consolidation() {
#[tokio::test]
async fn transcript_handoff_moves_deferred_repeats_and_partial_once() {
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = false;
chat.local_settings.tui.animations = false;
activate_voice(&mut chat);
chat.on_agent_message_delta("ordinary stream".to_string());
for _ in 0..super::super::MAX_PENDING_TRANSCRIPT_CELLS {
@@ -699,7 +699,7 @@ async fn completed_transcript_preserves_the_other_speakers_caption() {
#[tokio::test]
async fn live_voice_split_flap_animates_without_changing_final_history() {
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
chat.config.animations = true;
chat.local_settings.tui.animations = true;
activate_voice(&mut chat);
chat.on_realtime_transcript_delta("assistant".to_string(), "gate 73".to_string());
@@ -749,7 +749,7 @@ async fn spoken_user_transcript_preserves_red_chevron_and_canonical_history() {
.add_modifier
.contains(ratatui::style::Modifier::BOLD)
);
chat.config.animations = false;
chat.local_settings.tui.animations = false;
chat.on_realtime_transcript_delta("user".to_string(), " world".to_string());
assert!(
chat.realtime_conversation
@@ -14,7 +14,7 @@ use serial_test::serial;
#[tokio::test]
async fn voice_live_transcript_renders_beside_the_streamed_cell() {
let (mut chat, _rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;
chat.config.animations = false;
chat.local_settings.tui.animations = false;
activate_voice_for_thread(&mut chat, ThreadId::new());
chat.transcript.active_cell = Some(Box::new(history_cell::StreamingAgentTailCell::new(
vec![Line::from("Agent answer arriving").into()],