mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-10 18:48:54 +02:00
Bump go version to 1.21
Allows us to use the much faster builtin min/max functions for two variable min/max
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@@ -107,7 +105,7 @@ func (e MouseEvent) String() string {
|
||||
}
|
||||
|
||||
func pixel_to_cell(px, length, cell_length int) int {
|
||||
px = utils.Max(0, utils.Min(px, length-1))
|
||||
px = max(0, min(px, length-1))
|
||||
return px / cell_length
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"kitty/tools/tui/loop"
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@@ -68,7 +67,7 @@ func (self *MouseSelection) Clear() { *self = MouseSelection{} }
|
||||
func (ms *MouseSelection) StartNewSelection(ev *loop.MouseEvent, line LinePos, min_y, max_y, cell_width, cell_height int) {
|
||||
*ms = MouseSelection{cell_width: cell_width, cell_height: cell_height, min_y: min_y, max_y: max_y}
|
||||
ms.start.line = line
|
||||
ms.start.x = utils.Max(line.MinX(), utils.Min(ev.Cell.X, line.MaxX()))
|
||||
ms.start.x = max(line.MinX(), min(ev.Cell.X, line.MaxX()))
|
||||
cell_start := cell_width * ev.Cell.X
|
||||
ms.start.in_first_half_of_cell = ev.Pixel.X <= cell_start+cell_width/2
|
||||
ms.end = ms.start
|
||||
@@ -78,7 +77,7 @@ func (ms *MouseSelection) StartNewSelection(ev *loop.MouseEvent, line LinePos, m
|
||||
func (ms *MouseSelection) Update(ev *loop.MouseEvent, line LinePos) {
|
||||
ms.drag_scroll.timer_id = 0
|
||||
if ms.is_active {
|
||||
ms.end.x = utils.Max(line.MinX(), utils.Min(ev.Cell.X, line.MaxX()))
|
||||
ms.end.x = max(line.MinX(), min(ev.Cell.X, line.MaxX()))
|
||||
cell_start := ms.cell_width * ms.end.x
|
||||
ms.end.in_first_half_of_cell = ev.Pixel.X <= cell_start+ms.cell_width/2
|
||||
ms.end.line = line
|
||||
|
||||
@@ -19,7 +19,7 @@ func (self *Readline) text_upto_cursor_pos() string {
|
||||
buf.Grow(1024)
|
||||
for i, line := range self.input_state.lines {
|
||||
if i == self.input_state.cursor.Y {
|
||||
buf.WriteString(line[:utils.Min(len(line), self.input_state.cursor.X)])
|
||||
buf.WriteString(line[:min(len(line), self.input_state.cursor.X)])
|
||||
break
|
||||
} else {
|
||||
buf.WriteString(line)
|
||||
@@ -34,7 +34,7 @@ func (self *Readline) text_after_cursor_pos() string {
|
||||
buf.Grow(1024)
|
||||
for i, line := range self.input_state.lines {
|
||||
if i == self.input_state.cursor.Y {
|
||||
buf.WriteString(line[utils.Min(len(line), self.input_state.cursor.X):])
|
||||
buf.WriteString(line[min(len(line), self.input_state.cursor.X):])
|
||||
buf.WriteString("\n")
|
||||
} else if i > self.input_state.cursor.Y {
|
||||
buf.WriteString(line)
|
||||
@@ -165,7 +165,7 @@ func (self *Readline) move_cursor_vertically(amt int) (ans int) {
|
||||
break
|
||||
}
|
||||
}
|
||||
target_line_num := utils.Min(utils.Max(0, cursor_line_num+amt), len(screen_lines)-1)
|
||||
target_line_num := min(max(0, cursor_line_num+amt), len(screen_lines)-1)
|
||||
ans = target_line_num - cursor_line_num
|
||||
if ans != 0 {
|
||||
self.move_cursor_to_target_line(screen_lines[cursor_line_num], screen_lines[target_line_num])
|
||||
@@ -441,9 +441,9 @@ func (self *Readline) kill_previous_space_delimited_word(amt uint, traverse_line
|
||||
}
|
||||
|
||||
func (self *Readline) ensure_position_in_bounds(pos *Position) *Position {
|
||||
pos.Y = utils.Max(0, utils.Min(pos.Y, len(self.input_state.lines)-1))
|
||||
pos.Y = max(0, min(pos.Y, len(self.input_state.lines)-1))
|
||||
line := self.input_state.lines[pos.Y]
|
||||
pos.X = utils.Max(0, utils.Min(pos.X, len(line)))
|
||||
pos.X = max(0, min(pos.X, len(line)))
|
||||
return pos
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ type cell struct {
|
||||
}
|
||||
|
||||
func (self cell) whitespace(desired_length int) string {
|
||||
return strings.Repeat(" ", utils.Max(0, desired_length-self.length))
|
||||
return strings.Repeat(" ", max(0, desired_length-self.length))
|
||||
}
|
||||
|
||||
type column struct {
|
||||
@@ -212,7 +212,7 @@ func (self *Readline) screen_lines_for_match_group_without_descriptions(g *cli.M
|
||||
}
|
||||
}
|
||||
var ans []column
|
||||
ncols := utils.Max(1, self.screen_width/(max_length+1))
|
||||
ncols := max(1, self.screen_width/(max_length+1))
|
||||
for {
|
||||
cols, total_length := layout_words_in_table(words, lengths, ncols)
|
||||
if total_length > self.screen_width {
|
||||
|
||||
@@ -25,8 +25,8 @@ func (self *Readline) update_current_screen_size() {
|
||||
screen_size.WidthCells = 80
|
||||
screen_size.HeightCells = 24
|
||||
}
|
||||
self.screen_width = utils.Max(1, int(screen_size.WidthCells))
|
||||
self.screen_height = utils.Max(1, int(screen_size.HeightCells))
|
||||
self.screen_width = max(1, int(screen_size.WidthCells))
|
||||
self.screen_height = max(1, int(screen_size.HeightCells))
|
||||
}
|
||||
|
||||
type ScreenLine struct {
|
||||
|
||||
@@ -227,13 +227,13 @@ func (self *HistoryMatches) first(rl *Readline) bool {
|
||||
}
|
||||
|
||||
func (self *HistoryMatches) last(rl *Readline) bool {
|
||||
self.current_idx = utils.Max(0, len(self.items)-1)
|
||||
self.current_idx = max(0, len(self.items)-1)
|
||||
return self.apply(rl)
|
||||
}
|
||||
|
||||
func (self *HistoryMatches) previous(num uint, rl *Readline) bool {
|
||||
if self.current_idx > 0 {
|
||||
self.current_idx = utils.Max(0, self.current_idx-int(num))
|
||||
self.current_idx = max(0, self.current_idx-int(num))
|
||||
return self.apply(rl)
|
||||
}
|
||||
return false
|
||||
@@ -241,7 +241,7 @@ func (self *HistoryMatches) previous(num uint, rl *Readline) bool {
|
||||
|
||||
func (self *HistoryMatches) next(num uint, rl *Readline) bool {
|
||||
if self.current_idx+1 < len(self.items) {
|
||||
self.current_idx = utils.Min(len(self.items)-1, self.current_idx+int(num))
|
||||
self.current_idx = min(len(self.items)-1, self.current_idx+int(num))
|
||||
return self.apply(rl)
|
||||
}
|
||||
return false
|
||||
@@ -295,7 +295,7 @@ func (self *Readline) markup_history_search() {
|
||||
|
||||
func (self *Readline) remove_text_from_history_search(num uint) uint {
|
||||
l := len(self.history_search.query)
|
||||
nl := utils.Max(0, l-int(num))
|
||||
nl := max(0, l-int(num))
|
||||
self.history_search.query = self.history_search.query[:nl]
|
||||
num_removed := uint(l - nl)
|
||||
self.add_text_to_history_search("") // update the search results
|
||||
@@ -361,7 +361,7 @@ func (self *Readline) add_text_to_history_search(text string) {
|
||||
idx = 0
|
||||
}
|
||||
}
|
||||
self.history_search.current_idx = utils.Max(0, idx)
|
||||
self.history_search.current_idx = max(0, idx)
|
||||
self.markup_history_search()
|
||||
}
|
||||
|
||||
@@ -372,9 +372,9 @@ func (self *Readline) next_history_search(backwards bool, num uint) bool {
|
||||
return false
|
||||
}
|
||||
if backwards {
|
||||
ni = utils.Max(0, ni-int(num))
|
||||
ni = max(0, ni-int(num))
|
||||
} else {
|
||||
ni = utils.Min(ni+int(num), len(self.history_search.items)-1)
|
||||
ni = min(ni+int(num), len(self.history_search.items)-1)
|
||||
}
|
||||
if ni == self.history_search.current_idx {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user