Skip to main content

radicle_term/
lib.rs

1// Prevent use of `println!` and `print!` which panic on broken pipes.
2// Use `crate::io::println` or `term::io::print` instead.
3// See: https://github.com/rust-lang/rust/issues/62569
4#![deny(clippy::print_stdout)]
5
6pub mod ansi;
7pub mod cell;
8pub mod colors;
9pub mod editor;
10pub mod element;
11pub mod format;
12pub mod hstack;
13pub mod io;
14pub mod label;
15pub mod spinner;
16pub mod table;
17pub mod textarea;
18pub mod vstack;
19
20use std::fmt;
21use std::io::IsTerminal;
22
23pub use ansi::Color;
24pub use ansi::{Filled, Paint, Style, TerminalFile, paint};
25pub use editor::Editor;
26pub use element::{Constraint, Element, Line, Size};
27pub use hstack::HStack;
28pub use inquire::ui::Styled;
29pub use io::*;
30pub use label::{Label, label};
31pub use spinner::{Spinner, spinner, spinner_to};
32pub use table::{Table, TableOptions};
33pub use textarea::{TextArea, textarea};
34pub use vstack::{VStack, VStackOptions};
35
36#[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
37pub enum Interactive {
38    Yes,
39    #[default]
40    No,
41}
42
43impl Interactive {
44    pub fn new(term: impl IsTerminal) -> Self {
45        Self::from(term.is_terminal())
46    }
47
48    pub fn yes(&self) -> bool {
49        (*self).into()
50    }
51
52    pub fn no(&self) -> bool {
53        !self.yes()
54    }
55
56    pub fn confirm(&self, prompt: impl fmt::Display) -> bool {
57        if self.yes() { confirm(prompt) } else { true }
58    }
59}
60
61impl From<Interactive> for bool {
62    fn from(c: Interactive) -> Self {
63        match c {
64            Interactive::Yes => true,
65            Interactive::No => false,
66        }
67    }
68}
69
70impl From<bool> for Interactive {
71    fn from(b: bool) -> Self {
72        if b { Interactive::Yes } else { Interactive::No }
73    }
74}
75
76pub fn style<T>(item: T) -> Paint<T> {
77    paint(item)
78}