mirror of https://github.com/liamg/aminal.git
Buffer fix (#201)
* bug fix: Save/Restore Cursor mess + some refactoring * typo fix
This commit is contained in:
parent
1ca1b7c246
commit
bc1b3f0dfd
|
@ -10,6 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SelectionMode int
|
type SelectionMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SelectionChar SelectionMode = iota // char-by-char selection
|
SelectionChar SelectionMode = iota // char-by-char selection
|
||||||
SelectionWord SelectionMode = iota // by word selection
|
SelectionWord SelectionMode = iota // by word selection
|
||||||
|
@ -665,7 +666,7 @@ func (buffer *Buffer) Write(runes ...rune) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for int(buffer.CursorColumn()) >= len(line.cells) {
|
for int(buffer.CursorColumn()) >= len(line.cells) {
|
||||||
line.cells = append(line.cells, buffer.terminalState.DefaultCell(int(buffer.CursorColumn()) == len(line.cells)))
|
line.Append(buffer.terminalState.DefaultCell(int(buffer.CursorColumn()) == len(line.cells)))
|
||||||
}
|
}
|
||||||
line.cells[buffer.terminalState.cursorX].attr = buffer.terminalState.CursorAttr
|
line.cells[buffer.terminalState.cursorX].attr = buffer.terminalState.CursorAttr
|
||||||
line.cells[buffer.terminalState.cursorX].setRune(r)
|
line.cells[buffer.terminalState.cursorX].setRune(r)
|
||||||
|
@ -681,7 +682,7 @@ func (buffer *Buffer) Write(runes ...rune) {
|
||||||
|
|
||||||
newLine := buffer.getCurrentLine()
|
newLine := buffer.getCurrentLine()
|
||||||
if len(newLine.cells) == 0 {
|
if len(newLine.cells) == 0 {
|
||||||
newLine.cells = append(newLine.cells, buffer.terminalState.DefaultCell(true))
|
newLine.Append(buffer.terminalState.DefaultCell(true))
|
||||||
}
|
}
|
||||||
cell := &newLine.cells[0]
|
cell := &newLine.cells[0]
|
||||||
cell.setRune(r)
|
cell.setRune(r)
|
||||||
|
@ -696,7 +697,7 @@ func (buffer *Buffer) Write(runes ...rune) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
for int(buffer.CursorColumn()) >= len(line.cells) {
|
for int(buffer.CursorColumn()) >= len(line.cells) {
|
||||||
line.cells = append(line.cells, buffer.terminalState.DefaultCell(int(buffer.CursorColumn()) == len(line.cells)))
|
line.Append(buffer.terminalState.DefaultCell(int(buffer.CursorColumn()) == len(line.cells)))
|
||||||
}
|
}
|
||||||
|
|
||||||
cell := &line.cells[buffer.CursorColumn()]
|
cell := &line.cells[buffer.CursorColumn()]
|
||||||
|
@ -909,14 +910,12 @@ func (buffer *Buffer) EraseLineFromCursor() {
|
||||||
line.cells = line.cells[:buffer.terminalState.cursorX]
|
line.cells = line.cells[:buffer.terminalState.cursorX]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
max := int(buffer.ViewWidth()) - len(line.cells)
|
max := int(buffer.ViewWidth()) - len(line.cells)
|
||||||
|
|
||||||
buffer.SaveCursor()
|
|
||||||
for i := 0; i < max; i++ {
|
for i := 0; i < max; i++ {
|
||||||
buffer.Write(0)
|
line.Append(buffer.terminalState.DefaultCell(true))
|
||||||
}
|
}
|
||||||
buffer.RestoreCursor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buffer *Buffer) EraseDisplay() {
|
func (buffer *Buffer) EraseDisplay() {
|
||||||
|
@ -969,13 +968,11 @@ func (buffer *Buffer) EraseDisplayFromCursor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
line.cells = line.cells[:max]
|
line.cells = line.cells[:max]
|
||||||
for i := buffer.terminalState.cursorY + 1; i < buffer.ViewHeight(); i++ {
|
|
||||||
rawLine := buffer.convertViewLineToRawLine(i)
|
for rawLine := buffer.convertViewLineToRawLine(buffer.terminalState.cursorY) + 1; int(rawLine) < len(buffer.lines); rawLine++ {
|
||||||
if int(rawLine) < len(buffer.lines) {
|
|
||||||
buffer.lines[int(rawLine)].cells = []Cell{}
|
buffer.lines[int(rawLine)].cells = []Cell{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (buffer *Buffer) EraseDisplayToCursor() {
|
func (buffer *Buffer) EraseDisplayToCursor() {
|
||||||
defer buffer.emitDisplayChange()
|
defer buffer.emitDisplayChange()
|
||||||
|
@ -1061,7 +1058,7 @@ func (buffer *Buffer) ResizeView(width uint16, height uint16) {
|
||||||
if moveCount > len(nextLine.cells) {
|
if moveCount > len(nextLine.cells) {
|
||||||
moveCount = len(nextLine.cells)
|
moveCount = len(nextLine.cells)
|
||||||
}
|
}
|
||||||
line.cells = append(line.cells, nextLine.cells[:moveCount]...)
|
line.Append(nextLine.cells[:moveCount]...)
|
||||||
if moveCount == len(nextLine.cells) {
|
if moveCount == len(nextLine.cells) {
|
||||||
|
|
||||||
if i+offset <= int(buffer.terminalState.cursorY) {
|
if i+offset <= int(buffer.terminalState.cursorY) {
|
||||||
|
|
|
@ -75,4 +75,8 @@ func (line *Line) CutCellsFromEnd(n int) []Cell {
|
||||||
return cut
|
return cut
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (line *Line) Append(cells ...Cell) {
|
||||||
|
line.cells = append(line.cells, cells...)
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
|
|
|
@ -37,7 +37,7 @@ var csiSequences = []csiMapping{
|
||||||
{id: 'D', handler: csiCursorBackwardHandler, description: "Cursor Backward Ps Times (default = 1) (CUB)"},
|
{id: 'D', handler: csiCursorBackwardHandler, description: "Cursor Backward Ps Times (default = 1) (CUB)"},
|
||||||
{id: 'E', handler: csiCursorNextLineHandler, description: "Cursor Next Line Ps Times (default = 1) (CNL)"},
|
{id: 'E', handler: csiCursorNextLineHandler, description: "Cursor Next Line Ps Times (default = 1) (CNL)"},
|
||||||
{id: 'F', handler: csiCursorPrecedingLineHandler, description: "Cursor Preceding Line Ps Times (default = 1) (CPL)"},
|
{id: 'F', handler: csiCursorPrecedingLineHandler, description: "Cursor Preceding Line Ps Times (default = 1) (CPL)"},
|
||||||
{id: 'G', handler: csiCursorCharacterAbsoluteHandler, description: "Cursor Character Absolute [column] (default = [row,1]) (CHA)"},
|
{id: 'G', handler: csiCursorCharacterAbsoluteHandler, description: "Cursor Horizontal Absolute [column] (default = [row,1]) (CHA)"},
|
||||||
{id: 'H', handler: csiCursorPositionHandler, description: "Cursor Position [row;column] (default = [1,1]) (CUP)"},
|
{id: 'H', handler: csiCursorPositionHandler, description: "Cursor Position [row;column] (default = [1,1]) (CUP)"},
|
||||||
{id: 'J', handler: csiEraseInDisplayHandler, description: "Erase in Display (ED), VT100"},
|
{id: 'J', handler: csiEraseInDisplayHandler, description: "Erase in Display (ED), VT100"},
|
||||||
{id: 'K', handler: csiEraseInLineHandler, description: "Erase in Line (EL), VT100"},
|
{id: 'K', handler: csiEraseInLineHandler, description: "Erase in Line (EL), VT100"},
|
||||||
|
|
Loading…
Reference in New Issue