Print code but with ZIG?

Does anyone know how to print on a printer the code for example “code print” from “vscode” but with the particularities of zig
I only found “enscript” with the java template humm??? Most readable

There aren’t any libraries for using printers for zig as far as I am aware, so you will probably need to write the code yourself unfortunately. What is your use case? If you willing to rely on a system installed tool like enscript, you can get something running pretty quickly with zig. Here’s a basic starting point with enscript:

const std = @import("std");

pub fn main() !void {
    // ChildProcess.init requires an allocator, so we create one here
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const allocator = gpa.allocator();

    var enscript = std.ChildProcess.init(&.{
        "printer_name", // this will need to be set to the name of the printer - you may want use a variable here
    }, allocator);
    enscript.stdin_behavior = .Pipe; // Open a pipe with enscript so we can write our text to stdin

    try enscript.spawn(); // Spawn enscript

    // stdin to enscript is nullable, we unwrap it here or return an error if we can't
    const enscript_stdin = enscript.stdin orelse return error.StdinIsNull;
    // We print our text to enscript's stdin
    try enscript_stdin.writeAll("This will be printed");

    // Now we wait for enscript to finish running before exiting main
    var term = try enscript.wait();
    _ = term;

Note that I’m no export with enscript so you’ll need to read it’s documentation to figure out how to use it properly. Also, if enscript isn’t installed you’ll get a FileNotFound error when trying to access the stdin pipe.

Hopefully that answers your question! Otherwise, feel free to ask more.


this is what I already do, but I have to put java/ as the language

enscript -1rG --line-numbers -p $home/print/ --highlight=java --color=1 -c  FOLDER/FILESRC  --borders --highlight-bar-gray=gray --word-wrap

I was asking if anyone was using a script or something or a plugin etc.