Merge pull request #104 from liamg/fix-resize

Fix resize
This commit is contained in:
Liam Galvin 2018-12-03 09:09:59 +00:00 committed by GitHub
commit adee2d2284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
selectionExpanded bool // whether the selection to word expansion has already run on this point
selectionClickTime time.Time
defaultCell Cell
}
type Position struct {
@ -42,6 +43,7 @@ func NewBuffer(viewCols uint16, viewLines uint16, attr CellAttributes) *Buffer {
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()]

View File

@ -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