mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
More work on Go VT parser
This commit is contained in:
parent
e314755e4b
commit
54a42b564e
1 changed files with 16 additions and 10 deletions
|
|
@ -6,21 +6,26 @@ import (
|
|||
|
||||
var _ = fmt.Print
|
||||
|
||||
const extra_capacity uint = 4
|
||||
|
||||
type LineBuf struct {
|
||||
cells []Cell
|
||||
attrs []LineAttrs
|
||||
line_map []uint
|
||||
xnum, ynum uint
|
||||
cells []Cell
|
||||
attrs []LineAttrs
|
||||
line_map, scratch []uint
|
||||
xnum, ynum uint
|
||||
}
|
||||
|
||||
func NewLineBuf(xnum, ynum uint) *LineBuf {
|
||||
lm := make([]uint, ynum, ynum)
|
||||
lm := make([]uint, ynum, ynum+extra_capacity)
|
||||
var i uint
|
||||
for i = 0; i < ynum; i++ {
|
||||
lm[i] = i
|
||||
}
|
||||
return &LineBuf{
|
||||
cells: make([]Cell, xnum*ynum, xnum*ynum), attrs: make([]LineAttrs, ynum, ynum), xnum: xnum, ynum: ynum, line_map: lm,
|
||||
cells: make([]Cell, xnum*ynum, xnum*(ynum+extra_capacity)),
|
||||
attrs: make([]LineAttrs, len(lm), cap(lm)),
|
||||
scratch: make([]uint, len(lm), cap(lm)),
|
||||
xnum: xnum, ynum: ynum, line_map: lm,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,11 +37,11 @@ func (self *LineBuf) Line(y uint) Line {
|
|||
func (self *LineBuf) AddLines(n uint) {
|
||||
ynum := self.ynum + n
|
||||
if uint(cap(self.line_map)) >= ynum {
|
||||
self.line_map = self.line_map[:ynum]
|
||||
self.attrs = self.attrs[:ynum]
|
||||
self.cells = self.cells[:ynum*self.xnum]
|
||||
self.line_map = self.line_map[0:ynum:cap(self.line_map)]
|
||||
self.scratch = self.scratch[0:ynum:cap(self.scratch)]
|
||||
self.attrs = self.attrs[0:ynum:cap(self.attrs)]
|
||||
self.cells = self.cells[0 : ynum*self.xnum : cap(self.cells)]
|
||||
} else {
|
||||
const extra_capacity uint = 2
|
||||
newattrs := make([]LineAttrs, ynum, ynum+extra_capacity)
|
||||
copy(newattrs, self.attrs)
|
||||
newlinemap := make([]uint, ynum, ynum+extra_capacity)
|
||||
|
|
@ -49,6 +54,7 @@ func (self *LineBuf) AddLines(n uint) {
|
|||
self.attrs = newattrs
|
||||
self.line_map = newlinemap
|
||||
self.cells = newcells
|
||||
self.scratch = make([]uint, len(self.line_map), cap(self.line_map))
|
||||
}
|
||||
self.ynum = ynum
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue