Require @(init) and @(fini) to be proc "contextless" ()

This commit is contained in:
gingerBill
2025-08-08 12:10:01 +01:00
parent 3194fda8f3
commit 7642e0a0e0
47 changed files with 170 additions and 102 deletions
+5 -2
View File
@@ -1,6 +1,7 @@
#+private
package terminal
import "base:runtime"
import "core:os"
import "core:strings"
@@ -68,9 +69,11 @@ get_environment_color :: proc() -> Color_Depth {
}
@(init)
init_terminal :: proc() {
init_terminal :: proc "contextless" () {
_init_terminal()
context = runtime.default_context()
// We respect `NO_COLOR` specifically as a color-disabler but not as a
// blanket ban on any terminal manipulation codes, hence why this comes
// after `_init_terminal` which will allow Windows to enable Virtual
@@ -81,6 +84,6 @@ init_terminal :: proc() {
}
@(fini)
fini_terminal :: proc() {
fini_terminal :: proc "contextless" () {
_fini_terminal()
}
+3 -3
View File
@@ -4,12 +4,12 @@ package terminal
import "core:os"
_is_terminal :: proc(handle: os.Handle) -> bool {
_is_terminal :: proc "contextless" (handle: os.Handle) -> bool {
return true
}
_init_terminal :: proc() {
_init_terminal :: proc "contextless" () {
color_depth = .None
}
_fini_terminal :: proc() { }
_fini_terminal :: proc "contextless" () { }
+5 -3
View File
@@ -2,15 +2,17 @@
#+build linux, darwin, netbsd, openbsd, freebsd, haiku
package terminal
import "base:runtime"
import "core:os"
import "core:sys/posix"
_is_terminal :: proc(handle: os.Handle) -> bool {
_is_terminal :: proc "contextless" (handle: os.Handle) -> bool {
return bool(posix.isatty(posix.FD(handle)))
}
_init_terminal :: proc() {
_init_terminal :: proc "contextless" () {
context = runtime.default_context()
color_depth = get_environment_color()
}
_fini_terminal :: proc() { }
_fini_terminal :: proc "contextless" () { }
+6 -3
View File
@@ -1,10 +1,11 @@
#+private
package terminal
import "base:runtime"
import "core:os"
import "core:sys/windows"
_is_terminal :: proc(handle: os.Handle) -> bool {
_is_terminal :: proc "contextless" (handle: os.Handle) -> bool {
is_tty := windows.GetFileType(windows.HANDLE(handle)) == windows.FILE_TYPE_CHAR
return is_tty
}
@@ -18,7 +19,7 @@ old_modes: [2]struct{
}
@(init)
_init_terminal :: proc() {
_init_terminal :: proc "contextless" () {
vtp_enabled: bool
for &v in old_modes {
@@ -42,13 +43,15 @@ _init_terminal :: proc() {
// This color depth is available on Windows 10 since build 10586.
color_depth = .Four_Bit
} else {
context = runtime.default_context()
// The user may be on a non-default terminal emulator.
color_depth = get_environment_color()
}
}
@(fini)
_fini_terminal :: proc() {
_fini_terminal :: proc "contextless" () {
for v in old_modes {
handle := windows.GetStdHandle(v.handle)
if handle == windows.INVALID_HANDLE || handle == nil {