From a9df1b1cde1037d030f4e823ce576dfd9bcf9c97 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Tue, 20 May 2025 15:41:35 -0400 Subject: Rename `core:encoding/ansi` to `core:terminal/ansi` --- core/encoding/ansi/ansi.odin | 137 ---------------------------------- core/encoding/ansi/doc.odin | 20 ----- core/log/file_console_logger.odin | 2 +- core/terminal/ansi/ansi.odin | 137 ++++++++++++++++++++++++++++++++++ core/terminal/ansi/doc.odin | 20 +++++ core/testing/reporting.odin | 2 +- core/testing/runner.odin | 2 +- core/testing/signal_handler_libc.odin | 4 +- examples/all/all_main.odin | 4 +- 9 files changed, 164 insertions(+), 164 deletions(-) delete mode 100644 core/encoding/ansi/ansi.odin delete mode 100644 core/encoding/ansi/doc.odin create mode 100644 core/terminal/ansi/ansi.odin create mode 100644 core/terminal/ansi/doc.odin diff --git a/core/encoding/ansi/ansi.odin b/core/encoding/ansi/ansi.odin deleted file mode 100644 index 5550a1671..000000000 --- a/core/encoding/ansi/ansi.odin +++ /dev/null @@ -1,137 +0,0 @@ -package ansi - -BEL :: "\a" // Bell -BS :: "\b" // Backspace -ESC :: "\e" // Escape - -// Fe Escape sequences - -CSI :: ESC + "[" // Control Sequence Introducer -OSC :: ESC + "]" // Operating System Command -ST :: ESC + "\\" // String Terminator - -// CSI sequences - -CUU :: "A" // Cursor Up -CUD :: "B" // Cursor Down -CUF :: "C" // Cursor Forward -CUB :: "D" // Cursor Back -CNL :: "E" // Cursor Next Line -CPL :: "F" // Cursor Previous Line -CHA :: "G" // Cursor Horizontal Absolute -CUP :: "H" // Cursor Position -ED :: "J" // Erase in Display -EL :: "K" // Erase in Line -SU :: "S" // Scroll Up -SD :: "T" // Scroll Down -HVP :: "f" // Horizontal Vertical Position -SGR :: "m" // Select Graphic Rendition -AUX_ON :: "5i" // AUX Port On -AUX_OFF :: "4i" // AUX Port Off -DSR :: "6n" // Device Status Report - -// CSI: private sequences - -SCP :: "s" // Save Current Cursor Position -RCP :: "u" // Restore Saved Cursor Position -DECAWM_ON :: "?7h" // Auto Wrap Mode (Enabled) -DECAWM_OFF :: "?7l" // Auto Wrap Mode (Disabled) -DECTCEM_SHOW :: "?25h" // Text Cursor Enable Mode (Visible) -DECTCEM_HIDE :: "?25l" // Text Cursor Enable Mode (Invisible) - -// SGR sequences - -RESET :: "0" -BOLD :: "1" -FAINT :: "2" -ITALIC :: "3" // Not widely supported. -UNDERLINE :: "4" -BLINK_SLOW :: "5" -BLINK_RAPID :: "6" // Not widely supported. -INVERT :: "7" // Also known as reverse video. -HIDE :: "8" // Not widely supported. -STRIKE :: "9" -FONT_PRIMARY :: "10" -FONT_ALT1 :: "11" -FONT_ALT2 :: "12" -FONT_ALT3 :: "13" -FONT_ALT4 :: "14" -FONT_ALT5 :: "15" -FONT_ALT6 :: "16" -FONT_ALT7 :: "17" -FONT_ALT8 :: "18" -FONT_ALT9 :: "19" -FONT_FRAKTUR :: "20" // Rarely supported. -UNDERLINE_DOUBLE :: "21" // May be interpreted as "disable bold." -NO_BOLD_FAINT :: "22" -NO_ITALIC_BLACKLETTER :: "23" -NO_UNDERLINE :: "24" -NO_BLINK :: "25" -PROPORTIONAL_SPACING :: "26" -NO_REVERSE :: "27" -NO_HIDE :: "28" -NO_STRIKE :: "29" - -FG_BLACK :: "30" -FG_RED :: "31" -FG_GREEN :: "32" -FG_YELLOW :: "33" -FG_BLUE :: "34" -FG_MAGENTA :: "35" -FG_CYAN :: "36" -FG_WHITE :: "37" -FG_COLOR :: "38" -FG_COLOR_8_BIT :: "38;5" // Followed by ";n" where n is in 0..=255 -FG_COLOR_24_BIT :: "38;2" // Followed by ";r;g;b" where r,g,b are in 0..=255 -FG_DEFAULT :: "39" - -BG_BLACK :: "40" -BG_RED :: "41" -BG_GREEN :: "42" -BG_YELLOW :: "43" -BG_BLUE :: "44" -BG_MAGENTA :: "45" -BG_CYAN :: "46" -BG_WHITE :: "47" -BG_COLOR :: "48" -BG_COLOR_8_BIT :: "48;5" // Followed by ";n" where n is in 0..=255 -BG_COLOR_24_BIT :: "48;2" // Followed by ";r;g;b" where r,g,b are in 0..=255 -BG_DEFAULT :: "49" - -NO_PROPORTIONAL_SPACING :: "50" -FRAMED :: "51" -ENCIRCLED :: "52" -OVERLINED :: "53" -NO_FRAME_ENCIRCLE :: "54" -NO_OVERLINE :: "55" - -// SGR: non-standard bright colors - -FG_BRIGHT_BLACK :: "90" // Also known as grey. -FG_BRIGHT_RED :: "91" -FG_BRIGHT_GREEN :: "92" -FG_BRIGHT_YELLOW :: "93" -FG_BRIGHT_BLUE :: "94" -FG_BRIGHT_MAGENTA :: "95" -FG_BRIGHT_CYAN :: "96" -FG_BRIGHT_WHITE :: "97" - -BG_BRIGHT_BLACK :: "100" // Also known as grey. -BG_BRIGHT_RED :: "101" -BG_BRIGHT_GREEN :: "102" -BG_BRIGHT_YELLOW :: "103" -BG_BRIGHT_BLUE :: "104" -BG_BRIGHT_MAGENTA :: "105" -BG_BRIGHT_CYAN :: "106" -BG_BRIGHT_WHITE :: "107" - -// Fp Escape sequences - -DECSC :: ESC + "7" // DEC Save Cursor -DECRC :: ESC + "8" // DEC Restore Cursor - -// OSC sequences - -WINDOW_TITLE :: "2" // Followed by ";" ST. -HYPERLINK :: "8" // Followed by ";[params];" ST. Closed by OSC HYPERLINK ";;" ST. -CLIPBOARD :: "52" // Followed by ";c;" ST. diff --git a/core/encoding/ansi/doc.odin b/core/encoding/ansi/doc.odin deleted file mode 100644 index 966e6be00..000000000 --- a/core/encoding/ansi/doc.odin +++ /dev/null @@ -1,20 +0,0 @@ -/* -package ansi implements constant references to many widely-supported ANSI -escape codes, primarily used in terminal emulators for enhanced graphics, such -as colors, text styling, and animated displays. - -For example, you can print out a line of cyan text like this: - fmt.println(ansi.CSI + ansi.FG_CYAN + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR) - -Multiple SGR (Select Graphic Rendition) codes can be joined by semicolons: - fmt.println(ansi.CSI + ansi.BOLD + ";" + ansi.FG_BLUE + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR) - -If your terminal supports 24-bit true color mode, you can also do this: - fmt.println(ansi.CSI + ansi.FG_COLOR_24_BIT + ";0;255;255" + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR) - -For more information, see: -- [[ https://en.wikipedia.org/wiki/ANSI_escape_code ]] -- [[ https://www.vt100.net/docs/vt102-ug/chapter5.html ]] -- [[ https://invisible-island.net/xterm/ctlseqs/ctlseqs.html ]] -*/ -package ansi diff --git a/core/log/file_console_logger.odin b/core/log/file_console_logger.odin index f807f321f..0fe5c3477 100644 --- a/core/log/file_console_logger.odin +++ b/core/log/file_console_logger.odin @@ -3,11 +3,11 @@ package log import "base:runtime" -import "core:encoding/ansi" import "core:fmt" import "core:strings" import "core:os" import "core:terminal" +import "core:terminal/ansi" import "core:time" Level_Headers := [?]string{ diff --git a/core/terminal/ansi/ansi.odin b/core/terminal/ansi/ansi.odin new file mode 100644 index 000000000..5550a1671 --- /dev/null +++ b/core/terminal/ansi/ansi.odin @@ -0,0 +1,137 @@ +package ansi + +BEL :: "\a" // Bell +BS :: "\b" // Backspace +ESC :: "\e" // Escape + +// Fe Escape sequences + +CSI :: ESC + "[" // Control Sequence Introducer +OSC :: ESC + "]" // Operating System Command +ST :: ESC + "\\" // String Terminator + +// CSI sequences + +CUU :: "A" // Cursor Up +CUD :: "B" // Cursor Down +CUF :: "C" // Cursor Forward +CUB :: "D" // Cursor Back +CNL :: "E" // Cursor Next Line +CPL :: "F" // Cursor Previous Line +CHA :: "G" // Cursor Horizontal Absolute +CUP :: "H" // Cursor Position +ED :: "J" // Erase in Display +EL :: "K" // Erase in Line +SU :: "S" // Scroll Up +SD :: "T" // Scroll Down +HVP :: "f" // Horizontal Vertical Position +SGR :: "m" // Select Graphic Rendition +AUX_ON :: "5i" // AUX Port On +AUX_OFF :: "4i" // AUX Port Off +DSR :: "6n" // Device Status Report + +// CSI: private sequences + +SCP :: "s" // Save Current Cursor Position +RCP :: "u" // Restore Saved Cursor Position +DECAWM_ON :: "?7h" // Auto Wrap Mode (Enabled) +DECAWM_OFF :: "?7l" // Auto Wrap Mode (Disabled) +DECTCEM_SHOW :: "?25h" // Text Cursor Enable Mode (Visible) +DECTCEM_HIDE :: "?25l" // Text Cursor Enable Mode (Invisible) + +// SGR sequences + +RESET :: "0" +BOLD :: "1" +FAINT :: "2" +ITALIC :: "3" // Not widely supported. +UNDERLINE :: "4" +BLINK_SLOW :: "5" +BLINK_RAPID :: "6" // Not widely supported. +INVERT :: "7" // Also known as reverse video. +HIDE :: "8" // Not widely supported. +STRIKE :: "9" +FONT_PRIMARY :: "10" +FONT_ALT1 :: "11" +FONT_ALT2 :: "12" +FONT_ALT3 :: "13" +FONT_ALT4 :: "14" +FONT_ALT5 :: "15" +FONT_ALT6 :: "16" +FONT_ALT7 :: "17" +FONT_ALT8 :: "18" +FONT_ALT9 :: "19" +FONT_FRAKTUR :: "20" // Rarely supported. +UNDERLINE_DOUBLE :: "21" // May be interpreted as "disable bold." +NO_BOLD_FAINT :: "22" +NO_ITALIC_BLACKLETTER :: "23" +NO_UNDERLINE :: "24" +NO_BLINK :: "25" +PROPORTIONAL_SPACING :: "26" +NO_REVERSE :: "27" +NO_HIDE :: "28" +NO_STRIKE :: "29" + +FG_BLACK :: "30" +FG_RED :: "31" +FG_GREEN :: "32" +FG_YELLOW :: "33" +FG_BLUE :: "34" +FG_MAGENTA :: "35" +FG_CYAN :: "36" +FG_WHITE :: "37" +FG_COLOR :: "38" +FG_COLOR_8_BIT :: "38;5" // Followed by ";n" where n is in 0..=255 +FG_COLOR_24_BIT :: "38;2" // Followed by ";r;g;b" where r,g,b are in 0..=255 +FG_DEFAULT :: "39" + +BG_BLACK :: "40" +BG_RED :: "41" +BG_GREEN :: "42" +BG_YELLOW :: "43" +BG_BLUE :: "44" +BG_MAGENTA :: "45" +BG_CYAN :: "46" +BG_WHITE :: "47" +BG_COLOR :: "48" +BG_COLOR_8_BIT :: "48;5" // Followed by ";n" where n is in 0..=255 +BG_COLOR_24_BIT :: "48;2" // Followed by ";r;g;b" where r,g,b are in 0..=255 +BG_DEFAULT :: "49" + +NO_PROPORTIONAL_SPACING :: "50" +FRAMED :: "51" +ENCIRCLED :: "52" +OVERLINED :: "53" +NO_FRAME_ENCIRCLE :: "54" +NO_OVERLINE :: "55" + +// SGR: non-standard bright colors + +FG_BRIGHT_BLACK :: "90" // Also known as grey. +FG_BRIGHT_RED :: "91" +FG_BRIGHT_GREEN :: "92" +FG_BRIGHT_YELLOW :: "93" +FG_BRIGHT_BLUE :: "94" +FG_BRIGHT_MAGENTA :: "95" +FG_BRIGHT_CYAN :: "96" +FG_BRIGHT_WHITE :: "97" + +BG_BRIGHT_BLACK :: "100" // Also known as grey. +BG_BRIGHT_RED :: "101" +BG_BRIGHT_GREEN :: "102" +BG_BRIGHT_YELLOW :: "103" +BG_BRIGHT_BLUE :: "104" +BG_BRIGHT_MAGENTA :: "105" +BG_BRIGHT_CYAN :: "106" +BG_BRIGHT_WHITE :: "107" + +// Fp Escape sequences + +DECSC :: ESC + "7" // DEC Save Cursor +DECRC :: ESC + "8" // DEC Restore Cursor + +// OSC sequences + +WINDOW_TITLE :: "2" // Followed by ";" ST. +HYPERLINK :: "8" // Followed by ";[params];" ST. Closed by OSC HYPERLINK ";;" ST. +CLIPBOARD :: "52" // Followed by ";c;" ST. diff --git a/core/terminal/ansi/doc.odin b/core/terminal/ansi/doc.odin new file mode 100644 index 000000000..966e6be00 --- /dev/null +++ b/core/terminal/ansi/doc.odin @@ -0,0 +1,20 @@ +/* +package ansi implements constant references to many widely-supported ANSI +escape codes, primarily used in terminal emulators for enhanced graphics, such +as colors, text styling, and animated displays. + +For example, you can print out a line of cyan text like this: + fmt.println(ansi.CSI + ansi.FG_CYAN + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR) + +Multiple SGR (Select Graphic Rendition) codes can be joined by semicolons: + fmt.println(ansi.CSI + ansi.BOLD + ";" + ansi.FG_BLUE + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR) + +If your terminal supports 24-bit true color mode, you can also do this: + fmt.println(ansi.CSI + ansi.FG_COLOR_24_BIT + ";0;255;255" + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR) + +For more information, see: +- [[ https://en.wikipedia.org/wiki/ANSI_escape_code ]] +- [[ https://www.vt100.net/docs/vt102-ug/chapter5.html ]] +- [[ https://invisible-island.net/xterm/ctlseqs/ctlseqs.html ]] +*/ +package ansi diff --git a/core/testing/reporting.odin b/core/testing/reporting.odin index 6752cd79b..7c7eb7b2d 100644 --- a/core/testing/reporting.odin +++ b/core/testing/reporting.odin @@ -10,12 +10,12 @@ package testing */ import "base:runtime" -import "core:encoding/ansi" import "core:fmt" import "core:io" import "core:mem" import "core:path/filepath" import "core:strings" +import "core:terminal/ansi" // Definitions of colors for use in the test runner. SGR_RESET :: ansi.CSI + ansi.RESET + ansi.SGR diff --git a/core/testing/runner.odin b/core/testing/runner.odin index db0587370..c81d07109 100644 --- a/core/testing/runner.odin +++ b/core/testing/runner.odin @@ -13,7 +13,6 @@ package testing import "base:intrinsics" import "base:runtime" import "core:bytes" -import "core:encoding/ansi" @require import "core:encoding/base64" @require import "core:encoding/json" import "core:fmt" @@ -25,6 +24,7 @@ import "core:os" import "core:slice" @require import "core:strings" import "core:sync/chan" +import "core:terminal/ansi" import "core:thread" import "core:time" diff --git a/core/testing/signal_handler_libc.odin b/core/testing/signal_handler_libc.odin index 281fbde40..d17a6d6dc 100644 --- a/core/testing/signal_handler_libc.odin +++ b/core/testing/signal_handler_libc.odin @@ -12,9 +12,9 @@ package testing import "base:intrinsics" import "core:c/libc" -import "core:encoding/ansi" -import "core:sync" import "core:os" +import "core:sync" +import "core:terminal/ansi" @(private="file") stop_runner_flag: libc.sig_atomic_t diff --git a/examples/all/all_main.odin b/examples/all/all_main.odin index 97ecfee45..de037f6cd 100644 --- a/examples/all/all_main.odin +++ b/examples/all/all_main.odin @@ -58,7 +58,6 @@ import trace "core:debug/trace" import dynlib "core:dynlib" import net "core:net" -import ansi "core:encoding/ansi" import base32 "core:encoding/base32" import base64 "core:encoding/base64" import cbor "core:encoding/cbor" @@ -130,6 +129,7 @@ import sync "core:sync" import testing "core:testing" import terminal "core:terminal" +import ansi "core:terminal/ansi" import edit "core:text/edit" import i18n "core:text/i18n" @@ -203,7 +203,6 @@ _ :: pe _ :: trace _ :: dynlib _ :: net -_ :: ansi _ :: base32 _ :: base64 _ :: csv @@ -260,6 +259,7 @@ _ :: strings _ :: sync _ :: testing _ :: terminal +_ :: ansi _ :: scanner _ :: i18n _ :: match -- cgit v1.2.3