Refactoring of *View.writeRune

This commit is contained in:
Roi Martin 2017-08-18 09:21:00 +02:00
parent 2677ad0445
commit ad91aa2b83
1 changed files with 9 additions and 10 deletions

19
edit.go
View File

@ -245,25 +245,24 @@ func (v *View) writeRune(x, y int, ch rune) error {
v.lines = append(v.lines, s...)
}
c := cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: ch,
}
olen := len(v.lines[y])
var s []cell
if x >= len(v.lines[y]) {
s := make([]cell, x-len(v.lines[y])+1)
v.lines[y] = append(v.lines[y], s...)
s = make([]cell, x-len(v.lines[y])+1)
} else if !v.Overwrite {
v.lines[y] = append(v.lines[y], c)
s = make([]cell, 1)
}
v.lines[y] = append(v.lines[y], s...)
if !v.Overwrite || (v.Overwrite && x >= olen-1) {
copy(v.lines[y][x+1:], v.lines[y][x:])
}
v.lines[y][x] = c
v.lines[y][x] = cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: ch,
}
return nil
}