Crates.io | text2art |
lib.rs | text2art |
version | 1.0.2 |
source | src |
created_at | 2022-08-09 19:37:04.508255 |
updated_at | 2023-10-10 19:10:50.67264 |
description | Simple library for translate text to ascii art. |
homepage | |
repository | https://github.com/follow39/text2art |
max_upload_size | |
id | 641979 |
size | 90,200 |
_ ___ _ | | |__ \ | | | |_ ___ __ __ ) | __ _ _ __ | |_ | __| / _ \\ \/ / / / / _` || '__|| __| | |_ | __/ ) ( / /_ | (_| || | | |_ \__| \___|/_/\_\|____| \__,_||_| \__|
text2art = "1.0.2"
cargo run --example basic_usage
Code
use text2art::BasicFonts;
use text2art::Font;
use text2art::Printer;
fn main() {
let font = match Font::from_basic(BasicFonts::Big) {
Ok(font) => font,
Err(_) => panic!("something wrong with font"),
};
let prntr = Printer::with_font(font);
prntr.print_to_stdio("Welcome to tex2art! :)").ok();
prntr.print_to_stdio("text for print_to_stdio").ok();
prntr
.print_to("text for print_to", &mut std::io::stdout())
.ok();
let rendered_text = prntr.render_text("text for render");
match rendered_text {
Ok(rendered_text) => println!("{}", rendered_text),
Err(_) => println!("Something went wrong!"),
}
}
Output
__ __ __ _ _ _ ___ _ _ \ \ \ \ / / | | | | | | |__ \ | | | | _ | | \ \ /\ / / ___ | | ___ ___ _ __ ___ ___ | |_ ___ | |_ ___ __ __ ) | __ _ _ __ | |_ | | (_) | | \ \/ \/ / / _ \| | / __| / _ \ | '_ ` _ \ / _ \ | __| / _ \ | __| / _ \\ \/ / / / / _` || '__|| __|| | | | \ /\ / | __/| || (__ | (_) || | | | | || __/ | |_ | (_) | | |_ | __/ ) ( / /_ | (_| || | | |_ |_| _ | | \/ \/ \___||_| \___| \___/ |_| |_| |_| \___| \__| \___/ \__| \___|/_/\_\|____| \__,_||_| \__|(_) (_)/_/ _ _ __ _ _ _ _ _ _ | | | | / _| (_) | | | | | | | |(_) | |_ ___ __ __| |_ | |_ ___ _ __ _ __ _ __ _ _ __ | |_ | |_ ___ ___ | |_ __| | _ ___ | __| / _ \\ \/ /| __| | _| / _ \ | '__| | '_ \ | '__|| || '_ \ | __| | __| / _ \ / __|| __| / _` || | / _ \ | |_ | __/ ) ( | |_ | | | (_) || | | |_) || | | || | | || |_ ______ | |_ | (_) | ______ \__ \| |_ | (_| || || (_) | \__| \___|/_/\_\ \__| |_| \___/ |_| | .__/ |_| |_||_| |_| \__||______| \__| \___/ |______||___/ \__| \__,_||_| \___/ | | |_| _ _ __ _ _ _ | | | | / _| (_) | | | | | |_ ___ __ __| |_ | |_ ___ _ __ _ __ _ __ _ _ __ | |_ | |_ ___ | __| / _ \\ \/ /| __| | _| / _ \ | '__| | '_ \ | '__|| || '_ \ | __| | __| / _ \ | |_ | __/ ) ( | |_ | | | (_) || | | |_) || | | || | | || |_ ______ | |_ | (_) | \__| \___|/_/\_\ \__| |_| \___/ |_| | .__/ |_| |_||_| |_| \__||______| \__| \___/ | | |_| _ _ __ _ | | | | / _| | | | |_ ___ __ __| |_ | |_ ___ _ __ _ __ ___ _ __ __| | ___ _ __ | __| / _ \\ \/ /| __| | _| / _ \ | '__| | '__| / _ \| '_ \ / _` | / _ \| '__| | |_ | __/ ) ( | |_ | | | (_) || | | | | __/| | | || (_| || __/| | \__| \___|/_/\_\ \__| |_| \___/ |_| |_| \___||_| |_| \__,_| \___||_|
You can use your font from str or file. You can use these functions
pub fn from_basic(font: basic_fonts::BasicFonts) -> Result<Font, FontError>
pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Font, FontError>
Font rules:
For example:
'a':0: __ _ \n / _` |\n| (_| |\n \__,_|\n
Where:
'a' - font grapheme (you can use any unicode grapheme here) : - segmentation symbol 0 - shift __ _ \n / _` |\n| (_| |\n \__,_|\n - data
_ | | | |_ | __| | |_ \__|
Will be implemented as
't':0: _ \n| | \n| |_ \n| __|\n| |_ \n \__|\n
Grapheme without shift
't':0: _ \n| | \n| |_ \n| __|\n| |_ \n \__|\n _ ___ 5 | | | |_ | __| | |_ \__| ___ 0 | | 1 5 Internal parameters: Width - 5 Height - 6 Shift - 0
Grapheme with negative shift
'p':-2: _ __ \n| '_ \ \n| |_) |\n| .__/ \n| | \n|_| \n _ __ ___ 3 | '_ \ | |_) | | .__/ ___ 0 | | |_| __ -2 | | 1 7 Internal parameters: Width - 7 Height - 6 Shift - -2
Grapheme with positive shift
'"':3: _ _ \n( | )\n V V \n _ _ ___ 5 ( | ) V V ___ 3 ___ 0 | | 1 5 Internal parameters: Width - 5 Height - 3 Shift - 3
All examples in one structure
_ _ _ | | ( | ) | |_ _ __ V V | __|| '_ \ | |_ | |_) | \__|| .__/ | | |_|
For example:
# letters [a-z] 'a':0: __ _ \n / _` |\n| (_| |\n \__,_|\n 'b':0: _ \n| | \n| |__ \n| '_ \ \n| |_) |\n|_.__/ \n