aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-04-30 02:31:41 +0100
committerdam <dam@gudinoff>2024-04-30 02:31:41 +0100
commitc7a4f1c0c98a1df1e683b3de0454b3d981519e9e (patch)
tree6607631023a2aaed5b5cf10aba6736ef17cc0885 /modules/TUI
parentd7c2c312fe2ac08cadc3534a0a35357ef50cca20 (diff)
downloadtask-time-tracker-c7a4f1c0c98a1df1e683b3de0454b3d981519e9e.tar.zst
task-time-tracker-c7a4f1c0c98a1df1e683b3de0454b3d981519e9e.zip
WIP : OMG I add copied octal values from C which became decimal ones in jai.
Diffstat (limited to 'modules/TUI')
-rw-r--r--modules/TUI/unix.jai217
1 files changed, 135 insertions, 82 deletions
diff --git a/modules/TUI/unix.jai b/modules/TUI/unix.jai
index a6cd467..bb22030 100644
--- a/modules/TUI/unix.jai
+++ b/modules/TUI/unix.jai
@@ -10,50 +10,45 @@ USE_LIBC :: true;
#import "System";
#import "POSIX";
- // Set Attributes Actions.
- // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios-tcflow.h
+ // Queue selector used in tcflush(...).
+ // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios-struct.h
// MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
- // OptionalActions :: enum s32 {
- TCSANOW :: 0; // Change immediately.
- TCSADRAIN :: 1; // Change when pending output is written.
- TCSAFLUSH :: 2; // Flush pending input before changing.
- // }
-
- // TODO
- // QueueSelector :: enum s32 {
- // queue_selector
+ QueueSelector :: enum s32 {
#if OS == {
case .LINUX;
- // https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios.h
- TCIFLUSH :: 0; // Discard data received but not yet read.
- TCOFLUSH :: 1; // Discard data written but not yet sent.
- TCIOFLUSH :: 2; // Discard all pending data.
+ TCIFLUSH :: 0; // Discard data received but not yet read.
+ TCOFLUSH :: 1; // Discard data written but not yet sent.
+ TCIOFLUSH :: 2; // Discard all pending data.
case .MACOS;
- // https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
- TCIFLUSH :: 1; // Discard data received but not yet read.
- TCOFLUSH :: 2; // Discard data written but not yet sent.
- TCIOFLUSH :: 3; // Discard all pending data.
+ TCIFLUSH :: 1; // Discard data received but not yet read.
+ TCOFLUSH :: 2; // Discard data written but not yet sent.
+ TCIOFLUSH :: 3; // Discard all pending data.
}
}
+
+ // Optional actions used in tcsetattr(...).
+ // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios-tcflow.h
+ // MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
+ OptionalActions :: enum s32 {
+ TCSANOW :: 0; // Change immediately.
+ TCSADRAIN :: 1; // Change when pending output is written.
+ TCSAFLUSH :: 2; // Flush pending input before changing.
+ }
+ // Terminal control (struct termios).
// LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios-struct.h
// MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
- #if OS == {
- case .LINUX;
+ Terminal_IO_Mode :: struct {
+
+ #if OS == {
+ case .LINUX;
NCCS :: 32;
- case .MACOS;
+ case .MACOS;
NCCS :: 20;
- }
+ }
- // Information for the termios.h enums is platform dependent and was retrieved from:
- // https://elixir.bootlin.com/glibc/latest/source/sysdeps/unix/sysv/linux/bits/termios.h
-
-
-
- // The struct termios.
- Terminal_IO_Mode :: struct {
c_iflag : Input_Modes; // Input mode flags.
c_oflag : Output_Modes; // Output mode flags.
c_cflag : Control_Modes; // Control modes flags.
@@ -65,68 +60,126 @@ USE_LIBC :: true;
}
// Input modes.
+ // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios-c_iflag.h
+ // MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
Input_Modes :: enum_flags u32 {
- IGNBRK :: 0000001; // Ignore break condition.
- BRKINT :: 0000002; // Signal interrupt on break.
- IGNPAR :: 0000004; // Ignore characters with parity errors.
- PARMRK :: 0000010; // Mark parity and framing errors.
- INPCK :: 0000020; // Enable input parity check.
- ISTRIP :: 0000040; // Strip 8th bit off characters.
- INLCR :: 0000100; // Map NL to CR on input.
- IGNCR :: 0000200; // Ignore CR.
- ICRNL :: 0000400; // Map CR to NL on input.
- IUCLC :: 0001000; // Translate upper case input to lower case (not in POSIX).
- IXON :: 0002000; // Enable start/stop output control.
- IXANY :: 0004000; // Any character will restart after stop.
- IXOFF :: 0010000; // Enable start/stop input control.
- IMAXBEL :: 0020000; // Ring bell when input queue is full (not in POSIX).
- IUTF8 :: 0040000; // Input is UTF8 (not in POSIX).
+ IGNBRK :: 0x00000001; // Ignore break condition.
+ BRKINT :: 0x00000002; // Signal interrupt on break.
+ IGNPAR :: 0x00000004; // Ignore characters with parity errors.
+ PARMRK :: 0x00000008; // Mark parity and framing errors.
+ INPCK :: 0x00000010; // Enable input parity check.
+ ISTRIP :: 0x00000020; // Strip 8th bit off characters.
+ INLCR :: 0x00000040; // Map NL to CR on input.
+ IGNCR :: 0x00000080; // Ignore CR.
+ ICRNL :: 0x00000100; // Map CR to NL on input.
+
+ #if OS == {
+
+ case .LINUX;
+ IXON :: 0x00000400; // Enable start/stop output control.
+ IXANY :: 0x00000800; // Any character will restart after stop.
+ IXOFF :: 0x00001000; // Enable start/stop input control.
+
+ case .MACOS;
+ IXON :: 0x00000200; // Enable start/stop output control.
+ IXANY :: 0x00000400; // Any character will restart after stop.
+ IXOFF :: 0x00000800; // Enable start/stop input control.
+
+ }
}
// Output modes.
+ // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios.h
+ // MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
Output_Modes :: enum_flags u32 {
- OPOST :: 0000001; // Perform output processing.
- OLCUC :: 0000002; // Map lowercase characters to uppercase on output (not in POSIX).
- ONLCR :: 0000004; // Map NL to CR-NL on output.
- OCRNL :: 0000010; // Map CR to NL.
- ONOCR :: 0000020; // Discard CR's when on column 0.
- ONLRET :: 0000040; // Move to column 0 on NL.
- OFILL :: 0000100; // Send fill characters for delays.
- OFDEL :: 0000200; // Fill is DEL.
- VTDLY :: 0040000; // Select vertical-tab delays:
- VT0 :: 0000000; // Vertical-tab delay type 0.
- VT1 :: 0040000; // Vertical-tab delay type 1.
+ #if OS == {
+
+ case .LINUX;
+ OPOST :: 0x00000001; // Perform output processing.
+ ONLCR :: 0x00000004; // Map NL to CR-NL on output.
+ OCRNL :: 0x00000008; // Map CR to NL.
+ ONOCR :: 0x00000010; // Discard CR's when on column 0.
+ ONLRET :: 0x00000020; // Move to column 0 on NL.
+ OFILL :: 0x00000040; // Send fill characters for delays.
+
+ case .MACOS;
+ OPOST :: 0x00000001; // Perform output processing.
+ ONLCR :: 0x00000002; // Map NL to CR-NL on output.
+ OCRNL :: 0x00000010; // Map CR to NL.
+ ONOCR :: 0x00000020; // Discard CR's when on column 0.
+ ONLRET :: 0x00000040; // Move to column 0 on NL.
+ OFILL :: 0x00000080; // Send fill characters for delays.
+ }
}
// Control modes.
+ // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios.h
+ // MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
Control_Modes :: enum u32 {
- CS5 :: 0000000; // 5 bits per byte.
- CS6 :: 0000020; // 6 bits per byte.
- CS7 :: 0000040; // 7 bits per byte.
- CS8 :: 0000060; // 8 bits per byte.
- CSIZE :: 0000060; // Number of bits per byte (mask).
- CSTOPB :: 0000100; // Two stop bits instead of one.
- CREAD :: 0000200; // Enable receiver.
- PARENB :: 0000400; // Parity enable.
- PARODD :: 0001000; // Odd parity instead of even.
- HUPCL :: 0002000; // Hang up on last close.
- CLOCAL :: 0004000;
+ #if OS == {
+
+ case .LINUX;
+ CS5 :: 0x00000000; // 5 bits per byte.
+ CS6 :: 0x00000010; // 6 bits per byte.
+ CS7 :: 0x00000020; // 7 bits per byte.
+ CS8 :: 0x00000030; // 8 bits per byte.
+ CSIZE :: 0x00000030; // Number of bits per byte (mask).
+ CSTOPB :: 0x00000040; // Two stop bits instead of one.
+ CREAD :: 0x00000080; // Enable receiver.
+ PARENB :: 0x00000100; // Parity enable.
+ PARODD :: 0x00000200; // Odd parity instead of even.
+ HUPCL :: 0x00000400; // Hang up on last close.
+ CLOCAL :: 0x00000800;
+
+ case .MACOS;
+ CS5 :: 0x00000000; // 5 bits per byte.
+ CS6 :: 0x00000100; // 6 bits per byte.
+ CS7 :: 0x00000200; // 7 bits per byte.
+ CS8 :: 0x00000300; // 8 bits per byte.
+ CSIZE :: 0x00000300; // Number of bits per byte (mask).
+ CSTOPB :: 0x00000400; // Two stop bits instead of one.
+ CREAD :: 0x00000800; // Enable receiver.
+ PARENB :: 0x00001000; // Parity enable.
+ PARODD :: 0x00002000; // Odd parity instead of even.
+ HUPCL :: 0x00004000; // Hang up on last close.
+ CLOCAL :: 0x00008000;
+ }
}
// Local modes.
+ // LINUX : https://sourceware.org/git/glibc.git -> ./sysdeps/unix/sysv/linux/bits/termios.h
+ // MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
Local_Modes :: enum_flags u32 {
- ISIG :: 0000001; // Enable signals.
- ICANON :: 0000002; // Do erase and kill processing.
- ECHO :: 0000010; // Enable echo.
- ECHOE :: 0000020; // Visual erase for ERASE.
- ECHOK :: 0000040; // Echo NL after KILL.
- ECHONL :: 0000100; // Echo NL even if ECHO is off.
- NOFLSH :: 0000200; // Disable flush after interrupt.
- TOSTOP :: 0000400; // Send SIGTTOU for background output.
- IEXTEN :: 0100000; // Enable DISCARD and LNEXT.
+ #if OS == {
+
+ case .LINUX;
+ ISIG :: 0x00000001; // Enable signals.
+ ICANON :: 0x00000002; // Do erase and kill processing.
+ ECHO :: 0x00000008; // Enable echo.
+ ECHOE :: 0x00000010; // Visual erase for ERASE.
+ ECHOK :: 0x00000020; // Echo NL after KILL.
+ ECHONL :: 0x00000040; // Echo NL even if ECHO is off.
+ NOFLSH :: 0x00000080; // Disable flush after interrupt.
+ TOSTOP :: 0x00000100; // Send SIGTTOU for background output.
+ IEXTEN :: 0x00008000; // Enable DISCARD and LNEXT.
+
+ case .MACOS;
+ ISIG :: 0x00000080; // Enable signals.
+ ICANON :: 0x00000100; // Do erase and kill processing.
+ ECHO :: 0x00000008; // Enable echo.
+ ECHOE :: 0x00000002; // Visual erase for ERASE.
+ ECHOK :: 0x00000004; // Echo NL after KILL.
+ ECHONL :: 0x00000010; // Echo NL even if ECHO is off.
+ NOFLSH :: 0x80000000; // Disable flush after interrupt.
+ TOSTOP :: 0x00400000; // Send SIGTTOU for background output.
+ IEXTEN :: 0x00000400; // Enable DISCARD and LNEXT.
+ }
}
// Control Characters
+ TODO WIP
+ // LINUX : ???
+ // MACOS : https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/termios.h.auto.html
Control_Chars :: enum u8 {
VINTR :: 0;
VQUIT :: 1;
@@ -185,13 +238,13 @@ else {
k_termios: __kernel_termios;
cmd: u64;
if optional_actions == {
- case xx SetAttributesActions.TCSANOW;
+ case xx OptionalActions.TCSANOW;
cmd = TCSETS;
- case xx SetAttributesActions.TCSADRAIN;
+ case xx OptionalActions.TCSADRAIN;
cmd = TCSETSW;
- case xx SetAttributesActions.TCSAFLUSH;
+ case xx OptionalActions.TCSAFLUSH;
cmd = TCSETSF;
case;
@@ -343,7 +396,7 @@ OS_prepare_terminal :: () -> success := true {
raw_tio_mode.c_cc[Control_Chars.VMIN] = 1;
raw_tio_mode.c_cc[Control_Chars.VTIME] = 0;
- error = tcsetattr(STDIN_FILENO, TCSANOW, *raw_tio_mode);
+ error = tcsetattr(STDIN_FILENO, xx OptionalActions.TCSANOW, *raw_tio_mode);
if error {
error_code, error_string := get_error_value_and_string();
log_error("Failed to set raw_tio_mode: code %, %", error_code, error_string);
@@ -357,7 +410,7 @@ OS_prepare_terminal :: () -> success := true {
OS_reset_terminal :: inline () -> success := true {
restore_resize_handler();
- error := tcsetattr(STDIN_FILENO, TCSANOW, *initial_tio_mode);
+ error := tcsetattr(STDIN_FILENO, xx OptionalActions.TCSANOW, *initial_tio_mode);
if error {
error_code, error_string := get_error_value_and_string();
log_error("Failed to set initial_tio_mode: code %, %", error_code, error_string);
@@ -367,7 +420,7 @@ OS_reset_terminal :: inline () -> success := true {
}
OS_flush_input :: inline () -> success := true {
- error := tcflush(STDIN_FILENO, TCIFLUSH);
+ error := tcflush(STDIN_FILENO, xx QueueSelector.TCIFLUSH);
if error {
error_code, error_string := get_error_value_and_string();
log_error("Failed to flush input: code %, %", error_code, error_string);