garage44.eu/jeroen/pinnacle

logclone: git clone https://garage44.eu/jeroen/pinnacle.git

.. /programs/src/bin/palette.rs

raw

//! The command `palette`: the system's colours, drawn into an image the
//! terminal shows. What a command with a picture to show does: its pixels
//! go as shared memory beside an `Image` record.

#![no_std]
#![no_main]

extern crate alloc;

use pinnacle_gfx::{Canvas, Rect};
use pinnacle_rt::output::Output;
use pinnacle_ui::theme;

#[unsafe(no_mangle)]
fn main(argument: u64) -> u64 {
    let out = Output::start(argument);
    let colors = [
        ("Accent", theme::ACCENT),
        ("Good", theme::GOOD),
        ("Bad", theme::BAD),
        ("Text", theme::TEXT),
        ("Dim", theme::TEXT_DIM),
        ("Surface", theme::SURFACE_PRESSED),
    ];
    const CELL: i32 = 110;
    let (width, height) = (CELL * colors.len() as i32, 150);
    let mut pixels = alloc::vec![0u32; (width * height) as usize];
    let mut canvas = Canvas::new(&mut pixels, width as u32, height as u32);
    canvas.fill(theme::BACKGROUND);
    for (i, (name, color)) in colors.iter().enumerate() {
        let x = i as i32 * CELL;
        canvas.fill_circle(x + CELL / 2, 56, 40, *color);
        canvas.text_centered(theme::small(), Rect::new(x, 106, CELL, 34), name, theme::TEXT);
    }
    out.image(width as u32, height as u32, &pixels);
    out.status(0, "")
}