revue 2.71.1

A Vue-style TUI framework for Rust with CSS styling
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
//! Common utilities for widget rendering
//!
//! This module provides shared functionality used across multiple widgets.
//! Utilities are organized by category for easy discovery.
//!
//! # Categories
//!
//! ## Text Processing
//!
//! | Module | Description | Use Case |
//!|--------|-------------|----------|
//! | [`text`] | Text truncation, padding, wrapping | Text display |
//! | [`textbuffer`] | UTF-8 aware text buffer | Text editing |
//! | [`unicode`] | Unicode display width | Emoji, CJK support |
//!
//! ## Styling & Visual
//!
//! | Module | Description | Use Case |
//!|--------|-------------|----------|
//! | [`color`] | Color manipulation | Blending, darkening |
//! | [`gradient`] | Multi-stop gradients | Linear, radial |
//! | [`border`] | Border rendering | Bordered containers |
//! | [`mod@format`] | Human formatting | Duration, file size |
//! | [`syntax`] | Syntax highlighting | Code display |
//! | [`mod@figlet`] | ASCII art text | Large text |
//! | [`mod@highlight`] | Search highlighting | Fuzzy matches |
//!
//! ## Data Structures
//!
//! | Module | Description | Use Case |
//!|--------|-------------|----------|
//! | [`table`] | Table formatting | Column alignment |
//! | [`tree`] | Tree navigation | Collapsible trees |
//! | [`selection`] | List selection | Viewport scrolling |
//! | [`layout`] | Box layout | Bordered widgets |
//!
//! ## Utilities
//!
//! | Module | Description | Use Case |
//!|--------|-------------|----------|
//! | [`fuzzy`] | Fuzzy string matching | Search/filter |
//! | [`sort`] | Natural sorting | File names (file2 < file10) |
//! | [`diff`] | Text comparison | Diffs, patches |
//! | [`path`] | Path manipulation | File display |
//! | [`ansi`] | ANSI escape parsing | Terminal output |
//! | [`easing`] | Animation easing | Smooth transitions |
//! | [`animation`] | Frame-based animation | Spring, keyframes |
//! | [`debounce`] | Event debouncing | Rate limiting |
//! | [`mod@once`] | One-shot execution | Call once pattern |
//! | [`profiler`] | Performance timing | Benchmarks |
//! | [`lock`] | Lock handling | Poison errors |
//! | [`shell`] | Shell escaping | Command safety |
//!
//! ## System Integration
//!
//! | Module | Description | Use Case |
//!|--------|-------------|----------|
//! | [`clipboard`] | Clipboard access | Copy/paste |
//! | [`i18n`] | Internationalization | Multi-language |
//! | [`accessibility`] | Screen reader support | A11y features |
//! | [`validation`] | Form validation | Input checking |
//! | [`keymap`] | Key bindings | Keyboard shortcuts |
//! | [`browser`] | System browser | Open URLs |
//!
//! # Quick Start
//!
//! ## Color Manipulation
//!
//! ```rust,ignore
//! use revue::utils::color::{darken, lighten, blend};
//! use revue::style::Color;
//!
//! let color = Color::BLUE;
//! let darker = darken(color, 0.2);
//! let lighter = lighten(color, 0.3);
//! let blended = blend(color, Color::WHITE, 0.5);
//! ```
//!
//! ## Fuzzy Search
//!
//! ```rust,ignore
//! use revue::utils::fuzzy::fuzzy_match;
//!
//! let matches = fuzzy_match("hello", "hallo"); // High score
//! let no_match = fuzzy_match("hello", "bye"); // Low score
//! ```
//!
//! ## Natural Sorting
//!
//! ```rust,ignore
//! use revue::utils::sort::natural_cmp;
//!
//! let files = vec!["file10.txt", "file2.txt"];
//! files.sort_by(|a, b| natural_cmp(a, b));
//! // Result: file2.txt, file10.txt
//! ```

pub mod accessibility;
pub mod accessibility_signal;
pub mod animation;
pub mod ansi;
pub mod border;
pub mod browser;
pub mod clipboard;
pub mod color;
pub mod debounce;
pub mod diff;
pub mod easing;
pub mod figlet;
pub mod filter;
pub mod format;
pub mod fuzzy;
pub mod gradient;
pub mod highlight;
pub mod i18n;
pub mod keymap;
pub mod layout;
pub mod lock;
pub mod once;
pub mod overlay;
pub mod path;
pub mod profiler;
pub mod selection;
pub mod shell;
pub mod sort;
pub mod syntax;
pub mod table;
pub mod terminal;
pub mod text;
pub mod text_sizing;
pub mod textbuffer;
pub mod tree;
pub mod undo;
pub mod unicode;
pub mod validation;

// Border utilities
pub use border::{
    draw_border_title, draw_border_titles, draw_title, draw_title_center, draw_title_right,
    render_border, render_rounded_border, BorderChars, BorderEdge, BorderStyle, BorderTitle,
    TitlePosition,
};

// Text utilities
pub use text::{
    byte_to_char_index,
    center,
    char_count,
    char_slice,
    // Character index utilities (UTF-8 safe)
    char_to_byte_index,
    char_to_byte_index_with_char,
    insert_at_char,
    pad_left,
    pad_right,
    remove_char_at,
    remove_char_range,
    truncate,
    truncate_start,
    wrap_text,
};

// Color utilities
pub use color::{blend, contrast_color, darken, hsl_to_rgb, lighten, rgb_to_hsl};

// Natural sorting
pub use sort::{
    natural_cmp, natural_cmp_case_sensitive, natural_sort, natural_sort_case_sensitive, NaturalKey,
};

// Fuzzy matching
pub use fuzzy::{
    fuzzy_filter, fuzzy_filter_simple, fuzzy_match, fuzzy_matches, fuzzy_score, FuzzyMatch,
    FuzzyMatcher,
};

// Unicode width
pub use unicode::{
    center_to_width, char_width, display_width, pad_to_width, right_align_to_width, split_at_width,
    truncate_to_width, truncate_with_ellipsis, truncate_with_suffix, wrap_to_width,
};

// Highlighting
pub use highlight::{
    highlight_matches, highlight_range, highlight_ranges, highlight_substring,
    highlight_substring_case, HighlightSpan, Highlighter,
};

// Formatting
pub use format::{
    // Duration
    format_duration,
    format_duration_compact,
    format_duration_short,
    // Numbers
    format_number,
    format_number_short,
    format_percent,
    format_percent_precise,
    format_rate,
    format_rate_compact,
    // Relative time
    format_relative_time,
    format_relative_time_short,
    // Size
    format_size,
    format_size_compact,
    format_size_si,
    format_std_duration,
    format_std_duration_short,
    ordinal,
    // Misc
    pluralize,
    pluralize_s,
};

// Diff
pub use diff::{
    diff_chars, diff_lines, diff_words, format_unified_diff, DiffChange, DiffOp, DiffStats,
};

// Path utilities
pub use path::{
    abbreviate_path, abbreviate_path_keep, common_prefix, expand_home, extension, filename,
    home_dir, home_relative, is_hidden, join_paths, normalize_separators, parent, relative_to,
    shorten_path, stem, validate_characters, validate_no_traversal, validate_within_base,
    PathDisplay, PathError,
};

// ANSI parsing
pub use ansi::{ansi_len, parse_ansi, strip_ansi, AnsiSpan};

// Easing functions
pub use easing::{
    ease_in_back, ease_in_bounce, ease_in_circ, ease_in_cubic, ease_in_elastic, ease_in_expo,
    ease_in_out_back, ease_in_out_bounce, ease_in_out_circ, ease_in_out_cubic, ease_in_out_elastic,
    ease_in_out_expo, ease_in_out_quad, ease_in_out_quart, ease_in_out_quint, ease_in_out_sine,
    ease_in_quad, ease_in_quart, ease_in_quint, ease_in_sine, ease_out_back, ease_out_bounce,
    ease_out_circ, ease_out_cubic, ease_out_elastic, ease_out_expo, ease_out_quad, ease_out_quart,
    ease_out_quint, ease_out_sine, lerp, lerp_fn, linear, Easing, EasingFn, Interpolator,
};

// Figlet ASCII art
pub use figlet::{figlet, figlet_lines, figlet_with_font, font_height, FigletFont};

// Syntax highlighting
pub use syntax::{
    highlight, highlight_line, Language, SyntaxHighlighter, SyntaxTheme, Token, TokenType,
};

// Clipboard
pub use clipboard::{
    clear as clear_clipboard, copy, has_text as clipboard_has_text, paste, Clipboard,
    ClipboardBackend, ClipboardError, ClipboardHistory, ClipboardResult, MemoryClipboard,
    SystemClipboard,
};

// Validation
pub use validation::{
    all_of, alphabetic, alphanumeric, any_of, custom, email, length_range, lowercase, matches,
    max_length, max_value, min_length, min_value, not_one_of, numeric, one_of, pattern, required,
    uppercase, url, value_range, FormValidator, ValidationError, ValidationResult, Validator,
};

// i18n
pub use i18n::{Direction, I18n, Locale, LocaleId, Translation};

// Keymap utilities
pub use keymap::{
    emacs_preset, format_key_binding, parse_key_binding, vim_preset, KeyChord, KeymapConfig,
    LookupResult, Mode,
};

// Accessibility
pub use accessibility::{
    accessibility_manager, shared_accessibility, AccessibilityManager, AccessibleNode,
    AccessibleState, Announcement, Priority, Role, SharedAccessibility,
};

// Accessibility signal-based API
pub use accessibility_signal::{
    // Core announcement functions
    announce,
    // Widget-specific helpers
    announce_button_clicked,
    announce_checkbox_changed,
    announce_dialog_closed,
    announce_dialog_opened,
    announce_error,
    announce_focus_region,
    announce_list_selection,
    announce_loaded,
    announce_loading,
    announce_now,
    announce_progress,
    announce_progress_complete,
    announce_success,
    announce_tab_changed,
    announce_validation_error,
    has_announcements,
    is_accessibility_enabled,
    is_high_contrast,
    prefers_reduced_motion,
    set_accessibility_enabled,
    set_high_contrast,
    // Preference getters/setters
    set_reduced_motion,
    take_announcements,
};

// Text Buffer
pub use textbuffer::TextBuffer;

// Undo/Redo
pub use undo::{GroupedUndoHistory, Mergeable, UndoGroup, UndoHistory, DEFAULT_MAX_HISTORY};

// Gradient
pub use gradient::{
    presets as gradient_presets, ColorStop, Gradient, GradientDirection, InterpolationMode,
    LinearGradient, RadialGradient, SpreadMode,
};

// Animation
pub use animation::{
    presets as animation_presets, AnimatedValue, Interpolatable, Keyframe, Keyframes, Sequence,
    SequenceStep, Spring, Ticker, Timer,
};

// Table formatting
pub use table::{align_center, align_left, align_right, align_text, Align, Column, Table};

// Tree navigation
pub use tree::{Indent, TreeIcons, TreeItem, TreeNav};

// Selection with viewport
pub use selection::{wrap_next, wrap_prev, SectionedSelection, Selection};

// Box layout
pub use layout::BoxLayout;

// Browser utilities
pub use browser::{open_browser, open_file, open_folder, open_url, reveal_in_finder};

// Profiler
pub use profiler::{
    profile, profiler_report, start_profile, thread_profiler, FlameNode, ProfileGuard, Profiler,
    Stats, Timing,
};

// Text Sizing (Kitty OSC 66 protocol)
pub use text_sizing::{is_supported as text_sizing_supported, TextSizing};

// Lock utilities
pub use lock::{lock_or_recover, read_or_recover, write_or_recover};

// Shell escaping
pub use shell::{escape_applescript, escape_powershell, sanitize_string};

// Debounce and Throttle
pub use debounce::{debounce_ms, debouncer, throttle, throttle_ms, Debouncer, Edge, Throttle};

// Once (one-shot execution)
pub use once::{once, Once};

// Filter mode
pub use filter::FilterMode;

// Overlay rendering
pub use overlay::{draw_separator_overlay, draw_text_overlay};

// Terminal detection
pub use terminal::{is_sixel_capable, terminal_type, TerminalType};

#[cfg(test)]
mod tests {
    use super::*;

    // =========================================================================
    // Module Export Tests
    // =========================================================================
    //
    // This test module verifies that all publicly exported types and functions
    // from the utils module are accessible and compile correctly.
    //
    // These tests use compile-time type checking to verify the API surface
    // without executing functionality, which is tested in individual modules.

    #[test]
    fn test_all_modules_compile() {
        // This test ensures that importing and using the utility API compiles correctly.
        // The actual functionality is tested in each module's own test suite.

        // Filter modes
        let mode = FilterMode::default();
        assert_eq!(mode, FilterMode::Fuzzy);

        // Terminal type
        let term = terminal_type();
        match term {
            TerminalType::Kitty | TerminalType::Iterm2 | TerminalType::Unknown => {}
        }

        // Once utility
        let mut once = Once::new();
        assert!(once.call());
        assert!(!once.call());

        // Text sizing
        let _ = text_sizing_supported();

        // Shell escaping
        let escaped = escape_applescript("test");
        assert_eq!(escaped, "test");
        let escaped = escape_powershell("test");
        assert_eq!(escaped, "test");
        let sanitized = sanitize_string("test");
        assert_eq!(sanitized, "test");

        // Format utilities
        let size = format_size(1024);
        assert!(!size.is_empty());
        let duration = format_duration(60); // Takes u64 seconds
        assert!(!duration.is_empty());

        // Sort utilities
        let order = natural_cmp("file1", "file2");
        let _ = order; // Verify it compiles
        let _ = NaturalKey::new("file1");

        // Unicode utilities
        let width = display_width("hello");
        assert_eq!(width, 5);

        // Highlight utilities
        let spans = highlight_substring("hello world", "hello");
        assert!(!spans.is_empty());

        // ANSI utilities
        let stripped = strip_ansi("test");
        assert_eq!(stripped, "test");

        // Easing functions
        let eased = ease_in_out_quad(0.5);
        assert!((0.0..=1.0).contains(&eased));

        // Color utilities
        let c = crate::style::Color::rgb(100, 100, 100);
        let _darker = darken(c, 0.2);
        let _lighter = lighten(c, 0.2);

        // Border chars
        let border = BorderChars::ROUNDED;
        let _ = border.top_left;
        let _ = border.top_right;
        let _ = border.bottom_left;
        let _ = border.bottom_right;

        // Figlet
        let art = figlet("Hi");
        assert!(!art.is_empty());

        // I18n
        let mut i18n = I18n::new();
        i18n.add_translation("en", "test", "Test");
        assert_eq!(i18n.t("test"), "Test");

        // Validation
        let validator = required();
        let result = validator("value");
        assert!(result.is_ok());

        // Path utilities
        let name = filename("/path/to/file.txt");
        assert_eq!(name, Some("file.txt".to_string()));

        // Diff utilities
        let diffs = diff_lines("line1\nline2", "line1\nline3");
        assert!(!diffs.is_empty());

        // Fuzzy matching - use pattern that matches in order
        let score = fuzzy_score("hl", "hello");
        assert!(score > 0);

        // Filter mode
        assert!(FilterMode::Fuzzy.matches("hello", "hl"));
        assert!(FilterMode::Prefix.matches("hello", "he"));
        assert!(FilterMode::Contains.matches("hello", "el"));
        assert!(FilterMode::Exact.matches("hello", "hello"));
        assert!(FilterMode::None.matches("hello", "xyz"));

        // Debounce/throttle - just verify types compile
        let _ = debouncer(std::time::Duration::from_millis(100));
        let _ = debounce_ms(100);
        let _ = throttle(std::time::Duration::from_millis(100));
        let _ = throttle_ms(100);

        // Verify lock utilities compile
        let mutex = std::sync::Mutex::new(42);
        let guard = lock_or_recover(&mutex);
        assert_eq!(*guard, 42);

        let rwlock = std::sync::RwLock::new(42);
        let read_guard = read_or_recover(&rwlock);
        assert_eq!(*read_guard, 42);

        // Browser utilities - these return bool but we can't test actual execution
        // without a real environment
        let result = open_browser("https://example.com");
        let _ = result; // Just verify it compiles

        // Profiler
        let _ = profiler_report();

        // Text buffer
        let buffer = TextBuffer::new();
        assert!(buffer.is_empty());

        // Undo history
        let history: UndoHistory<String> = UndoHistory::new();
        assert!(!history.can_undo());
        assert!(!history.can_redo());

        // Selection
        let selection = Selection::new(10);
        assert_eq!(selection.index, 0);

        // Table
        let table = Table::new();
        assert_eq!(table.total_width(), 0);

        // Tree navigation
        let tree = TreeNav::new();
        assert_eq!(tree.selected(), 0);

        // Gradient - verify compilation only
        use crate::utils::gradient::Gradient;
        let _ = LinearGradient::new(
            Gradient::linear(crate::style::Color::RED, crate::style::Color::BLUE),
            GradientDirection::ToRight,
        );

        // Animation - verify compilation only (call one of the preset functions)
        let _ = animation_presets::fade_in(300);

        // Syntax highlighting - verify compilation only
        let _ = Language::from_fence("rust");
        let _ = SyntaxTheme::monokai();

        // Accessibility - verify compilation only
        let _ = shared_accessibility();
        let _ = accessibility_manager();
        announce("Test announcement");
        let _ = take_announcements();
        let _ = has_announcements();
        set_reduced_motion(false);
        let _ = prefers_reduced_motion();
        set_high_contrast(false);
        let _ = is_high_contrast();
        set_accessibility_enabled(true);
        let _ = is_accessibility_enabled();

        // Keymap - verify compilation only
        let _ = emacs_preset();
        let _ = vim_preset();
        let _ = KeymapConfig::default();

        // Box layout
        let layout = BoxLayout::new(0, 0, 20, 10);
        let _ = layout;

        // Check types are Copy/Clone where expected
        let mode1 = FilterMode::Fuzzy;
        let mode2 = mode1;
        assert_eq!(mode1, mode2);

        let term1 = TerminalType::Kitty;
        let term2 = term1;
        assert_eq!(term1, term2);

        // Verify Direction is Copy/Clone
        let dir1 = Direction::Ltr;
        let dir2 = dir1;
        assert_eq!(dir1, dir2);

        // Verify LocaleId is just String
        let id: LocaleId = "en".to_string();
        assert_eq!(id, "en");
    }
}