mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
Various fixes to make CodeQL happy
This commit is contained in:
@@ -144,25 +144,25 @@ func KeyEventFromCSI(csi string) *KeyEvent {
|
|||||||
csi = csi[:len(csi)-1]
|
csi = csi[:len(csi)-1]
|
||||||
sections := strings.Split(csi, ";")
|
sections := strings.Split(csi, ";")
|
||||||
|
|
||||||
get_sub_sections := func(section string, missing int) []int {
|
get_sub_sections := func(section string, missing int32) []int32 {
|
||||||
p := strings.Split(section, ":")
|
p := strings.Split(section, ":")
|
||||||
ans := make([]int, len(p))
|
ans := make([]int32, len(p))
|
||||||
for i, x := range p {
|
for i, x := range p {
|
||||||
if x == "" {
|
if x == "" {
|
||||||
ans[i] = missing
|
ans[i] = missing
|
||||||
} else {
|
} else {
|
||||||
q, err := strconv.Atoi(x)
|
q, err := strconv.ParseUint(x, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ans[i] = q
|
ans[i] = int32(q)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
first_section := get_sub_sections(sections[0], 0)
|
first_section := get_sub_sections(sections[0], 0)
|
||||||
second_section := []int{}
|
second_section := []int32{}
|
||||||
third_section := []int{}
|
third_section := []int32{}
|
||||||
if len(sections) > 1 {
|
if len(sections) > 1 {
|
||||||
second_section = get_sub_sections(sections[1], 1)
|
second_section = get_sub_sections(sections[1], 1)
|
||||||
}
|
}
|
||||||
@@ -170,9 +170,9 @@ func KeyEventFromCSI(csi string) *KeyEvent {
|
|||||||
third_section = get_sub_sections(sections[2], 0)
|
third_section = get_sub_sections(sections[2], 0)
|
||||||
}
|
}
|
||||||
var ans = KeyEvent{Type: PRESS, CSI: orig_csi}
|
var ans = KeyEvent{Type: PRESS, CSI: orig_csi}
|
||||||
var keynum int
|
var keynum int32
|
||||||
if val, ok := letter_trailer_to_csi_number_map[last_char]; ok {
|
if val, ok := letter_trailer_to_csi_number_map[last_char]; ok {
|
||||||
keynum = val
|
keynum = int32(val)
|
||||||
} else {
|
} else {
|
||||||
if len(first_section) == 0 {
|
if len(first_section) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -180,7 +180,7 @@ func KeyEventFromCSI(csi string) *KeyEvent {
|
|||||||
keynum = first_section[0]
|
keynum = first_section[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
key_name := func(keynum int) string {
|
key_name := func(keynum int32) string {
|
||||||
switch keynum {
|
switch keynum {
|
||||||
case 0:
|
case 0:
|
||||||
return ""
|
return ""
|
||||||
@@ -190,11 +190,11 @@ func KeyEventFromCSI(csi string) *KeyEvent {
|
|||||||
}
|
}
|
||||||
return "F3"
|
return "F3"
|
||||||
default:
|
default:
|
||||||
if val, ok := csi_number_to_functional_number_map[keynum]; ok {
|
if val, ok := csi_number_to_functional_number_map[int(keynum)]; ok {
|
||||||
keynum = val
|
keynum = int32(val)
|
||||||
}
|
}
|
||||||
ans := ""
|
ans := ""
|
||||||
if val, ok := functional_key_number_to_name_map[keynum]; ok {
|
if val, ok := functional_key_number_to_name_map[int(keynum)]; ok {
|
||||||
ans = val
|
ans = val
|
||||||
} else {
|
} else {
|
||||||
ans = string(rune(keynum))
|
ans = string(rune(keynum))
|
||||||
|
|||||||
@@ -70,18 +70,22 @@ func (self *Color) FromNumber(n uint8) {
|
|||||||
self.Is_numbered, self.Red = true, n
|
self.Is_numbered, self.Red = true, n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func as_uint8(x int) uint8 {
|
||||||
|
return uint8(uint(x) & 0xff)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Color) FromExtended(nums ...int) bool {
|
func (self *Color) FromExtended(nums ...int) bool {
|
||||||
switch nums[0] {
|
switch nums[0] {
|
||||||
case 5:
|
case 5:
|
||||||
if len(nums) > 1 {
|
if len(nums) > 1 {
|
||||||
self.Red = uint8(nums[1])
|
self.Red = as_uint8(nums[1])
|
||||||
self.Is_numbered = true
|
self.Is_numbered = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if len(nums) > 3 {
|
if len(nums) > 3 {
|
||||||
self.Is_numbered = false
|
self.Is_numbered = false
|
||||||
self.Red, self.Green, self.Blue = uint8(nums[1]), uint8(nums[2]), uint8(nums[3])
|
self.Red, self.Green, self.Blue = as_uint8(nums[1]), as_uint8(nums[2]), as_uint8(nums[3])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func Abspath(path string) string {
|
|||||||
|
|
||||||
var KittyExe = sync.OnceValue(func() string {
|
var KittyExe = sync.OnceValue(func() string {
|
||||||
if kitty_pid := os.Getenv("KITTY_PID"); kitty_pid != "" {
|
if kitty_pid := os.Getenv("KITTY_PID"); kitty_pid != "" {
|
||||||
if kp, err := strconv.Atoi(kitty_pid); err == nil {
|
if kp, err := strconv.ParseInt(kitty_pid, 10, 32); err == nil {
|
||||||
if p, err := process.NewProcess(int32(kp)); err == nil {
|
if p, err := process.NewProcess(int32(kp)); err == nil {
|
||||||
if exe, err := p.Exe(); err == nil && filepath.IsAbs(exe) && filepath.Base(exe) == "kitty" {
|
if exe, err := p.Exe(); err == nil && filepath.IsAbs(exe) && filepath.Base(exe) == "kitty" {
|
||||||
return exe
|
return exe
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ func is_oct_char(ch rune) bool {
|
|||||||
func (self *ansi_c) write_digits(base int) {
|
func (self *ansi_c) write_digits(base int) {
|
||||||
if self.digit_idx > 0 {
|
if self.digit_idx > 0 {
|
||||||
text := string(self.digits[:self.digit_idx])
|
text := string(self.digits[:self.digit_idx])
|
||||||
val, err := strconv.ParseUint(text, base, 32)
|
if val, err := strconv.ParseUint(text, base, 32); err == nil && val <= 0x10ffff {
|
||||||
if err == nil {
|
|
||||||
self.output.WriteRune(rune(val))
|
self.output.WriteRune(rune(val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ func (self sgr_color) as_sgr(base int) string {
|
|||||||
return fmt.Sprintf("%d:2:%d:%d:%d", base+8, self.color.Red, self.color.Green, self.color.Blue)
|
return fmt.Sprintf("%d:2:%d:%d:%d", base+8, self.color.Red, self.color.Green, self.color.Blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func as_uint8(x int) uint8 {
|
||||||
|
return uint8(uint(x) & 0xff)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *sgr_color) from_extended(nums []int) bool {
|
func (self *sgr_color) from_extended(nums []int) bool {
|
||||||
switch nums[0] {
|
switch nums[0] {
|
||||||
case 5:
|
case 5:
|
||||||
@@ -45,9 +49,9 @@ func (self *sgr_color) from_extended(nums []int) bool {
|
|||||||
case 2:
|
case 2:
|
||||||
if len(nums) > 3 {
|
if len(nums) > 3 {
|
||||||
self.number = -1
|
self.number = -1
|
||||||
self.color.Red = uint8(nums[1])
|
self.color.Red = as_uint8(nums[1])
|
||||||
self.color.Green = uint8(nums[2])
|
self.color.Green = as_uint8(nums[2])
|
||||||
self.color.Blue = uint8(nums[3])
|
self.color.Blue = as_uint8(nums[3])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user