~alva/zlolcat

d46dfb2b5234c415a510b3a6e53b32979d00ebdb — owl 6 months ago c78d16a
keep up with the times
18 files changed, 29 insertions(+), 57 deletions(-)

M README.md
D bin/linux/aarch64/zlolcat
D bin/linux/arm/zlolcat
D bin/linux/powerpc64/zlolcat
D bin/linux/powerpc64le/zlolcat
D bin/linux/riscv64/zlolcat
D bin/linux/x86/zlolcat
D bin/linux/x86_64/zlolcat
D bin/macos/aarch64/zlolcat
D bin/macos/x86_64/zlolcat
D bin/windows/aarch64/zlolcat.exe
D bin/windows/x86_64/zlolcat.exe
M build.zig
M build.zig.zon
M src/cat.zig
M src/main.zig
M src/term.zig
D x.sh
M README.md => README.md +6 -7
@@ 14,18 14,17 @@ but slower on some edge-cases.

![screenshot showing multibyte support and LCH colors](share/screenshot.png)

## install
there's prebuilt executables in [`bin`](bin/), but windows and mac are untested.
plop them somewhere on your `$PATH` and invoke `zlolcat` with something on `stdin`,
## building
[install latest zig](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
and do `zig build install --prefix ~/.local -Doptimize=ReleaseFast`.

## usage
install the program in your `$PATH`, and invoke `zlolcat` with something on `stdin`,
or `zlolcat file1 file2`.

use `zlolcat -h` to see all the options. to randomise the rainbow phase,
you can plug a random source in like `zlolcat -s$RANDOM`.

### build from source
[install latest zig](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
and do `zig build install --prefix ~/.local -Doptimize=ReleaseFast`.

## acknowledgments
- unicode support is thanks to [ziglyph](https://codeberg.org/dude_the_builder/ziglyph).
- argument parsing is thanks to [clap](https://github.com/Hejsil/zig-clap).

D bin/linux/aarch64/zlolcat => bin/linux/aarch64/zlolcat +0 -0
D bin/linux/arm/zlolcat => bin/linux/arm/zlolcat +0 -0
D bin/linux/powerpc64/zlolcat => bin/linux/powerpc64/zlolcat +0 -0
D bin/linux/powerpc64le/zlolcat => bin/linux/powerpc64le/zlolcat +0 -0
D bin/linux/riscv64/zlolcat => bin/linux/riscv64/zlolcat +0 -0
D bin/linux/x86/zlolcat => bin/linux/x86/zlolcat +0 -0
D bin/linux/x86_64/zlolcat => bin/linux/x86_64/zlolcat +0 -0
D bin/macos/aarch64/zlolcat => bin/macos/aarch64/zlolcat +0 -0
D bin/macos/x86_64/zlolcat => bin/macos/x86_64/zlolcat +0 -0
D bin/windows/aarch64/zlolcat.exe => bin/windows/aarch64/zlolcat.exe +0 -0
D bin/windows/x86_64/zlolcat.exe => bin/windows/x86_64/zlolcat.exe +0 -0
M build.zig => build.zig +5 -6
@@ 9,11 9,10 @@ pub fn build(b: *std.Build) void {
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
        .single_threaded = true,
        .strip = b.option(bool, "strip", "Omit debug symbols") orelse (optimize != .Debug),
    });

    exe.single_threaded = true;
    exe.strip = b.option(bool, "strip", "Omit debug symbols") orelse (optimize != .Debug);

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);


@@ 34,7 33,7 @@ pub fn build(b: *std.Build) void {
        .optimize = optimize,
    });

    if (target.os_tag == .windows)
    if (target.result.os.tag == .windows)
        b.enable_wine = true;

    const run_unit_tests = b.addRunArtifact(unit_tests);


@@ 51,7 50,7 @@ pub fn build(b: *std.Build) void {
            .target = target,
            .optimize = optimize,
        });
        exe.addModule(m, d.module(m));
        unit_tests.addModule(m, d.module(m));
        exe.root_module.addImport(m, d.module(m));
        unit_tests.root_module.addImport(m, d.module(m));
    }
}

M build.zig.zon => build.zig.zon +6 -6
@@ 6,16 6,16 @@
    },
    .dependencies = .{
        .clap = .{
            .url = "https://github.com/Hejsil/zig-clap/archive/34e0687.tar.gz",
            .hash = "12206795542ab1c19251aac74db20dda4c2abf3289597dd02d52b1d70175064fb298",
            .url = "https://github.com/Hejsil/zig-clap/archive/8c98e64.tar.gz",
            .hash = "122014e73fd712190e109950837b97f6143f02d7e2b6986e1db70b6f4aadb5ba6a0d",
        },
        .colorz = .{
            .url = "https://git.sr.ht/~alva/colorz/archive/5cd1b5d9.tar.gz",
            .hash = "122025a06e25e9e9f5b7a5d866719f0b6bfa3f007081a7cbef2983e0e5cb7b3fd60d",
            .url = "https://git.sr.ht/~alva/colorz/archive/69b52a6.tar.gz",
            .hash = "122076114a4693592b7b08bd81d9ffae0e4d79f310cec3119b462712e075bc5372ff",
        },
        .ziglyph = .{
            .url = "https://codeberg.org/dude_the_builder/ziglyph/archive/ef6a97e3e6.tar.gz",
            .hash = "1220847f934ea57e90ffb4d447a43e37ff4dce2aab23c84513dfff591376350ffd31",
            .url = "https://codeberg.org/dude_the_builder/ziglyph/archive/947ed39203.tar.gz",
            .hash = "12208b23d1eb6dcb929e85346524db8f8b8aa1401bdf8a97dee1e0cfb55da8d5fb42",
        },
    },
}

M src/cat.zig => src/cat.zig +3 -3
@@ 34,9 34,9 @@ pub fn Cat(comptime WriterT: type) type {
                    self.color_data[i * entry_len ..],
                    color_fmt,
                    .{
                        colorz.crudeIntFromF32(u8, col.r),
                        colorz.crudeIntFromF32(u8, col.g),
                        colorz.crudeIntFromF32(u8, col.b),
                        colorz.fastIntFromFloat(u8, col.r),
                        colorz.fastIntFromFloat(u8, col.g),
                        colorz.fastIntFromFloat(u8, col.b),
                    },
                );
            }

M src/main.zig => src/main.zig +7 -5
@@ 18,28 18,30 @@ const params = clap.parseParamsComptime(
);

const parsers = .{
    .file = clap.parsers.string,
    .real = clap.parsers.float(f32),
    .int = clap.parsers.int(u16, 0),
    .file = clap.parsers.string,
    .amb = clap.parsers.enumeration(zg.display_width.AmbiguousWidth),
};

pub fn main() !void {
    @setFloatMode(std.builtin.FloatMode.Optimized);
    @setFloatMode(std.builtin.FloatMode.optimized);
    const std_out = std.io.getStdOut();
    const is_tty = std_out.isTty();
    var diag = clap.Diagnostic{};
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    var res = clap.parse(clap.Help, &params, parsers, .{
        .diagnostic = &diag,
        .allocator = gpa.allocator(),
    }) catch |err| {
        try diag.report(std.io.getStdErr().writer(), err);
        std.os.exit(1);
        std.process.exit(1);
    };
    defer res.deinit();

    if (res.args.help != 0) {
        try clap.help(std_out.writer(), clap.Help, &params, .{});
        std.os.exit(1);
        std.process.exit(1);
    }

    var bw = std.io.bufferedWriter(std_out.writer());


@@ 75,7 77,7 @@ pub fn main() !void {
    uffda catch |e| {
        const std_err = std.io.getStdErr();
        try std_err.writer().print("\r😿 there was a {s}\x1b[0K\n", .{@errorName(e)});
        std.os.exit(1);
        std.process.exit(1);
    };
}


M src/term.zig => src/term.zig +2 -2
@@ 8,8 8,8 @@ pub fn getTermWidth() !u16 {
}

fn getTermWidthIoctl() !u16 {
    var termsz: std.os.system.winsize = undefined;
    if (-1 == std.os.system.ioctl(1, std.os.system.T.IOCGWINSZ, @intFromPtr(&termsz)))
    var termsz: std.posix.system.winsize = undefined;
    if (-1 == std.posix.system.ioctl(1, std.posix.system.T.IOCGWINSZ, @intFromPtr(&termsz)))
        return error.IoCtl;
    return termsz.ws_col;
}

D x.sh => x.sh +0 -28
@@ 1,28 0,0 @@
#!/bin/sh
set -eu

out=$(dirname "$(readlink -f "$0")")/bin

build_for_arch_and_os() {
        zig build -Doptimize=ReleaseFast -Dtarget="$1-$2" --prefix "$out/$2/$1"
        mv "$out/$2/$1/bin/"* "$out/$2/$1/"
        rmdir "$out/$2/$1/bin"
}

test_for_arch_and_os() {
        zig build test -Dtarget="$1-$2"
}

for a in aarch64 arm riscv64 powerpc64 powerpc64le x86_64 x86; do
    build_for_arch_and_os $a linux
done

for a in aarch64 x86_64; do
    for o in windows macos; do
        build_for_arch_and_os $a $o 
    done
done

for o in linux windows; do # macos doesn't work for some reason
    test_for_arch_and_os x86_64 "$o"
done