radicle_term/
lib.rs

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