1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +02:00

bump gocui

This commit is contained in:
Jesse Duffield
2022-10-02 12:47:57 -07:00
parent c953871ec7
commit 5670c0a301
26 changed files with 220 additions and 25 deletions

View File

@ -37,8 +37,12 @@ func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.TextArea.MoveCursorDown()
case key == KeyArrowUp:
v.TextArea.MoveCursorUp()
case key == KeyArrowLeft && (mod&ModAlt) != 0:
v.TextArea.MoveLeftWord()
case key == KeyArrowLeft:
v.TextArea.MoveCursorLeft()
case key == KeyArrowRight && (mod&ModAlt) != 0:
v.TextArea.MoveRightWord()
case key == KeyArrowRight:
v.TextArea.MoveCursorRight()
case key == KeyEnter:

View File

@ -214,6 +214,8 @@ func (ei *escapeInterpreter) outputNormal() error {
case p == 0:
ei.curFgColor = ColorDefault
ei.curBgColor = ColorDefault
case p >= 21 && p <= 29:
ei.curFgColor &= ^getFontEffect(p - 20)
default:
ei.curFgColor |= getFontEffect(p)
}

View File

@ -64,6 +64,54 @@ func (self *TextArea) MoveCursorRight() {
self.cursor++
}
func (self *TextArea) MoveLeftWord() {
if self.cursor == 0 {
return
}
if self.atLineStart() {
self.cursor--
return
}
for !self.atLineStart() && strings.ContainsRune(WHITESPACES, self.content[self.cursor-1]) {
self.cursor--
}
separators := false
for !self.atLineStart() && strings.ContainsRune(WORD_SEPARATORS, self.content[self.cursor-1]) {
self.cursor--
separators = true
}
if !separators {
for !self.atLineStart() && !strings.ContainsRune(WHITESPACES+WORD_SEPARATORS, self.content[self.cursor-1]) {
self.cursor--
}
}
}
func (self *TextArea) MoveRightWord() {
if self.atEnd() {
return
}
if self.atLineEnd() {
self.cursor++
return
}
for !self.atLineEnd() && strings.ContainsRune(WHITESPACES, self.content[self.cursor]) {
self.cursor++
}
separators := false
for !self.atLineEnd() && strings.ContainsRune(WORD_SEPARATORS, self.content[self.cursor]) {
self.cursor++
separators = true
}
if !separators {
for !self.atLineEnd() && !strings.ContainsRune(WHITESPACES+WORD_SEPARATORS, self.content[self.cursor]) {
self.cursor++
}
}
}
func (self *TextArea) MoveCursorUp() {
x, y := self.GetCursorXY()
self.SetCursor2D(x, y-1)

View File

@ -601,6 +601,14 @@ func (v *View) writeCells(x, y int, cells []cell) {
v.lines[y] = line[:newLen]
}
// readCell gets cell at specified location (x, y)
func (v *View) readCell(x, y int) (cell, bool) {
if y < 0 || y >= len(v.lines) || x < 0 || x >= len(v.lines[y]) {
return cell{}, false
}
return v.lines[y][x], true
}
// Write appends a byte slice into the view's internal buffer. Because
// View implements the io.Writer interface, it can be passed as parameter
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
@ -631,17 +639,29 @@ func (v *View) writeRunes(p []rune) {
for _, r := range p {
switch r {
case '\n':
if c, ok := v.readCell(v.wx+1, v.wy); !ok || c.chr == 0 {
v.writeCells(v.wx, v.wy, []cell{{
chr: 0,
fgColor: 0,
bgColor: 0,
}})
}
v.wx = 0
v.wy++
if v.wy >= len(v.lines) {
v.lines = append(v.lines, nil)
}
fallthrough
// not valid in every OS, but making runtime OS checks in cycle is bad.
case '\r':
if c, ok := v.readCell(v.wx, v.wy); !ok || c.chr == 0 {
v.writeCells(v.wx, v.wy, []cell{{
chr: 0,
fgColor: 0,
bgColor: 0,
}})
}
v.wx = 0
default:
moveCursor, cells := v.parseInput(r)
moveCursor, cells := v.parseInput(r, v.wx, v.wy)
if cells == nil {
continue
}
@ -666,7 +686,7 @@ func (v *View) writeString(s string) {
// parseInput parses char by char the input written to the View. It returns nil
// while processing ESC sequences. Otherwise, it returns a cell slice that
// contains the processed data.
func (v *View) parseInput(ch rune) (bool, []cell) {
func (v *View) parseInput(ch rune, x int, y int) (bool, []cell) {
cells := []cell{}
moveCursor := true
@ -698,8 +718,9 @@ func (v *View) parseInput(ch rune) (bool, []cell) {
return moveCursor, nil
} else if ch == '\t' {
// fill tab-sized space
const tabStop = 4
ch = ' '
repeatCount = 4
repeatCount = tabStop - (x % tabStop)
}
c := cell{
fgColor: v.ei.curFgColor,
@ -936,11 +957,14 @@ func (v *View) draw() error {
if y >= maxY {
break
}
x := 0
x := -v.ox
j := 0
var c cell
for {
if j < v.ox {
if x < 0 {
if j < len(vline.line) {
x += runewidth.RuneWidth(vline.line[j].chr)
}
j++
continue
}