stdIn or stdout changed last night

Hi, I compiled with the night version and I can’t figure out how to solve this problem.

I’ve looked for explanations ???

I understand that std.io is changed to std.Io

I’ve seen that std.fs.File.stdout exists

const stdout = std.io.getStdOut().writer();
const stdin = std.io.getStdIn().reader();

error: root source file struct ‘Io’ has no member named ‘getStdIn’
const stdin = std.io.getStdIn().reader();

std.fs.File.std[out/err/in]()
fyi, in the future File will be moved to std.Io as it will be a part of the new Io interface

how to hang up stdout to std.Io.Writer please

before with :
const stdout = std.fs.File.stdout();
const stdin = std.fs.File.stdin();

it worked properly

today I have an error
stdout.print(“\x1b[{d}D”, .{y}) catch {};

.readerStreaming() and .writerStreaming().
there are non streaming variants but those dont work with stdin/out/error and will change their config to streaming when you first try to use them meaning they wont do the read/write the first time either.

both variants take a buffer as the buffering is a part of the interface instead of being a specific implementation as it used to be. You can set this to a zero length slice &.{}, if you don’t want a buffer, but it will be slower.
if you use a buffer dont forget to call flush on the interface.

The interface has changed to now be a field of the implementation usually called interface, whereas before it was gotten through an any() function, the generic implementations have been deprecated for a while and just forwarded to the any implementations.

the API has changed to be more focused on chaining readers and writers and is a little more clunky when you are at either end of the chaining.

1 Like

the convenient write/print/read api has been removed from File as it’s now a primitive for the Io interface, the nicer apis are apart of reader,writer, and Io(when that gets finished).

fyi the apis and interfaces are still being developed so they could change again, though any changes should be smaller (aside from Io being finished).

a code snippet:

pub fn main() !void {
    var out = std.fs.File.stdout().writerStreaming(&.{});
    var in = std.fs.File.stdin().readerStreaming(&.{});

    var buf: [10]u8 = undefined;
    while (in.interface.readVec(&.{&buf})) |r| {
        if (r > 0)
            try out.interface.print("echo: {s}", .{buf[0..r]});
    } else |e| return e;
}

(post deleted by author)

to replace print and writeall in my code

onst std = @import("std");


var stdout = std.fs.File.stdout().writerStreaming(&.{});
var in = std.fs.File.stdin().readerStreaming(&.{});
var stdin = std.fs.File.stdin();
pub inline fn print( comptime format: []const u8, args: anytype) !void {
    // const out = self(args); 
    try stdout.interface.print(format, args) ;

}
pub inline fn writeAll( args: anytype) !void {

    try stdout.interface.writeAll(args);
}

fn getkey() ! void{

    var keybuf: [16] u8 =  [_]u8{0} ** 16;
    var c: usize = 0;
        while (c == 0) {
            c = try stdin.read(&keybuf) ;
        }
    if ( c > 0) std.debug.print("len char {d} {s}",.{c,keybuf});

}

pub fn main() !void {
    // const out = std.fs.File.stdout().writerStreaming(&.{});


    var buf: [10]u8 = undefined;
    while (in.interface.readVec(&.{&buf})) |r| {
        std.debug.print("nbr char  {d}",.{r});
        if (r > 0)    
            try print("echo: {s}", .{buf[0..r]});
            if (buf[0] == 'q') break;
        if (r > 0)
            try writeAll("ok");
    } else |e| return e;

    try getkey();
   
}

is this going to be stable, you were talking about a stdout move…

you’ll have to change std.fs.File to std.Io.File when the Io interface gets merged (almost certainly will happen after 0.15).

are you using llm to code? not accusing, just the code has so many issues when I’ve seen you on here for a while.

/home/soleil/.zig/zig build -Doptimize=Debug --build-file /home/soleil/Zterm/src-zig/buildtest.zig

I use helix
and manjaro

I don’t use IA too many errors and obtuse

    ///-----------------------
    /// build test
    ///-----------------------

const std = @import("std");
// zi=g 0.12.0 dev

pub fn build(b: *std.Build) void {
    // Standard release options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
    const target   = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});


    // Definition of module
    // data commune
    // Definition of dependencies


    // ===========================================================
    // const cursed = b.dependency("libtui", .{}).module("cursed");
    // const utils  = b.dependency("libtui", .{}).module("utils");
    // const forms  = b.dependency("libtui", .{}).module("forms");
    // const grid   = b.dependency("libtui", .{}).module("grid");
    // const menu   = b.dependency("libtui", .{}).module("menu");


    // Building the executable
    const Prog = b.addExecutable(.{
        .name = "test",
        .root_module = b.createModule(.{
        .root_source_file =b.path( "./test.zig" ),
        .target = target,
        .optimize = optimize,
        }),
    });
    // Prog.root_module.addImport("cursed", cursed);

    // Prog.root_module.addImport("utils", utils);

    
    // Prog.root_module.addImport("forms", forms);
     
    // Prog.root_module.addImport("grid" , grid);
    
    // Prog.root_module.addImport("menu" , menu);

    b.installArtifact(Prog);


}