mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Avoid Querying screen size on every resize
This commit is contained in:
@@ -47,10 +47,7 @@ func shell_loop(rl *readline.Readline, kill_if_signaled bool) (int, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lp.OnResize = func(old_size loop.ScreenSize, new_size loop.ScreenSize) error {
|
lp.OnResize = rl.OnResize
|
||||||
rl.Redraw()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
lp.OnKeyEvent = func(event *loop.KeyEvent) error {
|
lp.OnKeyEvent = func(event *loop.KeyEvent) error {
|
||||||
err := rl.OnKeyEvent(event)
|
err := rl.OnKeyEvent(event)
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ type Readline struct {
|
|||||||
history *History
|
history *History
|
||||||
|
|
||||||
// The number of lines after the initial line on the screen
|
// The number of lines after the initial line on the screen
|
||||||
cursor_y int
|
cursor_y int
|
||||||
|
screen_width int
|
||||||
// Input lines
|
// Input lines
|
||||||
lines []string
|
lines []string
|
||||||
// The cursor position in the text
|
// The cursor position in the text
|
||||||
@@ -172,3 +173,12 @@ func (self *Readline) AllText() string {
|
|||||||
func (self *Readline) CursorAtEndOfLine() bool {
|
func (self *Readline) CursorAtEndOfLine() bool {
|
||||||
return self.cursor.X >= len(self.lines[self.cursor.Y])
|
return self.cursor.X >= len(self.lines[self.cursor.Y])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Readline) OnResize(old_size loop.ScreenSize, new_size loop.ScreenSize) error {
|
||||||
|
self.screen_width = int(new_size.CellWidth)
|
||||||
|
if self.screen_width < 1 {
|
||||||
|
self.screen_width = 1
|
||||||
|
}
|
||||||
|
self.Redraw()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (self *Readline) move_cursor_to_text_position(pos, screen_width int) int {
|
|||||||
return num_of_lines
|
return num_of_lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Readline) current_screen_size() (int, int) {
|
func (self *Readline) update_current_screen_size() {
|
||||||
screen_size, err := self.loop.ScreenSize()
|
screen_size, err := self.loop.ScreenSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
screen_size.WidthCells = 80
|
screen_size.WidthCells = 80
|
||||||
@@ -41,12 +41,14 @@ func (self *Readline) current_screen_size() (int, int) {
|
|||||||
if screen_size.HeightCells < 1 {
|
if screen_size.HeightCells < 1 {
|
||||||
screen_size.HeightCells = 1
|
screen_size.HeightCells = 1
|
||||||
}
|
}
|
||||||
return int(screen_size.WidthCells), int(screen_size.HeightCells)
|
self.screen_width = int(screen_size.WidthCells)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Readline) redraw() {
|
func (self *Readline) redraw() {
|
||||||
screen_width, _ := self.current_screen_size()
|
if self.screen_width == 0 {
|
||||||
if screen_width < 4 {
|
self.update_current_screen_size()
|
||||||
|
}
|
||||||
|
if self.screen_width < 4 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if self.cursor_y > 0 {
|
if self.cursor_y > 0 {
|
||||||
@@ -66,7 +68,7 @@ func (self *Readline) redraw() {
|
|||||||
if i == self.cursor.Y {
|
if i == self.cursor.Y {
|
||||||
line_with_cursor = y
|
line_with_cursor = y
|
||||||
}
|
}
|
||||||
y += self.write_line_with_prompt(line, p, screen_width)
|
y += self.write_line_with_prompt(line, p, self.screen_width)
|
||||||
}
|
}
|
||||||
self.loop.MoveCursorVertically(-y + line_with_cursor)
|
self.loop.MoveCursorVertically(-y + line_with_cursor)
|
||||||
line := self.lines[self.cursor.Y]
|
line := self.lines[self.cursor.Y]
|
||||||
@@ -74,6 +76,6 @@ func (self *Readline) redraw() {
|
|||||||
if self.cursor.Y > 0 {
|
if self.cursor.Y > 0 {
|
||||||
plen = self.continuation_prompt_len
|
plen = self.continuation_prompt_len
|
||||||
}
|
}
|
||||||
line_with_cursor += self.move_cursor_to_text_position(plen+wcswidth.Stringwidth(line[:self.cursor.X]), screen_width)
|
line_with_cursor += self.move_cursor_to_text_position(plen+wcswidth.Stringwidth(line[:self.cursor.X]), self.screen_width)
|
||||||
self.cursor_y = line_with_cursor
|
self.cursor_y = line_with_cursor
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user