#text #box #message #tty

text_box

Create useful messages in console with text boxes using 'termion'

12 releases

0.2.4 Jan 18, 2020
0.2.3 Jan 18, 2020
0.1.11 Jan 18, 2020

#33 in #tty

MIT/Apache

11KB
115 lines

Cargo.toml

In order to use this crate you have to add to deps list in Cargo.toml.

...

[dependencies]
text_box = "*"

...

Imports

Now you can import crate and features with:

extern crate text_box;

use text_box::TextBox;
use text_box::utils::{clear_screen, goto};

Full example

A complete usage example.

extern crate text_box;

use text_box::TextBox;
use text_box::utils::{clear_screen, goto};

fn main() {
	clear_screen();

	let box1 = TextBox::new(
		30, 10,
		15, 6,
		2,
		"Box 1",
		"This box have a border type 2. A first level message, must be checked quickly."
	).unwrap();
	let box2 = TextBox::new(
		10, 10,
		15, 6,
		0,
		"Box 2",
		"This box have a border type 0. Normal boxed text for alingment."
	).unwrap();
	let box3 = TextBox::new(
		10, 2,
		35, 6,
		1,
		"Box 3",
		"This box have a border type 1. A second level message. \n You can create multiple boxes, just be careful with console window size."
	).unwrap();
	let box4 = TextBox::new(
		47, 2,
		15, 14,
		2,
		"Box 4",
		"If you want a new line inside a box you need to put it between spaces like \n this: ' \\n '. Formatter identifies this as a new line word, so it can be printed. \n \n Right?"
	).unwrap();

	println!("{}{}{}{}", box1, box2, box3, box4);
	
	goto(1, 40);
}

This example should print out:

Box 3──────────────────────────────┐╔Box 4══════════╗
 │This box have a border type 1. A   │║If you want a  ║
 │second level message.              │║new line inside║
 │You can create multiple boxes, just│║a box you need ║
 │be careful with console window     │║to put it      ║
 │size.                              │║between spaces ║
 │                                   │║like           ║
 └───────────────────────────────────┘║this: ' \n '.Box 2Box 1══════════╗║Formatter      ║
  This box have a    ║This box have a║║identifies this║
  border type 0.     ║border type 2. ║║as a new line  ║
  Normal boxed       ║A first level  ║║word, so it can║
  text for           ║message, must  ║║be printed.    ║
  alingment.         ║be checked     ║║               ║
                     ║quickly.       ║║Right?         ║
                     ╚═══════════════╝╚═══════════════╝

License

Licensed under either of

at your option.

Licensing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~165KB