mirror of https://github.com/liamg/aminal.git
fix tabbing
This commit is contained in:
parent
adee2d2284
commit
03fd345079
|
@ -709,10 +709,7 @@ func (buffer *Buffer) CarriageReturn() {
|
|||
|
||||
func (buffer *Buffer) Tab() {
|
||||
tabSize := 4
|
||||
shift := int(buffer.cursorX-1) % tabSize
|
||||
if shift == 0 {
|
||||
shift = tabSize
|
||||
}
|
||||
shift := tabSize - (int(buffer.cursorX+1) % tabSize)
|
||||
for i := 0; i < shift; i++ {
|
||||
buffer.Write(' ')
|
||||
}
|
||||
|
|
|
@ -9,6 +9,35 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTabbing(t *testing.T) {
|
||||
b := NewBuffer(30, 3, CellAttributes{})
|
||||
b.Write([]rune("hello")...)
|
||||
b.Tab()
|
||||
b.Write([]rune("x")...)
|
||||
b.Tab()
|
||||
b.Write([]rune("goodbye")...)
|
||||
b.CarriageReturn()
|
||||
b.NewLine()
|
||||
b.Write([]rune("hell")...)
|
||||
b.Tab()
|
||||
b.Write([]rune("xxx")...)
|
||||
b.Tab()
|
||||
b.Write([]rune("good")...)
|
||||
b.CarriageReturn()
|
||||
b.NewLine()
|
||||
expected := `
|
||||
hello x goodbye
|
||||
hell xxx good
|
||||
`
|
||||
|
||||
lines := b.GetVisibleLines()
|
||||
strs := []string{}
|
||||
for _, l := range lines {
|
||||
strs = append(strs, l.String())
|
||||
}
|
||||
require.Equal(t, strings.TrimSpace(expected), strings.Join(strs, "\n"))
|
||||
}
|
||||
|
||||
func TestOffsets(t *testing.T) {
|
||||
b := NewBuffer(10, 3, CellAttributes{})
|
||||
b.Write([]rune("hello")...)
|
||||
|
|
Loading…
Reference in New Issue