Skip to content

Commit

Permalink
more efficient text rendering and streamlining of output handling
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg committed Dec 1, 2018
1 parent 1a932fa commit 177e928
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 268 deletions.
6 changes: 0 additions & 6 deletions Makefile
Expand Up @@ -22,12 +22,6 @@ install-tools:
which dep || curl -L https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
which packr || go get -u github.com/gobuffalo/packr/packr

.PHONY: update-fonts
update-fonts: install-tools
curl -L https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Hack/Regular/complete/Hack%20Regular%20Nerd%20Font%20Complete.ttf -o "${FONTPATH}/Hack Regular Nerd Font Complete.ttf"
curl -L https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Hack/Bold/complete/Hack%20Bold%20Nerd%20Font%20Complete.ttf -o "${FONTPATH}/Hack Bold Nerd Font Complete.ttf"
packr -v

.PHONY: build-linux
build-linux:
mkdir -p bin/linux
Expand Down
31 changes: 5 additions & 26 deletions buffer/buffer.go
Expand Up @@ -610,20 +610,10 @@ func (buffer *Buffer) ReverseIndex() {
func (buffer *Buffer) Write(runes ...rune) {

// scroll to bottom on input
inc := true
buffer.scrollLinesFromBottom = 0

for _, r := range runes {
if r == 0x0a {
buffer.NewLine()
continue
} else if r == 0x0d {
buffer.CarriageReturn()
continue
} else if r == 0x9 {
buffer.Tab()
continue
}

line := buffer.getCurrentLine()

if buffer.replaceMode {
Expand All @@ -634,7 +624,7 @@ func (buffer *Buffer) Write(runes ...rune) {
}

for int(buffer.CursorColumn()) >= len(line.cells) {
line.cells = append(line.cells, NewBackgroundCell(buffer.cursorAttr.BgColour))
line.cells = append(line.cells, Cell{})
}
line.cells[buffer.cursorX].attr = buffer.cursorAttr
line.cells[buffer.cursorX].setRune(r)
Expand Down Expand Up @@ -665,31 +655,23 @@ func (buffer *Buffer) Write(runes ...rune) {
} else {

for int(buffer.CursorColumn()) >= len(line.cells) {
line.cells = append(line.cells, NewBackgroundCell(buffer.cursorAttr.BgColour))
line.cells = append(line.cells, Cell{})
}

cell := &line.cells[buffer.CursorColumn()]
cell.setRune(r)
cell.attr = buffer.cursorAttr

}

if inc {
buffer.incrementCursorPosition()
}
buffer.incrementCursorPosition()
}
}

func (buffer *Buffer) incrementCursorPosition() {

defer buffer.emitDisplayChange()

// we can increment one column past the end of the line.
// this is effectively the beginning of the next line, except when we \r etc.
if buffer.CursorColumn() < buffer.Width() { // if not at end of line

if buffer.CursorColumn() < buffer.Width() {
buffer.cursorX++

}
}

Expand All @@ -708,7 +690,6 @@ func (buffer *Buffer) Backspace() {
}

func (buffer *Buffer) CarriageReturn() {
defer buffer.emitDisplayChange()

for {
line := buffer.getCurrentLine()
Expand All @@ -726,7 +707,6 @@ func (buffer *Buffer) CarriageReturn() {
}

func (buffer *Buffer) Tab() {
defer buffer.emitDisplayChange()
tabSize := 4
shift := int(buffer.cursorX-1) % tabSize
if shift == 0 {
Expand All @@ -738,7 +718,6 @@ func (buffer *Buffer) Tab() {
}

func (buffer *Buffer) NewLine() {
defer buffer.emitDisplayChange()

buffer.cursorX = 0
buffer.Index()
Expand Down

0 comments on commit 177e928

Please sign in to comment.