Skip to content

Instantly share code, notes, and snippets.

@marvhus
Created September 9, 2023 12:15
Show Gist options
  • Save marvhus/5e977391d9fc545258d0499d4dd7d4bf to your computer and use it in GitHub Desktop.
Save marvhus/5e977391d9fc545258d0499d4dd7d4bf to your computer and use it in GitHub Desktop.
Blocking Console Input in Jai.
main :: () {
print("What is your name?\n> ");
name := input();
print("Hello, %!\n", name);
}
#import "Basic";
#if OS == .LINUX {
#import "POSIX";
input :: () -> string {
MAX_BYTES_TO_READ :: 4096; // if anyone needs more, just modify it
buffer: [MAX_BYTES_TO_READ] u8;
bytes_read := read(STDIN_FILENO, buffer.data, MAX_BYTES_TO_READ-1);
str := to_string(buffer.data, bytes_read-1); // ignoring the newline at the end
return copy_string(str);
}
} else {
#assert(false); // @TODO support more than linux
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment