Created
September 9, 2023 12:15
-
-
Save marvhus/5e977391d9fc545258d0499d4dd7d4bf to your computer and use it in GitHub Desktop.
Blocking Console Input in Jai.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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