fix resize

This commit is contained in:
Liam Galvin 2018-12-03 09:02:06 +00:00
parent c4389a87e4
commit fd71169b63
2 changed files with 16 additions and 9 deletions

View File

@ -27,6 +27,7 @@ type Buffer struct {
selectionComplete bool // whether the selected text can update or whether it is final 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 selectionExpanded bool // whether the selection to word expansion has already run on this point
selectionClickTime time.Time selectionClickTime time.Time
defaultCell Cell
} }
type Position struct { type Position struct {
@ -37,11 +38,12 @@ type Position struct {
// NewBuffer creates a new terminal buffer // NewBuffer creates a new terminal buffer
func NewBuffer(viewCols uint16, viewLines uint16, attr CellAttributes) *Buffer { func NewBuffer(viewCols uint16, viewLines uint16, attr CellAttributes) *Buffer {
b := &Buffer{ b := &Buffer{
cursorX: 0, cursorX: 0,
cursorY: 0, cursorY: 0,
lines: []Line{}, lines: []Line{},
cursorAttr: attr, cursorAttr: attr,
autoWrap: true, autoWrap: true,
defaultCell: Cell{attr: attr},
} }
b.SetVerticalMargins(0, uint(viewLines-1)) b.SetVerticalMargins(0, uint(viewLines-1))
b.ResizeView(viewCols, viewLines) b.ResizeView(viewCols, viewLines)
@ -511,8 +513,7 @@ func (buffer *Buffer) InsertBlankCharacters(count int) {
index := int(buffer.RawLine()) index := int(buffer.RawLine())
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
cells := buffer.lines[index].cells cells := buffer.lines[index].cells
c := Cell{} buffer.lines[index].cells = append(cells[:buffer.cursorX], append([]Cell{buffer.defaultCell}, cells[buffer.cursorX:]...)...)
buffer.lines[index].cells = append(cells[:buffer.cursorX], append([]Cell{c}, cells[buffer.cursorX:]...)...)
} }
} }
@ -624,7 +625,7 @@ func (buffer *Buffer) Write(runes ...rune) {
} }
for int(buffer.CursorColumn()) >= len(line.cells) { 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].attr = buffer.cursorAttr
line.cells[buffer.cursorX].setRune(r) line.cells[buffer.cursorX].setRune(r)
@ -655,7 +656,7 @@ func (buffer *Buffer) Write(runes ...rune) {
} else { } else {
for int(buffer.CursorColumn()) >= len(line.cells) { 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()] cell := &line.cells[buffer.CursorColumn()]

View File

@ -6,6 +6,7 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"github.com/go-gl/gl/all-core/gl" "github.com/go-gl/gl/all-core/gl"
@ -33,6 +34,7 @@ type GUI struct {
terminalAlpha float32 terminalAlpha float32
showDebugInfo bool showDebugInfo bool
keyboardShortcuts map[config.UserAction]*config.KeyCombination keyboardShortcuts map[config.UserAction]*config.KeyCombination
resizeLock *sync.Mutex
} }
func New(config *config.Config, terminal *terminal.Terminal, logger *zap.SugaredLogger) (*GUI, error) { 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, fontScale: 14.0,
terminalAlpha: 1, terminalAlpha: 1,
keyboardShortcuts: shortcuts, keyboardShortcuts: shortcuts,
resizeLock: &sync.Mutex{},
}, nil }, nil
} }
@ -65,6 +68,9 @@ func (gui *GUI) scale() float32 {
// can only be called on OS thread // can only be called on OS thread
func (gui *GUI) resize(w *glfw.Window, width int, height int) { 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.logger.Debugf("Initiating GUI resize to %dx%d", width, height)
gui.width = width gui.width = width