blockprint

Function blockprint 

Source
pub fn blockprint(content: impl ToString, color: Color)
Expand description

Prints content with a simple border around it

This function is a convenience wrapper around blockfmt and println. It automatically formats the content with a border using the specified color and then prints it to the console.

ยงExample

use console::Color;
use libpt_cli::printing::blockprint;
blockprint("Hello world!", Color::Blue);
Examples found in repository?
examples/cli.rs (line 32)
24fn main() {
25    let cli = Cli::parse();
26    let _logger = Logger::builder().set_level(cli.verbosity.level()).build();
27
28    debug!("logger initialized with level: {}", cli.verbosity.level());
29
30    if !cli.machine {
31        let text = cli.text.join(" ");
32        printing::blockprint(text, console::Color::Green);
33    } else {
34        for text in cli.text {
35            println!("{text}")
36        }
37    }
38}
More examples
Hide additional examples
examples/repl.rs (line 76)
31fn main() -> anyhow::Result<()> {
32    // You would normally make a proper cli interface with clap before entering the repl. This is
33    // omitted here for brevity
34    let _logger = Logger::builder().display_time(false).build();
35
36    // the compiler can infer that we want to use the ReplCommand enum.
37    let mut repl = DefaultRepl::<ReplCommand>::default();
38
39    debug!("entering the repl");
40    loop {
41        // repl.step() should be at the start of your loop
42        // It is here that the repl will get the user input, validate it, and so on
43        match repl.step() {
44            Ok(c) => c,
45            Err(e) => {
46                // if the user requested the help, print in blue, otherwise in red as it's just an
47                // error
48                if let libpt_cli::repl::error::Error::Parsing(e) = &e {
49                    if e.kind() == clap::error::ErrorKind::DisplayHelp {
50                        println!("{}", style(e).cyan());
51                        continue;
52                    }
53                }
54                println!("{}", style(e).red().bold());
55                continue;
56            }
57        };
58
59        // now we can match our defined commands
60        //
61        // only None if the repl has not stepped yet
62        match repl.command().to_owned().unwrap() {
63            ReplCommand::Exit => break,
64            ReplCommand::Wait { len } => {
65                debug!("len: {len}");
66                let spinner = indicatif::ProgressBar::new_spinner();
67                spinner.enable_steady_tick(std::time::Duration::from_millis(100));
68                std::thread::sleep(std::time::Duration::from_secs(len));
69                spinner.finish();
70            }
71            ReplCommand::Hello => println!("Hello!"),
72            ReplCommand::Echo { text, fancy } => {
73                if !fancy {
74                    println!("{}", text.join(" "))
75                } else {
76                    printing::blockprint(text.join(" "), console::Color::Cyan)
77                }
78            }
79        }
80    }
81    Ok(())
82}