mirror of https://github.com/liamg/aminal.git
more CSI h/l
This commit is contained in:
parent
d757d2a543
commit
9e7b1798a2
|
@ -17,6 +17,8 @@ type Buffer struct {
|
||||||
scrollLinesFromBottom uint
|
scrollLinesFromBottom uint
|
||||||
topMargin uint // see DECSTBM docs - this is for scrollable regions
|
topMargin uint // see DECSTBM docs - this is for scrollable regions
|
||||||
bottomMargin uint // see DECSTBM docs - this is for scrollable regions
|
bottomMargin uint // see DECSTBM docs - this is for scrollable regions
|
||||||
|
replaceMode bool // overwrite character at cursor or insert new
|
||||||
|
autoWrap bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuffer creates a new terminal buffer
|
// NewBuffer creates a new terminal buffer
|
||||||
|
@ -26,11 +28,24 @@ func NewBuffer(viewCols uint16, viewLines uint16, attr CellAttributes) *Buffer {
|
||||||
cursorY: 0,
|
cursorY: 0,
|
||||||
lines: []Line{},
|
lines: []Line{},
|
||||||
cursorAttr: attr,
|
cursorAttr: attr,
|
||||||
|
autoWrap: true,
|
||||||
}
|
}
|
||||||
b.ResizeView(viewCols, viewLines)
|
b.ResizeView(viewCols, viewLines)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (buffer *Buffer) SetAutoWrap(enabled bool) {
|
||||||
|
buffer.autoWrap = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
func (buffer *Buffer) SetInsertMode() {
|
||||||
|
buffer.replaceMode = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (buffer *Buffer) SetReplaceMode() {
|
||||||
|
buffer.replaceMode = true
|
||||||
|
}
|
||||||
|
|
||||||
func (buffer *Buffer) SetMargins(top uint, bottom uint) {
|
func (buffer *Buffer) SetMargins(top uint, bottom uint) {
|
||||||
buffer.topMargin = top
|
buffer.topMargin = top
|
||||||
buffer.bottomMargin = bottom
|
buffer.bottomMargin = bottom
|
||||||
|
@ -170,6 +185,7 @@ func (buffer *Buffer) ViewHeight() uint16 {
|
||||||
func (buffer *Buffer) Write(runes ...rune) {
|
func (buffer *Buffer) Write(runes ...rune) {
|
||||||
|
|
||||||
// scroll to bottom on input
|
// scroll to bottom on input
|
||||||
|
inc := true
|
||||||
buffer.scrollLinesFromBottom = 0
|
buffer.scrollLinesFromBottom = 0
|
||||||
|
|
||||||
for _, r := range runes {
|
for _, r := range runes {
|
||||||
|
@ -183,28 +199,30 @@ func (buffer *Buffer) Write(runes ...rune) {
|
||||||
line := buffer.getCurrentLine()
|
line := buffer.getCurrentLine()
|
||||||
|
|
||||||
if buffer.CursorColumn() >= buffer.Width() { // if we're after the line, move to next
|
if buffer.CursorColumn() >= buffer.Width() { // if we're after the line, move to next
|
||||||
buffer.cursorX = 0
|
|
||||||
|
|
||||||
if buffer.cursorY >= buffer.ViewHeight()-1 {
|
if buffer.autoWrap {
|
||||||
buffer.lines = append(buffer.lines, newLine())
|
buffer.cursorX = 0
|
||||||
|
|
||||||
|
if buffer.cursorY >= buffer.ViewHeight()-1 {
|
||||||
|
buffer.lines = append(buffer.lines, newLine())
|
||||||
|
} else {
|
||||||
|
buffer.cursorY++
|
||||||
|
}
|
||||||
|
|
||||||
|
newLine := buffer.getCurrentLine()
|
||||||
|
newLine.setWrapped(true)
|
||||||
|
if len(newLine.cells) == 0 {
|
||||||
|
newLine.cells = []Cell{Cell{}}
|
||||||
|
}
|
||||||
|
cell := &newLine.cells[buffer.CursorColumn()]
|
||||||
|
cell.setRune(r)
|
||||||
|
cell.attr = buffer.cursorAttr
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
buffer.cursorY++
|
buffer.cursorX = buffer.Width() - 1
|
||||||
|
inc = false
|
||||||
}
|
}
|
||||||
|
|
||||||
//if int(buffer.RawLine()) >= len(buffer.lines) { // if we need to create a new line, set it to wrapped and write to it
|
|
||||||
|
|
||||||
newLine := buffer.getCurrentLine()
|
|
||||||
newLine.setWrapped(true)
|
|
||||||
if len(newLine.cells) == 0 {
|
|
||||||
newLine.cells = []Cell{Cell{}}
|
|
||||||
}
|
|
||||||
cell := &newLine.cells[buffer.CursorColumn()]
|
|
||||||
cell.setRune(r)
|
|
||||||
cell.attr = buffer.cursorAttr
|
|
||||||
//} else {
|
|
||||||
//newLine := &buffer.lines[buffer.RawLine()]
|
|
||||||
//}
|
|
||||||
|
|
||||||
// @todo if next line is wrapped then prepend to it and shuffle characters along line, wrapping to next if necessary
|
// @todo if next line is wrapped then prepend to it and shuffle characters along line, wrapping to next if necessary
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -218,7 +236,9 @@ func (buffer *Buffer) Write(runes ...rune) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.incrementCursorPosition()
|
if inc {
|
||||||
|
buffer.incrementCursorPosition()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,31 +264,14 @@ func (buffer *Buffer) Backspace() {
|
||||||
if line.wrapped {
|
if line.wrapped {
|
||||||
buffer.MovePosition(int16(buffer.Width()-1), -1)
|
buffer.MovePosition(int16(buffer.Width()-1), -1)
|
||||||
} else {
|
} else {
|
||||||
//@todo ring bell or whatever
|
//@todo ring bell or whatever - actually i think the pty will trigger this
|
||||||
fmt.Println("BELL?")
|
//fmt.Println("BELL?")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer.MovePosition(-1, 0)
|
buffer.MovePosition(-1, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buffer *Buffer) BackspaceDelete() {
|
|
||||||
|
|
||||||
if buffer.cursorX == 0 {
|
|
||||||
line := buffer.getCurrentLine()
|
|
||||||
if line.wrapped {
|
|
||||||
buffer.MovePosition(int16(buffer.Width()-1), -1)
|
|
||||||
buffer.GetCell(buffer.cursorX, buffer.cursorY).erase()
|
|
||||||
} else {
|
|
||||||
//@todo ring bell or whatever
|
|
||||||
fmt.Println("BELL?")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buffer.MovePosition(-1, 0)
|
|
||||||
buffer.GetCell(buffer.cursorX, buffer.cursorY).erase()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (buffer *Buffer) CarriageReturn() {
|
func (buffer *Buffer) CarriageReturn() {
|
||||||
defer buffer.emitDisplayChange()
|
defer buffer.emitDisplayChange()
|
||||||
buffer.cursorX = 0
|
buffer.cursorX = 0
|
||||||
|
|
|
@ -70,8 +70,18 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch modeStr {
|
switch modeStr {
|
||||||
|
case "4":
|
||||||
|
if enabled { // @todo support replace mode
|
||||||
|
terminal.ActiveBuffer().SetInsertMode()
|
||||||
|
} else {
|
||||||
|
terminal.ActiveBuffer().SetReplaceMode()
|
||||||
|
}
|
||||||
case "?1":
|
case "?1":
|
||||||
terminal.modes.ApplicationCursorKeys = enabled
|
terminal.modes.ApplicationCursorKeys = enabled
|
||||||
|
case "?7":
|
||||||
|
// auto-wrap mode
|
||||||
|
//DECAWM
|
||||||
|
terminal.ActiveBuffer().SetAutoWrap(enabled)
|
||||||
case "?9":
|
case "?9":
|
||||||
if enabled {
|
if enabled {
|
||||||
terminal.SetMouseMode(MouseModeX10)
|
terminal.SetMouseMode(MouseModeX10)
|
||||||
|
|
Loading…
Reference in New Issue