diff --git a/buffer/buffer.go b/buffer/buffer.go index 9065ecb..dcfcc07 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -27,6 +27,7 @@ type Buffer struct { selectionComplete bool // whether the selected text can update or whether it is final selectionExpanded bool // whether the selection to word expansion has already run on this point selectionClickTime time.Time + defaultCell Cell } type Position struct { @@ -37,11 +38,12 @@ type Position struct { // NewBuffer creates a new terminal buffer func NewBuffer(viewCols uint16, viewLines uint16, attr CellAttributes) *Buffer { b := &Buffer{ - cursorX: 0, - cursorY: 0, - lines: []Line{}, - cursorAttr: attr, - autoWrap: true, + cursorX: 0, + cursorY: 0, + lines: []Line{}, + cursorAttr: attr, + autoWrap: true, + defaultCell: Cell{attr: attr}, } b.SetVerticalMargins(0, uint(viewLines-1)) b.ResizeView(viewCols, viewLines) @@ -511,8 +513,7 @@ func (buffer *Buffer) InsertBlankCharacters(count int) { index := int(buffer.RawLine()) for i := 0; i < count; i++ { cells := buffer.lines[index].cells - c := Cell{} - buffer.lines[index].cells = append(cells[:buffer.cursorX], append([]Cell{c}, cells[buffer.cursorX:]...)...) + buffer.lines[index].cells = append(cells[:buffer.cursorX], append([]Cell{buffer.defaultCell}, cells[buffer.cursorX:]...)...) } } @@ -624,7 +625,7 @@ func (buffer *Buffer) Write(runes ...rune) { } for int(buffer.CursorColumn()) >= len(line.cells) { - line.cells = append(line.cells, Cell{}) + line.cells = append(line.cells, buffer.defaultCell) } line.cells[buffer.cursorX].attr = buffer.cursorAttr line.cells[buffer.cursorX].setRune(r) @@ -655,7 +656,7 @@ func (buffer *Buffer) Write(runes ...rune) { } else { for int(buffer.CursorColumn()) >= len(line.cells) { - line.cells = append(line.cells, Cell{}) + line.cells = append(line.cells, buffer.defaultCell) } cell := &line.cells[buffer.CursorColumn()] diff --git a/gui/gui.go b/gui/gui.go index 328c497..a1a1a68 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -6,6 +6,7 @@ import ( "runtime" "strconv" "strings" + "sync" "time" "github.com/go-gl/gl/all-core/gl" @@ -33,6 +34,7 @@ type GUI struct { terminalAlpha float32 showDebugInfo bool keyboardShortcuts map[config.UserAction]*config.KeyCombination + resizeLock *sync.Mutex } func New(config *config.Config, terminal *terminal.Terminal, logger *zap.SugaredLogger) (*GUI, error) { @@ -51,6 +53,7 @@ func New(config *config.Config, terminal *terminal.Terminal, logger *zap.Sugared fontScale: 14.0, terminalAlpha: 1, keyboardShortcuts: shortcuts, + resizeLock: &sync.Mutex{}, }, nil } @@ -65,6 +68,9 @@ func (gui *GUI) scale() float32 { // can only be called on OS thread func (gui *GUI) resize(w *glfw.Window, width int, height int) { + gui.resizeLock.Lock() + defer gui.resizeLock.Unlock() + gui.logger.Debugf("Initiating GUI resize to %dx%d", width, height) gui.width = width