| 1 | use super::*; |
| 2 | use codewhale_runtime::config::Config; |
| 3 | use ratatui::{buffer::Buffer, style::Color}; |
| 4 | use std::path::PathBuf; |
| 5 | |
| 6 | fn app() -> App { |
| 7 | let mut app = App::new( |
| 8 | crate::tui::test_support::test_tui_options(PathBuf::from(".")), |
| 9 | &Config::default(), |
| 10 | ); |
| 11 | app.ui_locale = codewhale_localization::Locale::En; |
| 12 | app.ui_theme.text_body = Color::Rgb(29, 47, 83); |
| 13 | app.ui_theme.panel_bg = Color::Rgb(13, 31, 59); |
| 14 | app.ui_theme.border = Color::Rgb(71, 43, 101); |
| 15 | app.ui_theme.status_working = Color::Rgb(47, 109, 67); |
| 16 | app |
| 17 | } |
| 18 | #[test] |
| 19 | fn shared_native_scroll_rail_preserves_custom_ground_and_existing_modifiers() { |
| 20 | let app = app(); |
| 21 | for height in 0..=12 { |
| 22 | for total in [0, 1, 8, 128] { |
| 23 | let area = Rect::new(7, 5, 1, height); |
| 24 | let mut expected = Buffer::empty(Rect::new(2, 3, 30, 20)); |
| 25 | for cell in &mut expected.content { |
| 26 | cell.set_symbol("~").set_style( |
| 27 | Style::default() |
| 28 | .bg(Color::Green) |
| 29 | .add_modifier(Modifier::ITALIC | Modifier::REVERSED), |
| 30 | ); |
| 31 | } |
| 32 | let mut actual = expected.clone(); |
| 33 | // Exact old rail formula with the host's original foreground/background assignments. |
| 34 | if height > 0 && total > 0 { |
| 35 | let h = usize::from(height); |
| 36 | let size = (h * 3 / total).max(1).min(h); |
| 37 | let start = |
| 38 | 2usize.saturating_mul(h.saturating_sub(size)) / total.saturating_sub(3).max(1); |
| 39 | for row in 0..h { |
| 40 | let active = row >= start && row < start.saturating_add(size); |
| 41 | expected[(7, 5 + row as u16)] |
| 42 | .set_symbol(if active { "┃" } else { "│" }) |
| 43 | .set_fg(if active { |
| 44 | app.ui_theme.status_working |
| 45 | } else { |
| 46 | app.ui_theme.border |
| 47 | }) |
| 48 | .set_bg(app.ui_theme.panel_bg); |
| 49 | } |
| 50 | } |
| 51 | codewhale_ratatui::WorkbarScrollbar { |
| 52 | offset: 2, |
| 53 | visible: 3, |
| 54 | total, |
| 55 | thumb: "┃", |
| 56 | track: "│", |
| 57 | thumb_style: Style::default() |
| 58 | .fg(app.ui_theme.status_working) |
| 59 | .bg(app.ui_theme.panel_bg), |
| 60 | track_style: Style::default() |
| 61 | .fg(app.ui_theme.border) |
| 62 | .bg(app.ui_theme.panel_bg), |
| 63 | } |
| 64 | .paint(area, &mut actual); |
| 65 | assert_eq!(actual, expected, "height={height} total={total}"); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 |