Avoid Querying screen size on every resize

This commit is contained in:
Kovid Goyal
2022-10-16 12:20:27 +05:30
parent 595a78c956
commit 260249491d
3 changed files with 20 additions and 11 deletions

View File

@@ -59,7 +59,8 @@ type Readline struct {
history *History
// The number of lines after the initial line on the screen
cursor_y int
cursor_y int
screen_width int
// Input lines
lines []string
// The cursor position in the text
@@ -172,3 +173,12 @@ func (self *Readline) AllText() string {
func (self *Readline) CursorAtEndOfLine() bool {
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
}