Skip to content

Instantly share code, notes, and snippets.

@thetarnav
Last active March 28, 2024 15:28
Show Gist options
  • Select an option

  • Save thetarnav/435194b41e49532dcdcb7645a55c6f29 to your computer and use it in GitHub Desktop.

Select an option

Save thetarnav/435194b41e49532dcdcb7645a55c6f29 to your computer and use it in GitHub Desktop.
isatty in odin
when ODIN_OS == .Windows {
is_terminal :: proc(fd: os.Handle) -> bool {
return false
}
} else {
foreign import libc "system:c"
foreign libc {
@(link_name = "isatty")
_isatty :: proc(fd: os.Handle) -> b32 ---
}
is_terminal :: proc(fd: os.Handle) -> bool {
return bool(_isatty(fd))
}
}
main :: proc() {
if is_terminal(os.stdin) {
fmt.println("\e[0;36mEnter a name:\e[0m")
}
buf, alloc_err := make([]byte, mem.Megabyte * 10)
if alloc_err != nil {
fmt.panicf("error allocating memory: %v", alloc_err)
}
input: string
input_len, os_err := os.read(os.stdin, buf[:])
if os_err != os.ERROR_NONE {
fmt.panicf("error reading input: %d", os_err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment