lib.rs 1.8 KB
Newer Older
Moritz Sokoll's avatar
Moritz Sokoll committed
1
//! # btui
Moritz Sokoll's avatar
Moritz Sokoll committed
2
//! ## beautiful text user interfaces
Moritz Sokoll's avatar
Moritz Sokoll committed
3
4
5
6
//!
//! with btui you can create beautiful text user interfaces for the terminal.
//! To get started add `btui` as a dependency to your project:
//! ```toml
7
//! btui = "0.6.10"
Moritz Sokoll's avatar
Moritz Sokoll committed
8
9
10
11
//! ```
//!
//! # Examples
//! This is a basic coloring example which will output hello world in red:
12
//! ```
Moritz Sokoll's avatar
Moritz Sokoll committed
13
14
15
16
//! use btui::effects::{Color, Special};
//! use btui::print::{fg, sp};
//!
//! println!("{}Hello World!{}", fg(Color::Red), sp(Special::Reset));
Moritz Sokoll's avatar
Moritz Sokoll committed
17
18
//! ```

Moritz Sokoll's avatar
Moritz Sokoll committed
19
#[cfg(feature = "core")]
20
mod ft;
Moritz Sokoll's avatar
Moritz Sokoll committed
21

Moritz Sokoll's avatar
Moritz Sokoll committed
22
#[cfg(feature = "linux")]
Moritz Sokoll's avatar
Moritz Sokoll committed
23
/// module containing stuff for basic linux based print operations
Moritz Sokoll's avatar
Moritz Sokoll committed
24
pub mod linux;
Moritz Sokoll's avatar
Moritz Sokoll committed
25
26
27
28
29

#[cfg(feature = "pbar")]
/// module containing a progressbar
pub mod pbar;

30
31
pub use linux::Terminal;

32
pub use ft::{effects, print};
Moritz Sokoll's avatar
Moritz Sokoll committed
33
34
35

#[cfg(test)]
mod tests {
36
    use crate::effects::Color::Black;
37
    use crate::pbar::*;
38
    use crate::print::fg;
39
    use crate::Terminal;
Moritz Sokoll's avatar
Moritz Sokoll committed
40
    #[test]
41
42
    fn correct_color() {
        assert_eq!(String::from("\x1b[30m"), fg(Black));
Moritz Sokoll's avatar
Moritz Sokoll committed
43
    }
44
45
46
47
48
49
    #[test]
    fn printing_with_terminal() {
        let t: Terminal = Terminal::default();
        match t.println("Hello World!") {
            Ok(_) => (),
            Err(e) => panic!("{}", e),
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
        }
    }
    #[test]
    fn progressbar() {
        let t: Terminal = Terminal::default();
        let mut pbar = ProgressBar::new("test", '-', '#');
        pbar.set_progress(75.6);
        match t.println(format!("{}", pbar.render())) {
            Ok(_) => (),
            Err(e) => panic!("{}", e),
        }
    }
    #[test]
    fn extprogressbar() {
        let t: Terminal = Terminal::default();
        let mut pbar = ExtProgressBar::new("[=> ]", "test");
        pbar.set_progress(75.6);
        match t.println(format!("{}", pbar.render())) {
            Ok(_) => (),
            Err(e) => panic!("{}", e),
70
71
        }
    }
Moritz Sokoll's avatar
Moritz Sokoll committed
72
}