mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Require @(init) and @(fini) to be proc "contextless" ()
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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" () { }
|
||||
@@ -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" () { }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user