fixed top

This commit is contained in:
Liam Galvin 2018-07-04 22:31:52 +01:00
parent 006e6d53ea
commit 702811507e
5 changed files with 9854 additions and 19 deletions

View File

@ -52,6 +52,7 @@ func (cell *Cell) SetRune(r rune) {
return return
} }
if cell.text != nil { if cell.text != nil {
cell.text.SetColor(mgl32.Vec3{cell.fgColour[0], cell.fgColour[1], cell.fgColour[2]})
if r == '%' { if r == '%' {
cell.text.SetString("%%") cell.text.SetString("%%")
} else { } else {
@ -64,7 +65,6 @@ func (cell *Cell) SetRune(r rune) {
func (cell *Cell) SetFgColour(r, g, b float32) { func (cell *Cell) SetFgColour(r, g, b float32) {
if cell.text != nil && (cell.fgColour[0] != r || cell.fgColour[1] != g || cell.fgColour[2] != b) { if cell.text != nil && (cell.fgColour[0] != r || cell.fgColour[1] != g || cell.fgColour[2] != b) {
cell.fgColour = [3]float32{r, g, b} cell.fgColour = [3]float32{r, g, b}
cell.text.SetColor(mgl32.Vec3{r, g, b})
} }
} }
@ -75,7 +75,7 @@ func (cell *Cell) SetBgColour(r float32, g float32, b float32) {
} }
cell.bgColour = [3]float32{r, g, b} cell.bgColour = [3]float32{r, g, b}
cell.Clean() //cell.Clean()
cell.makeVao() cell.makeVao()
} }

View File

@ -112,7 +112,6 @@ func (gui *GUI) updateTexts() {
} }
gui.cells[row][col].SetFgColour(c.GetFgColour()) gui.cells[row][col].SetFgColour(c.GetFgColour())
gui.cells[row][col].SetBgColour(c.GetBgColour())
gui.cells[row][col].SetRune(c.GetRune()) gui.cells[row][col].SetRune(c.GetRune())
gui.cells[row][col].Show() gui.cells[row][col].Show()
@ -122,6 +121,8 @@ func (gui *GUI) updateTexts() {
gui.config.ColourScheme.Cursor[1], gui.config.ColourScheme.Cursor[1],
gui.config.ColourScheme.Cursor[2], gui.config.ColourScheme.Cursor[2],
) )
} else {
gui.cells[row][col].SetBgColour(c.GetBgColour())
} }
} }
} }

View File

@ -1,6 +1,7 @@
package terminal package terminal
import ( import (
"fmt"
"strconv" "strconv"
"strings" "strings"
) )
@ -20,7 +21,10 @@ func (terminal *Terminal) processInput(buffer chan rune) {
// https://en.wikipedia.org/wiki/ANSI_escape_code // https://en.wikipedia.org/wiki/ANSI_escape_code
lineOverflow := false
for { for {
b := <-buffer b := <-buffer
if b == 0x1b { // if the byte is an escape character, read the next byte to determine which one if b == 0x1b { // if the byte is an escape character, read the next byte to determine which one
@ -201,7 +205,7 @@ func (terminal *Terminal) processInput(buffer chan rune) {
if line != nil { if line != nil {
for i := 0; i <= terminal.position.Col; i++ { for i := 0; i <= terminal.position.Col; i++ {
if i < len(line.Cells) { if i < len(line.Cells) {
line.Cells[i].r = ' ' line.Cells[i].r = 0
} }
} }
} }
@ -244,7 +248,7 @@ func (terminal *Terminal) processInput(buffer chan rune) {
if line != nil { if line != nil {
for i := 0; i <= terminal.position.Col; i++ { for i := 0; i <= terminal.position.Col; i++ {
if i < len(line.Cells) { if i < len(line.Cells) {
line.Cells[i].r = ' ' line.Cells[i].r = 0
} }
} }
} }
@ -361,7 +365,7 @@ func (terminal *Terminal) processInput(buffer chan rune) {
terminal.logger.Errorf("Unknown SGR control sequence: (ESC[%s%s%s)", param, intermediate, string(final)) terminal.logger.Errorf("Unknown SGR control sequence: (ESC[%s%s%s)", param, intermediate, string(final))
} }
terminal.logger.Debugf("SGR control sequence: (ESC[%s%s%s)", param, intermediate, string(final)) //terminal.logger.Debugf("SGR control sequence: (ESC[%s%s%s)", param, intermediate, string(final))
} }
default: default:
@ -439,11 +443,36 @@ func (terminal *Terminal) processInput(buffer chan rune) {
// numeric char selection @todo // numeric char selection @todo
case '=': case '=':
//alternate char selection @todo //alternate char selection @todo
case '?':
pm := ""
for {
b = <-buffer
switch b {
case 'h':
switch pm {
default:
terminal.logger.Errorf("Unknown private code ESC?%sh", pm)
}
case 'l':
switch pm {
default:
terminal.logger.Errorf("Unknown private code ESC?%sl", pm)
}
default:
pm += string(b)
}
}
default: default:
terminal.logger.Errorf("Unknown control sequence: 0x%02X [%s]", b, string(b)) terminal.logger.Errorf("Unknown control sequence: 0x%02X [%s]", b, string(b))
} }
} else { } else {
fmt.Printf("%s", string(b))
if b != 0x0d {
lineOverflow = false
}
switch b { switch b {
case 0x0a: case 0x0a:
@ -455,7 +484,13 @@ func (terminal *Terminal) processInput(buffer chan rune) {
} }
case 0x0d: case 0x0d:
if terminal.position.Col == 0 && terminal.position.Line > 0 && lineOverflow {
terminal.position.Line--
terminal.logger.Debugf("Swallowing forced new line for CR")
lineOverflow = false
}
terminal.position.Col = 0 terminal.position.Col = 0
case 0x08: case 0x08:
// backspace // backspace
terminal.position.Col-- terminal.position.Col--
@ -469,6 +504,7 @@ func (terminal *Terminal) processInput(buffer chan rune) {
// fmt.Printf("%s\n", string([]byte{b})) // fmt.Printf("%s\n", string([]byte{b}))
if b >= 0x20 { if b >= 0x20 {
terminal.writeRune(b) terminal.writeRune(b)
lineOverflow = terminal.position.Col == 0
} else { } else {
terminal.logger.Error("Non-readable rune received: 0x%X", b) terminal.logger.Error("Non-readable rune received: 0x%X", b)
} }

View File

@ -142,16 +142,7 @@ func (terminal *Terminal) hideCursor() {
func (terminal *Terminal) incrementPosition() { func (terminal *Terminal) incrementPosition() {
position := terminal.getPosition() position := terminal.getPosition()
if position.Col+1 >= int(terminal.size.Width) { position.Col++
position.Line++
_, h := terminal.GetSize()
if position.Line >= h {
position.Line--
}
position.Col = 0
} else {
position.Col++
}
terminal.SetPosition(position) terminal.SetPosition(position)
} }
@ -206,7 +197,20 @@ func (terminal *Terminal) Read() error {
} }
func (terminal *Terminal) writeRune(r rune) { func (terminal *Terminal) writeRune(r rune) {
terminal.setRuneAtPos(terminal.position, r) w, h := terminal.GetSize()
wrap := false
if terminal.position.Col >= w {
terminal.position.Col = 0
terminal.position.Line++
wrap = true
for terminal.position.Line >= h {
terminal.position.Line--
line := NewLine()
line.wrapped = true
terminal.lines = append(terminal.lines, line)
}
}
terminal.setRuneAtPos(terminal.position, r, wrap)
terminal.incrementPosition() terminal.incrementPosition()
} }
@ -241,7 +245,7 @@ func (terminal *Terminal) GetCellAtPos(pos Position) (*Cell, error) {
return &line.Cells[pos.Col], nil return &line.Cells[pos.Col], nil
} }
func (terminal *Terminal) setRuneAtPos(pos Position, r rune) error { func (terminal *Terminal) setRuneAtPos(pos Position, r rune, wrap bool) error {
if int(terminal.size.Width) <= pos.Col { if int(terminal.size.Width) <= pos.Col {
terminal.logger.Errorf("Col %d does not exist", pos.Col) terminal.logger.Errorf("Col %d does not exist", pos.Col)
@ -249,7 +253,9 @@ func (terminal *Terminal) setRuneAtPos(pos Position, r rune) error {
} }
for terminal.position.Line >= len(terminal.lines) { for terminal.position.Line >= len(terminal.lines) {
terminal.lines = append(terminal.lines, NewLine()) nl := NewLine()
nl.wrapped = wrap
terminal.lines = append(terminal.lines, nl)
} }
line := terminal.getBufferedLine(pos.Line) line := terminal.getBufferedLine(pos.Line)

9792
top.log Normal file

File diff suppressed because it is too large Load Diff