refactor: Move gEscapeCode to where it is used (#2285)

This commit is contained in:
Joe Lim authored and GitHub committed 2025-12-02 18:23:11 +11:00
1 parent 4ee121fb56
commit 6402bafb9a
2 files changed
+6 -6

No files matched your search

+6 -4
View File
@@ -11,6 +11,8 @@ import (
"github.com/gdamore/tcell/v2"
)
const gEscapeCode byte = '\x1b'
// This function is used to remove style-related ANSI escape sequences from
// a given string.
//
@@ -49,7 +51,7 @@ func stripTermSequence(s string) string {
func readTermSequence(s string) string {
slen := len(s)
// must start with ESC
if slen < 2 || s[0] != byte(gEscapeCode) {
if slen < 2 || s[0] != gEscapeCode {
return ""
}
@@ -72,7 +74,7 @@ func readTermSequence(s string) string {
return s[:i+1]
}
// ESC\ (ECMA-48)
if b == byte(gEscapeCode) && i+1 < slen && s[i+1] == '\\' {
if b == gEscapeCode && i+1 < slen && s[i+1] == '\\' {
return s[:i+2]
}
}
@@ -99,7 +101,7 @@ func parseEscapeSequence(s string) tcell.Style {
// Accepts SGR and OSC sequences.
func applyTermSequence(s string, st tcell.Style) tcell.Style {
slen := len(s)
if slen < 2 || s[0] != byte(gEscapeCode) {
if slen < 2 || s[0] != gEscapeCode {
return st
}
switch s[1] {
@@ -112,7 +114,7 @@ func applyTermSequence(s string, st tcell.Style) tcell.Style {
// trim terminator (BEL or ESC\), then parse body
if s[slen-1] == 0x07 {
return applyOSC(s[2:slen-1], st)
} else if slen >= 2 && s[slen-2] == byte(gEscapeCode) && s[slen-1] == '\\' {
} else if slen >= 2 && s[slen-2] == gEscapeCode && s[slen-1] == '\\' {
return applyOSC(s[2:slen-2], st)
}
return st
-2
View File
@@ -22,8 +22,6 @@ import (
"golang.org/x/term"
)
const gEscapeCode = 27
var gKeyVal = map[tcell.Key]string{
tcell.KeyEnter: "<enter>",
tcell.KeyBackspace: "<backspace>",