fix background renderinf

This commit is contained in:
Liam Galvin 2018-09-01 21:19:13 +01:00
parent f0a1742c0a
commit be60c1d053
6 changed files with 22 additions and 24 deletions

View File

@ -227,7 +227,7 @@ func (buffer *Buffer) Write(runes ...rune) {
} else {
for int(buffer.CursorColumn()) >= len(line.cells) {
line.cells = append(line.cells, newCell())
line.cells = append(line.cells, NewBackgroundCell(buffer.cursorAttr.BgColour))
}
cell := &line.cells[buffer.CursorColumn()]
@ -383,14 +383,15 @@ func (buffer *Buffer) EraseLineFromCursor() {
defer buffer.emitDisplayChange()
line := buffer.getCurrentLine()
max := int(buffer.cursorX)
if max > len(line.cells) {
max = len(line.cells)
}
line.cells = line.cells[:buffer.cursorX]
for c := int(buffer.cursorX); c < len(line.cells); c++ {
line.cells[c].erase()
max := int(buffer.ViewWidth()) - len(line.cells)
buffer.SaveCursor()
for i := 0; i < max; i++ {
buffer.Write(0)
}
buffer.RestoreCursor()
}
func (buffer *Buffer) EraseDisplay() {

View File

@ -289,8 +289,6 @@ func TestGetCellWithBadCursor(t *testing.T) {
b := NewBuffer(80, 2, CellAttributes{})
b.Write([]rune("Hello\r\nthere\r\nsomething...")...)
require.Nil(t, b.GetCell(8, 3))
require.Nil(t, b.GetCell(8, -1))
require.Nil(t, b.GetCell(-8, 1))
require.Nil(t, b.GetCell(90, 0))
}
@ -365,7 +363,7 @@ func TestEraseLineAfterCursor(t *testing.T) {
b.MovePosition(-3, 0)
b.EraseLineFromCursor()
assert.Equal(t, "hello, this is a test", b.lines[0].String())
assert.Equal(t, "dele\x00\x00\x00", b.lines[1].String())
assert.Equal(t, "dele", b.lines[1].String())
}
func TestEraseDisplay(t *testing.T) {
b := NewBuffer(80, 5, CellAttributes{})
@ -404,9 +402,9 @@ func TestBackspace(t *testing.T) {
b.Write([]rune("hello")...)
b.Backspace()
b.Backspace()
b.Write([]rune("l")...)
b.Write([]rune("p")...)
lines := b.GetVisibleLines()
assert.Equal(t, "hell\x00", lines[0].String())
assert.Equal(t, "helpo", lines[0].String())
}
func TestBackspaceWithWrap(t *testing.T) {
@ -424,7 +422,7 @@ func TestBackspaceWithWrap(t *testing.T) {
b.Backspace()
b.EraseLineFromCursor()
lines := b.GetVisibleLines()
assert.Equal(t, "hello\x00\x00\x00\x00\x00", lines[0].String())
assert.Equal(t, "hello", lines[0].String())
}
func TestHorizontalResizeView(t *testing.T) {

View File

@ -16,10 +16,6 @@ type CellAttributes struct {
Hidden bool
}
func newCell() Cell {
return Cell{}
}
func (cell *Cell) Attr() CellAttributes {
return cell.attr
}

View File

@ -1,5 +1,9 @@
package buffer
import (
"strings"
)
type Line struct {
wrapped bool // whether line was wrapped onto from the previous one
cells []Cell
@ -40,7 +44,7 @@ func (line *Line) String() string {
for _, cell := range line.cells {
runes = append(runes, cell.r)
}
return string(runes)
return strings.TrimRight(string(runes), "\x00 ")
}
// @todo test these (ported from legacy) ------------------

View File

@ -219,9 +219,9 @@ func (gui *GUI) Render() error {
cells := lines[y].Cells()
if x < len(cells) {
cell = cells[x]
if cell.Rune() == 0 {
cell = defaultCell
}
//if cell.Rune() == 0 {
// cell = defaultCell
//}
}
}
@ -240,7 +240,7 @@ func (gui *GUI) Render() error {
if x < len(cells) {
cell = cells[x]
if cell.Rune() == 0 {
cell = defaultCell
continue
}
}
}

View File

@ -215,7 +215,6 @@ func (r *OpenGLRenderer) DrawCellBg(cell buffer.Cell, col uint, row uint) {
rect.setColour(bg)
rect.Draw()
}
}
func (r *OpenGLRenderer) DrawCellText(cell buffer.Cell, col uint, row uint) {