rich_rust 0.2.1

A Rust port of Python's Rich library for beautiful terminal output
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
//! End-to-end tests for interactive prompts, select, confirm, pager, and status.
//!
//! Tests use simulated input via `BufRead` readers and non-terminal consoles
//! to verify prompt logic, validation, defaults, and error handling.

mod common;

use common::init_test_logging;
use rich_rust::interactive::{Confirm, Select};
use rich_rust::prelude::*;
use std::io::{self, Cursor};
use std::sync::Arc;

/// Helper: create a console configured as interactive (terminal).
fn interactive_console() -> Console {
    Console::builder()
        .width(80)
        .force_terminal(true)
        .markup(true)
        .build()
}

/// Helper: create a console configured as non-interactive (pipe/redirect).
fn non_interactive_console() -> Console {
    Console::builder()
        .width(80)
        .force_terminal(false)
        .markup(true)
        .build()
}

/// Helper: create a BufRead reader from a string.
fn input(s: &str) -> Cursor<Vec<u8>> {
    Cursor::new(s.as_bytes().to_vec())
}

// =============================================================================
// Text Prompt: Basic Input
// =============================================================================

/// Test: Prompt accepts simple text input.
#[test]
fn test_prompt_basic_text_input() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Name");
    let mut reader = input("Alice\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "Alice");
}

/// Test: Prompt with default returns default on empty input.
#[test]
fn test_prompt_default_on_empty_input() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Name").default("Bob");
    let mut reader = input("\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "Bob");
}

/// Test: Prompt returns user input even when default is set.
#[test]
fn test_prompt_user_input_overrides_default() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Name").default("Bob");
    let mut reader = input("Charlie\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "Charlie");
}

/// Test: Prompt with allow_empty accepts empty input.
#[test]
fn test_prompt_allow_empty() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Optional").allow_empty(true);
    let mut reader = input("\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "");
}

/// Test: Prompt strips trailing whitespace from input.
#[test]
fn test_prompt_trims_trailing_whitespace() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Input");
    let mut reader = input("hello   \n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "hello");
}

// =============================================================================
// Text Prompt: Validation
// =============================================================================

/// Test: Prompt with validator retries on invalid input.
#[test]
fn test_prompt_validation_retry() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Age").validate(|s: &str| {
        s.parse::<u32>()
            .map(|_| ())
            .map_err(|_| "Enter a number".to_string())
    });

    // First input is invalid "abc", second is valid "25"
    let mut reader = input("abc\n25\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "25");
}

/// Test: Prompt validator accepts valid input on first try.
#[test]
fn test_prompt_validation_passes() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Email").validate(|s: &str| {
        if s.contains('@') {
            Ok(())
        } else {
            Err("Must contain @".to_string())
        }
    });
    let mut reader = input("user@example.com\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "user@example.com");
}

// =============================================================================
// Text Prompt: Non-Interactive Mode
// =============================================================================

/// Test: Non-interactive console returns default without reading input.
#[test]
fn test_prompt_non_interactive_returns_default() {
    init_test_logging();

    let console = non_interactive_console();
    let prompt = Prompt::new("Name").default("DefaultUser");

    let result = prompt.ask(&console).unwrap();
    assert_eq!(result, "DefaultUser");
}

/// Test: Non-interactive console without default returns NotInteractive error.
#[test]
fn test_prompt_non_interactive_no_default_errors() {
    init_test_logging();

    let console = non_interactive_console();
    let prompt = Prompt::new("Name");

    let result = prompt.ask(&console);
    assert!(result.is_err());
    assert_eq!(
        result.unwrap_err().to_string(),
        "prompt requires an interactive console"
    );
}

// =============================================================================
// Text Prompt: EOF Handling
// =============================================================================

/// Test: Prompt returns Eof error when input stream is empty.
#[test]
fn test_prompt_eof_on_empty_stream() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Input");
    let mut reader = input(""); // empty = EOF

    let result = prompt.ask_from(&console, &mut reader);
    assert!(result.is_err());
    assert_eq!(result.unwrap_err().to_string(), "prompt input reached EOF");
}

// =============================================================================
// Text Prompt: Max Length
// =============================================================================

/// Test: Prompt with max_length rejects oversized input.
#[test]
fn test_prompt_max_length_exceeded() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Input").max_length(10);
    // Input exceeds 10 bytes
    let mut reader = input("This is way too long\n");

    let result = prompt.ask_from(&console, &mut reader);
    assert!(result.is_err());
    let err = result.unwrap_err();
    assert!(err.is_input_too_long());
    assert_eq!(err.input_limit(), Some(10));
}

/// Test: Prompt with max_length accepts input within limit.
#[test]
fn test_prompt_max_length_within_limit() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Input").max_length(100);
    let mut reader = input("Short\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "Short");
}

// =============================================================================
// Integer Prompt (via Validation)
// =============================================================================

/// Test: Integer validation accepts valid integer input.
#[test]
fn test_integer_prompt_valid() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Count").validate(|s: &str| {
        s.parse::<i64>()
            .map(|_| ())
            .map_err(|_| "Enter a valid integer".to_string())
    });
    let mut reader = input("42\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "42");
}

/// Test: Integer validation rejects non-numeric input, then accepts.
#[test]
fn test_integer_prompt_retry_then_valid() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Count").validate(|s: &str| {
        s.parse::<i64>()
            .map(|_| ())
            .map_err(|_| "Enter a valid integer".to_string())
    });
    let mut reader = input("abc\n3.14\n99\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "99");
}

/// Test: Negative integer accepted by integer validator.
#[test]
fn test_integer_prompt_negative() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Temperature").validate(|s: &str| {
        s.parse::<i64>()
            .map(|_| ())
            .map_err(|_| "Enter a valid integer".to_string())
    });
    let mut reader = input("-10\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "-10");
}

// =============================================================================
// Float Prompt (via Validation)
// =============================================================================

/// Test: Float validation accepts valid float input.
#[test]
fn test_float_prompt_valid() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Price").validate(|s: &str| {
        s.parse::<f64>()
            .map(|_| ())
            .map_err(|_| "Enter a valid number".to_string())
    });
    let mut reader = input("3.14\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "3.14");
}

/// Test: Float validation rejects text, then accepts.
#[test]
fn test_float_prompt_retry() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Weight").validate(|s: &str| {
        s.parse::<f64>()
            .map(|_| ())
            .map_err(|_| "Enter a valid number".to_string())
    });
    let mut reader = input("heavy\n72.5\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "72.5");
}

// =============================================================================
// Confirm Prompt
// =============================================================================

/// Test: Confirm accepts "y" as true.
#[test]
fn test_confirm_yes() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Proceed?");
    let mut reader = input("y\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(result);
}

/// Test: Confirm accepts "n" as false.
#[test]
fn test_confirm_no() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Proceed?");
    let mut reader = input("n\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(!result);
}

/// Test: Confirm accepts "yes" (full word) as true.
#[test]
fn test_confirm_yes_full() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Continue?");
    let mut reader = input("yes\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(result);
}

/// Test: Confirm accepts "no" (full word) as false.
#[test]
fn test_confirm_no_full() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Continue?");
    let mut reader = input("no\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(!result);
}

/// Test: Confirm accepts "true" and "1" as true.
#[test]
fn test_confirm_true_and_one() {
    init_test_logging();

    let console = interactive_console();

    let confirm = Confirm::new("Q?");
    let mut reader = input("true\n");
    assert!(confirm.ask_from(&console, &mut reader).unwrap());

    let confirm = Confirm::new("Q?");
    let mut reader = input("1\n");
    assert!(confirm.ask_from(&console, &mut reader).unwrap());
}

/// Test: Confirm accepts "false" and "0" as false.
#[test]
fn test_confirm_false_and_zero() {
    init_test_logging();

    let console = interactive_console();

    let confirm = Confirm::new("Q?");
    let mut reader = input("false\n");
    assert!(!confirm.ask_from(&console, &mut reader).unwrap());

    let confirm = Confirm::new("Q?");
    let mut reader = input("0\n");
    assert!(!confirm.ask_from(&console, &mut reader).unwrap());
}

/// Test: Confirm with default returns default on empty input.
#[test]
fn test_confirm_default_on_empty() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Proceed?").default(true);
    let mut reader = input("\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(result);
}

/// Test: Confirm with default(false) returns false on empty input.
#[test]
fn test_confirm_default_false_on_empty() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Delete?").default(false);
    let mut reader = input("\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(!result);
}

/// Test: Confirm retries on invalid input, then accepts valid.
#[test]
fn test_confirm_invalid_then_valid() {
    init_test_logging();

    let console = interactive_console();
    let confirm = Confirm::new("Proceed?");
    let mut reader = input("maybe\ny\n");

    let result = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(result);
}

/// Test: Confirm case-insensitive ("Y", "N").
#[test]
fn test_confirm_case_insensitive() {
    init_test_logging();

    let console = interactive_console();

    let confirm = Confirm::new("Q?");
    let mut reader = input("Y\n");
    assert!(confirm.ask_from(&console, &mut reader).unwrap());

    let confirm = Confirm::new("Q?");
    let mut reader = input("N\n");
    assert!(!confirm.ask_from(&console, &mut reader).unwrap());

    let confirm = Confirm::new("Q?");
    let mut reader = input("YES\n");
    assert!(confirm.ask_from(&console, &mut reader).unwrap());
}

/// Test: Confirm non-interactive returns default.
#[test]
fn test_confirm_non_interactive_returns_default() {
    init_test_logging();

    let console = non_interactive_console();
    let confirm = Confirm::new("Q?").default(true);

    let result = confirm.ask(&console).unwrap();
    assert!(result);
}

/// Test: Confirm non-interactive without default returns NotInteractive.
#[test]
fn test_confirm_non_interactive_no_default_errors() {
    init_test_logging();

    let console = non_interactive_console();
    let confirm = Confirm::new("Q?");

    let result = confirm.ask(&console);
    assert!(result.is_err());
}

// =============================================================================
// Select Prompt
// =============================================================================

/// Test: Select by exact text match.
#[test]
fn test_select_by_text() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Color").choices(["red", "green", "blue"]);
    let mut reader = input("green\n");

    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "green");
}

/// Test: Select by number.
#[test]
fn test_select_by_number() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Fruit").choices(["apple", "banana", "cherry"]);
    let mut reader = input("2\n");

    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "banana");
}

/// Test: Select uses default on empty input.
#[test]
fn test_select_default_on_empty() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Size")
        .choices(["small", "medium", "large"])
        .default("medium");
    let mut reader = input("\n");

    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "medium");
}

/// Test: Select retries on invalid input.
#[test]
fn test_select_invalid_then_valid() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Color").choices(["red", "green", "blue"]);
    // "purple" is not a valid choice, "1" selects "red"
    let mut reader = input("purple\n1\n");

    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "red");
}

/// Test: Select case-insensitive match.
#[test]
fn test_select_case_insensitive() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Pick").choices(["Red", "Green", "Blue"]);
    let mut reader = input("red\n");

    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "Red");
}

/// Test: Select with no choices returns validation error.
#[test]
fn test_select_no_choices_error() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Pick");
    let mut reader = input("anything\n");

    let result = select.ask_from(&console, &mut reader);
    assert!(result.is_err());
    assert!(result.unwrap_err().to_string().contains("No choices"));
}

/// Test: Select non-interactive returns default.
#[test]
fn test_select_non_interactive_returns_default() {
    init_test_logging();

    let console = non_interactive_console();
    let select = Select::new("Pick").choices(["a", "b", "c"]).default("b");

    let result = select.ask(&console).unwrap();
    assert_eq!(result, "b");
}

/// Test: Select non-interactive without default returns NotInteractive.
#[test]
fn test_select_non_interactive_no_default_errors() {
    init_test_logging();

    let console = non_interactive_console();
    let select = Select::new("Pick").choices(["a", "b", "c"]);

    let result = select.ask(&console);
    assert!(result.is_err());
}

/// Test: Select by boundary numbers (first and last).
#[test]
fn test_select_boundary_numbers() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Pick").choices(["first", "middle", "last"]);

    let mut reader = input("1\n");
    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "first");

    let select = Select::new("Pick").choices(["first", "middle", "last"]);
    let mut reader = input("3\n");
    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "last");
}

/// Test: Select with out-of-range number retries.
#[test]
fn test_select_out_of_range_number() {
    init_test_logging();

    let console = interactive_console();
    let select = Select::new("Pick").choices(["a", "b"]);
    // 5 is out of range, then "a" is valid
    let mut reader = input("5\na\n");

    let result = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "a");
}

// =============================================================================
// Pager
// =============================================================================

/// Test: Pager can be constructed with defaults.
#[test]
fn test_pager_default_construction() {
    init_test_logging();

    let pager = Pager::default();
    // Pager should exist; further behavior depends on terminal
    let _ = pager;
}

/// Test: Pager with custom command.
#[test]
fn test_pager_custom_command() {
    init_test_logging();

    let pager = Pager::default().command("less");
    let _ = pager;
}

/// Test: Pager with color toggle.
#[test]
fn test_pager_allow_color() {
    init_test_logging();

    let pager = Pager::default().allow_color(true);
    let _ = pager;

    let pager2 = Pager::default().allow_color(false);
    let _ = pager2;
}

// =============================================================================
// Status Display
// =============================================================================

/// Test: Status can be created in non-interactive mode.
#[test]
fn test_status_non_interactive() {
    init_test_logging();

    let console = Arc::new(non_interactive_console());
    let status = Status::new(&console, "Loading...").unwrap();

    // Status should be created successfully
    status.update("Still loading...");
    drop(status);
}

/// Test: Status update changes message.
#[test]
fn test_status_update_message() {
    init_test_logging();

    let console = Arc::new(non_interactive_console());
    let status = Status::new(&console, "First message").unwrap();

    status.update("Second message");
    status.update("Third message");
    // No crash; update succeeds silently in non-interactive mode
    drop(status);
}

/// Test: Status can be dropped safely.
#[test]
fn test_status_drop_safety() {
    init_test_logging();

    let console = Arc::new(non_interactive_console());

    // Create and immediately drop
    {
        let status = Status::new(&console, "Temporary").unwrap();
        let _ = status;
    }
    // No panic or resource leak
}

// =============================================================================
// PromptError
// =============================================================================

/// Test: PromptError display messages.
#[test]
fn test_prompt_error_display() {
    init_test_logging();

    assert_eq!(
        PromptError::NotInteractive.to_string(),
        "prompt requires an interactive console"
    );
    assert_eq!(PromptError::Eof.to_string(), "prompt input reached EOF");
    assert_eq!(
        PromptError::Validation("bad input".into()).to_string(),
        "bad input"
    );

    let io_err = PromptError::Io(io::Error::new(io::ErrorKind::BrokenPipe, "pipe broke"));
    assert!(io_err.to_string().contains("pipe broke"));
}

/// Test: PromptError::InputTooLong display and helpers.
#[test]
fn test_prompt_error_input_too_long() {
    init_test_logging();

    let err = PromptError::InputTooLong {
        limit: 100,
        received: 200,
    };
    assert!(err.is_input_too_long());
    assert_eq!(err.input_limit(), Some(100));
    assert!(err.to_string().contains("200"));
    assert!(err.to_string().contains("100"));
}

/// Test: PromptError implements std::error::Error.
#[test]
fn test_prompt_error_std_error_trait() {
    init_test_logging();

    use std::error::Error;

    let err = PromptError::NotInteractive;
    assert!(err.source().is_none());

    let io_err = PromptError::Io(io::Error::other("test"));
    assert!(io_err.source().is_some());
}

/// Test: PromptError From<io::Error>.
#[test]
fn test_prompt_error_from_io() {
    init_test_logging();

    let io_err = io::Error::new(io::ErrorKind::UnexpectedEof, "eof");
    let prompt_err: PromptError = io_err.into();
    assert!(prompt_err.to_string().contains("eof"));
}

// =============================================================================
// Prompt with Markup
// =============================================================================

/// Test: Prompt with markup disabled.
#[test]
fn test_prompt_no_markup() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Input").markup(false);
    let mut reader = input("test\n");

    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "test");
}

/// Test: Prompt with show_default disabled.
#[test]
fn test_prompt_hide_default() {
    init_test_logging();

    let console = interactive_console();
    let prompt = Prompt::new("Name").default("Bob").show_default(false);
    let mut reader = input("\n");

    // Still uses default, just doesn't show it
    let result = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(result, "Bob");
}

// =============================================================================
// Combined Workflows
// =============================================================================

/// Test: Full interactive workflow: prompt → validate → select → confirm.
#[test]
fn test_full_interactive_workflow() {
    init_test_logging();

    let console = interactive_console();

    // Step 1: Get a name
    let prompt = Prompt::new("Name");
    let mut reader = input("Alice\n");
    let name = prompt.ask_from(&console, &mut reader).unwrap();
    assert_eq!(name, "Alice");

    // Step 2: Select a role
    let select = Select::new("Role").choices(["admin", "user", "guest"]);
    let mut reader = input("2\n");
    let role = select.ask_from(&console, &mut reader).unwrap();
    assert_eq!(role, "user");

    // Step 3: Confirm
    let confirm = Confirm::new("Create account?").default(true);
    let mut reader = input("y\n");
    let confirmed = confirm.ask_from(&console, &mut reader).unwrap();
    assert!(confirmed);
}

/// Test: Non-interactive workflow uses all defaults.
#[test]
fn test_non_interactive_all_defaults() {
    init_test_logging();

    let console = non_interactive_console();

    let name = Prompt::new("Name").default("System").ask(&console).unwrap();
    assert_eq!(name, "System");

    let role = Select::new("Role")
        .choices(["admin", "user"])
        .default("user")
        .ask(&console)
        .unwrap();
    assert_eq!(role, "user");

    let confirmed = Confirm::new("Proceed?")
        .default(true)
        .ask(&console)
        .unwrap();
    assert!(confirmed);
}