Something went wrong. Try again.
A sans-I/O Zig library that reads and writes DEC sixel graphics as z2d surfaces.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Copies standard input to standard output, replacing each sixel image with//! a line saying what it was://!//! $ img2sixel picture.png | zig build example//! [sixel 640x480, ended by st]//!//! With `--reencode`, writes each image back out through the encoder instead,//! which shows the round trip in a terminal that displays sixel.
const std = @import("std");const Io = std.Io;const sixel = @import("sixel");
const Handler = struct { gpa: std.mem.Allocator, out: *Io.Writer, reencode: bool,
pub fn image(self: *Handler, img: sixel.Image) !void { var owned = img; defer owned.deinit(self.gpa); if (self.reencode) { try sixel.encode(self.gpa, self.out, &owned.surface, .{}); return; } try self.out.print("[sixel {d}x{d}, ended by {t}{s}]\n", .{ owned.width(), owned.height(), owned.termination, if (owned.clipped) ", clipped" else "", }); }};
pub fn main(init: std.process.Init) !void { const io = init.io; const args = try init.minimal.args.toSlice(init.arena.allocator()); var reencode = false; for (args[1..]) |arg| { if (std.mem.eql(u8, arg, "--reencode")) reencode = true; }
var in_buffer: [64 * 1024]u8 = undefined; var out_buffer: [64 * 1024]u8 = undefined; var stdin: Io.File.Reader = .init(.stdin(), io, &in_buffer); var stdout: Io.File.Writer = .init(.stdout(), io, &out_buffer);
var handler: Handler = .{ .gpa = init.gpa, .out = &stdout.interface, .reencode = reencode }; try sixel.relay(init.gpa, &stdin.interface, &stdout.interface, &handler, .{});}