malevich 1.18.2

Terminal plotting: a small grammar of marks, honest axes, millions of points
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! The iTerm2 inline-image encoder: a PNG inside an OSC 1337 escape.
//!
//! `width`/`height` are given in cells, pinning the image to the exact cell box
//! the layout reserved — the terminal scales if its real cell geometry differs
//! from the configured one, so chrome and panel can never drift apart.

use super::render::Image;
use super::{base64, png};

pub(crate) fn encode(image: &Image, columns: usize, rows: usize) -> String {
    let png = png::encode(image);
    let payload = base64::encode(&png);
    format!(
        "\x1b]1337;File=inline=1;size={};width={columns};height={rows};preserveAspectRatio=0:{payload}\x07",
        png.len()
    )
}