Bez popisu

Anas Elgarhy 5172fb0385 chore(github): add polar link před 2 měsíci
.github 5172fb0385 chore(github): add polar link před 2 měsíci
benches 80324bf77a chore(bench): create benches před 4 měsíci
samples 9648afed83 chore(samples): add the sample images před 4 měsíci
src 3c15e97e7e docs: fix typo před 4 měsíci
.codespellignore a1458bfe56 chore(codespell): create the codespell ignore file před 4 měsíci
.dockerignore df85b8f6a0 chore(docker): create docker ignore list před 3 měsíci
.gitignore 46feadf00b chore(git): remove `Cargo.lock` entry před 6 měsíci
.release-plz.toml ba30dade13 chore(changelog): re-generate changelog před 2 měsíci
CHANGELOG.md 9f974321e5 chore(changelog): re-generate changelog před 2 měsíci
CONTRIBUTING.md 9c2a87004e chore: add the contributing guide před 4 měsíci
Cargo.lock 2f1e173802 fix(deps): update rust crate image to 0.25 (#62) před 2 měsíci
Cargo.toml 3189699920 chore(cargo): ver bump před 2 měsíci
Dockerfile fb2e554222 chore(docker): patch Cargo.toml před 3 měsíci
LICENSE.txt 37e39e3c9d Create the MIT license 💙 před 1 rokem
README.md d083a23feb docs(readme): re-generate the readme před 4 měsíci
_deps.png 425e5f8ac7 chore(deps): don't include the dev-deps před 4 měsíci
_readme.tpl b33485f20e chore(readme): create readme template před 4 měsíci
_typos.toml 8a027da265 chore(typos): ignore .git dir před 4 měsíci
cliff.toml 8c65534e0a chore(cliff): setup git-cliff před 2 měsíci
committed.toml 535a35c56f chore(committed): create the commited config před 4 měsíci
deny.toml 76c217dcba chore(license): allow Zlib and Unicode-DFS-2016 před 4 měsíci
justfile 425e5f8ac7 chore(deps): don't include the dev-deps před 4 měsíci
renovate.json 9d76b9268d Add renovate.json před 1 rokem

README.md

asciicast

aarty

mini freamwork to render images in the terminals/ttys.

crates.io docs.rs downloads license

Examples

let cfg = Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%', '$', '@', '#'].into());

let image = image::open("mylove.jpg").unwrap();
let (w, h) = image.dimensions();

let mut out = BufWriter::with_capacity(cfg.calc_buf_size(w, h), io::stdout().lock());

convert_image_to_ascii(&cfg, &image, &mut out).expect("IO error");

Enable the foreground colors

let cfg = Config::new(vec![' ', '.', ',', '-', '~', '!', '*', '%'].into()).with_flags(COLORS);

// ...

Reverse them with the background color

let cfg = Config::new(Sympols::empty()).with_background((232, 209, 204)).with_flags(COLORS | REVERSE);

// ...

If you wanna build a rebresentesion in memory so you can modify it or use it multiple times, then you may found that implement [FragmentWriter] for such a structher is useful.

struct TerminalFrame {
    fragments: Vec<(char, ANSIColor)>,
   cfg: Config,
}

impl FragmentWriter for TerminalFrame {
    fn background(&mut self, _: &ANSIColor) -> Result<bool, Box<dyn std::error::Error>> {
        // Nah, I don't care, I have my configs :p
        //  but pretent like if you care so it will skip the swap operation.
        Ok(true)
    }

    fn write_fragment(&mut self, info: FragmentInfo) -> Result<(), Box<dyn std::error::Error>> {
        self.fragments.push((info.sym, info.fg));
        Ok(())
    }

    fn write_colored_fragment(
        &mut self,
        info: FragmentInfo,
        _: Option<&ANSIColor>,
        _: Option<&ANSIColor>,
    ) -> Result<(), Box<dyn std::error::Error>> {
        self.write_fragment(info)
    }

    fn write_bytes(&mut self, _bytes: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
        // Just ignore them
        Ok(())
    }
}

// So you can use it as a buffer
let cfg = Config::new(vec!['I', 'L', 'O', 'V', 'E', 'U'].into()).with_flags(COLORS);

let image = image::open("mylove.jpg").unwrap();
let (w, h) = image.dimensions();
let mut frame = TerminalFrame {
    fragments: Vec::with_capacity(w as usize * h as usize),
    cfg: cfg.clone(),
};
aarty::convert_image_to_ascii(&cfg, &image, &mut frame).expect("Write error");
//  Do whatever you want with this object...

But be aware by doing this, you'll have to implement the rendaring mechanism when its its the time to print the image (a.k.a. rendering it).

For such this case, we have [TextImage], which basically dose the same thing as the code above but in more ergnomic way, And it does implement the rendering mechanism, so you can just print it, and it will render the image properly. You can enable this type with text_image feature, which is enabled by default.

The text_image feature also include the [ToTextImage] trait, which provide an ergonomic way to construct an [TextImage] object.

use aarty::ToTextImage;
let cfg = Config::new_with_background(Sympols::empty(), (232, 209, 204).into()).with_flags(COLORS | REVERSE);

let image = image::open("mylove.jpg").unwrap().to_text(cfg);
println!("{image}");

You have to enable the image feature for this to work.

The binary

We offer a simple binary that's implement the most of this crate features. You can build it with the build command or if u use cargo then you can install it via cargo install aarty.

[!Note] for more information about the binary and how to use it, you can run aarty --help or see this match.

Contributing

I'm happy to accept any contributions, just consider reading the CONTRIBUTING.md guide first.

the main keywords are: signed commits, conventional commits, no emojis, linear history, the PR shouldn't have more than tree commits most of the time

License

This project is licensed under MIT license.

Dependencies graph

deps graph

Generated with cargo-depgraph