Merge pull request #42 from liamg/tabbing

Add tabbing support
This commit is contained in:
Liam Galvin 2018-10-26 09:47:27 +01:00 committed by GitHub
commit 19cbba9936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -554,6 +554,9 @@ func (buffer *Buffer) Write(runes ...rune) {
} else if r == 0x0d { } else if r == 0x0d {
buffer.CarriageReturn() buffer.CarriageReturn()
continue continue
} else if r == 0x9 {
buffer.Tab()
continue
} }
line := buffer.getCurrentLine() line := buffer.getCurrentLine()
@ -638,6 +641,18 @@ func (buffer *Buffer) CarriageReturn() {
buffer.cursorX = 0 buffer.cursorX = 0
} }
func (buffer *Buffer) Tab() {
defer buffer.emitDisplayChange()
tabSize := 4
shift := int(buffer.cursorX) % tabSize
if shift == 0 {
shift = tabSize
}
for i := 0; i < shift; i++ {
buffer.Write(' ')
}
}
func (buffer *Buffer) NewLine() { func (buffer *Buffer) NewLine() {
defer buffer.emitDisplayChange() defer buffer.emitDisplayChange()