core:os -> core:os/os2 in core:terminal

This commit is contained in:
Jeroen van Rijn
2025-10-28 14:20:28 +01:00
parent 02477b2526
commit 456f9b17ed
4 changed files with 20 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
// Interaction with the command line interface (`CLI`) of the system.
package terminal
import "core:os"
import os "core:os/os2"
/*
This describes the range of colors that a terminal is capable of supporting.
@@ -15,14 +15,14 @@ Color_Depth :: enum {
}
/*
Returns true if the file `handle` is attached to a terminal.
Returns true if the `File` is attached to a terminal.
This is normally true for `os.stdout` and `os.stderr` unless they are
redirected to a file.
*/
@(require_results)
is_terminal :: proc(handle: os.Handle) -> bool {
return _is_terminal(handle)
is_terminal :: proc(f: ^os.File) -> bool {
return _is_terminal(f)
}
/*

View File

@@ -2,9 +2,7 @@
#+build js
package terminal
import "core:os"
_is_terminal :: proc "contextless" (handle: os.Handle) -> bool {
_is_terminal :: proc "contextless" (handle: any) -> bool {
return true
}

View File

@@ -2,12 +2,15 @@
#+build linux, darwin, netbsd, openbsd, freebsd, haiku
package terminal
import "base:runtime"
import "core:os"
import "core:sys/posix"
import "base:runtime"
import os "core:os/os2"
import "core:sys/posix"
_is_terminal :: proc "contextless" (handle: os.Handle) -> bool {
return bool(posix.isatty(posix.FD(handle)))
_is_terminal :: proc "contextless" (f: ^os.File) -> bool {
context = runtime.default_context()
fd := os.fd(f)
is_tty := posix.isatty(posix.FD(fd))
return bool(is_tty)
}
_init_terminal :: proc "contextless" () {

View File

@@ -1,12 +1,14 @@
#+private
package terminal
import "base:runtime"
import "core:os"
import "core:sys/windows"
import "base:runtime"
import os "core:os/os2"
import "core:sys/windows"
_is_terminal :: proc "contextless" (handle: os.Handle) -> bool {
is_tty := windows.GetFileType(windows.HANDLE(handle)) == windows.FILE_TYPE_CHAR
_is_terminal :: proc "contextless" (f: ^os.File) -> bool {
context = runtime.default_context()
fd := os.fd(f)
is_tty := windows.GetFileType(windows.HANDLE(fd)) == windows.FILE_TYPE_CHAR
return is_tty
}