mirror of https://github.com/liamg/aminal.git
fix stuff
This commit is contained in:
parent
8d96db73d1
commit
d3e7784b4d
20
gui/gui.go
20
gui/gui.go
|
@ -110,7 +110,7 @@ func (gui *GUI) updateTexts() {
|
||||||
gui.cells[row][col].SetRune(c.GetRune())
|
gui.cells[row][col].SetRune(c.GetRune())
|
||||||
gui.cells[row][col].Show()
|
gui.cells[row][col].Show()
|
||||||
|
|
||||||
if gui.terminal.GetPosition().Col == col && gui.terminal.GetPosition().Line == row {
|
if gui.terminal.IsCursorVisible() && gui.terminal.GetPosition().Col == col && gui.terminal.GetPosition().Line == row {
|
||||||
gui.cells[row][col].SetBgColour(
|
gui.cells[row][col].SetBgColour(
|
||||||
gui.config.ColourScheme.Cursor[0],
|
gui.config.ColourScheme.Cursor[0],
|
||||||
gui.config.ColourScheme.Cursor[1],
|
gui.config.ColourScheme.Cursor[1],
|
||||||
|
@ -175,8 +175,8 @@ func (gui *GUI) Render() error {
|
||||||
gl.BindFragDataLocation(program, 0, gl.Str("outColour\x00"))
|
gl.BindFragDataLocation(program, 0, gl.Str("outColour\x00"))
|
||||||
|
|
||||||
gui.logger.Debugf("Loading font...")
|
gui.logger.Debugf("Loading font...")
|
||||||
if err := gui.loadFont("/usr/share/fonts/nerd-fonts-complete/ttf/Roboto Mono Nerd Font Complete.ttf", 12); err != nil {
|
//if err := gui.loadFont("/usr/share/fonts/nerd-fonts-complete/ttf/Roboto Mono Nerd Font Complete.ttf", 12); err != nil {
|
||||||
//if err := gui.loadFont("./fonts/CamingoCode-Regular.ttf", 12); err != nil {
|
if err := gui.loadFont("./fonts/Roboto.ttf", 12); err != nil {
|
||||||
return fmt.Errorf("Failed to load font: %s", err)
|
return fmt.Errorf("Failed to load font: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,17 @@ func (gui *GUI) Render() error {
|
||||||
case <-updateChan:
|
case <-updateChan:
|
||||||
updateRequired = 2
|
updateRequired = 2
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
text.SetString(fmt.Sprintf("%dx%d@%d,%d", gui.cols, gui.rows, gui.terminal.GetPosition().Col, gui.terminal.GetPosition().Line))
|
ca := gui.terminal.GetCellAttributes()
|
||||||
|
text.SetString(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"%dx%d@%d,%d reverse=%t",
|
||||||
|
gui.cols,
|
||||||
|
gui.rows,
|
||||||
|
gui.terminal.GetPosition().Col,
|
||||||
|
gui.terminal.GetPosition().Line,
|
||||||
|
ca.Reverse,
|
||||||
|
),
|
||||||
|
)
|
||||||
updateRequired = 2
|
updateRequired = 2
|
||||||
default:
|
default:
|
||||||
break CheckUpdate
|
break CheckUpdate
|
||||||
|
@ -275,7 +285,7 @@ func (gui *GUI) Render() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug to show co-ords
|
// debug to show co-ords
|
||||||
//text.Draw()
|
text.Draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
glfw.PollEvents()
|
glfw.PollEvents()
|
||||||
|
|
|
@ -34,6 +34,7 @@ func (cell *Cell) IsHidden() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cell *Cell) GetFgColour() (r float32, g float32, b float32) {
|
func (cell *Cell) GetFgColour() (r float32, g float32, b float32) {
|
||||||
|
|
||||||
if cell.attr.Reverse {
|
if cell.attr.Reverse {
|
||||||
return cell.attr.BgColour[0], cell.attr.BgColour[1], cell.attr.BgColour[2]
|
return cell.attr.BgColour[0], cell.attr.BgColour[1], cell.attr.BgColour[2]
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,7 @@ func (cell *Cell) GetFgColour() (r float32, g float32, b float32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cell *Cell) GetBgColour() (r float32, g float32, b float32) {
|
func (cell *Cell) GetBgColour() (r float32, g float32, b float32) {
|
||||||
|
|
||||||
if cell.attr.Reverse {
|
if cell.attr.Reverse {
|
||||||
return cell.attr.FgColour[0], cell.attr.FgColour[1], cell.attr.FgColour[2]
|
return cell.attr.FgColour[0], cell.attr.FgColour[1], cell.attr.FgColour[2]
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package terminal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (terminal *Terminal) processInput(buffer chan rune) {
|
func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
|
@ -16,24 +17,25 @@ func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
switch b {
|
switch b {
|
||||||
case 0x5b: // CSI: Control Sequence Introducer ]
|
case 0x5b: // CSI: Control Sequence Introducer ]
|
||||||
var final rune
|
var final rune
|
||||||
params := []string{}
|
param := ""
|
||||||
|
intermediate := ""
|
||||||
CSI:
|
CSI:
|
||||||
for {
|
for {
|
||||||
b = <-buffer
|
b = <-buffer
|
||||||
param := ""
|
|
||||||
switch true {
|
switch true {
|
||||||
case b >= 0x30 && b <= 0x3F:
|
case b >= 0x30 && b <= 0x3F:
|
||||||
param = param + string(b)
|
param = param + string(b)
|
||||||
case b >= 0x20 && b <= 0x2F:
|
case b >= 0x20 && b <= 0x2F:
|
||||||
params = append(params, param)
|
//intermediate? useful?
|
||||||
param = ""
|
intermediate += string(b)
|
||||||
case b >= 0x40 && b <= 0x7e:
|
case b >= 0x40 && b <= 0x7e:
|
||||||
params = append(params, param)
|
|
||||||
final = b
|
final = b
|
||||||
break CSI
|
break CSI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params := strings.Split(param, ";")
|
||||||
|
|
||||||
switch final {
|
switch final {
|
||||||
case 'A':
|
case 'A':
|
||||||
distance := 1
|
distance := 1
|
||||||
|
@ -156,6 +158,7 @@ func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
terminal.position.Col = x - 1
|
terminal.position.Col = x - 1
|
||||||
terminal.position.Line = y - 1
|
terminal.position.Line = y - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'J':
|
case 'J':
|
||||||
|
|
||||||
n := "0"
|
n := "0"
|
||||||
|
@ -215,7 +218,12 @@ func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
|
|
||||||
switch n {
|
switch n {
|
||||||
case "0", "":
|
case "0", "":
|
||||||
terminal.ClearToEndOfLine()
|
line := terminal.getBufferedLine(terminal.position.Line)
|
||||||
|
if line != nil {
|
||||||
|
if terminal.position.Col < len(line.Cells) {
|
||||||
|
line.Cells = line.Cells[:terminal.position.Col]
|
||||||
|
}
|
||||||
|
}
|
||||||
case "1":
|
case "1":
|
||||||
line := terminal.getBufferedLine(terminal.position.Line)
|
line := terminal.getBufferedLine(terminal.position.Line)
|
||||||
if line != nil {
|
if line != nil {
|
||||||
|
@ -231,12 +239,13 @@ func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
default:
|
default:
|
||||||
terminal.logger.Errorf("Unsupported EL: %s", n)
|
terminal.logger.Errorf("Unsupported EL: %s", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
// SGR: colour and shit
|
// SGR: colour and shit
|
||||||
for i := range params {
|
for i := range params {
|
||||||
param := params[i]
|
param := params[i]
|
||||||
switch param {
|
switch param {
|
||||||
case "0":
|
case "0", "":
|
||||||
terminal.cellAttr = terminal.defaultCellAttr
|
terminal.cellAttr = terminal.defaultCellAttr
|
||||||
case "1":
|
case "1":
|
||||||
terminal.cellAttr.Bold = true
|
terminal.cellAttr.Bold = true
|
||||||
|
@ -330,13 +339,23 @@ func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
terminal.cellAttr.BgColour = terminal.colourScheme.LightCyanBg
|
terminal.cellAttr.BgColour = terminal.colourScheme.LightCyanBg
|
||||||
case "107":
|
case "107":
|
||||||
terminal.cellAttr.BgColour = terminal.colourScheme.WhiteBg
|
terminal.cellAttr.BgColour = terminal.colourScheme.WhiteBg
|
||||||
|
default:
|
||||||
|
|
||||||
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
b = <-buffer
|
switch param + intermediate + string(final) {
|
||||||
terminal.logger.Errorf("Unknown CSI control sequence: 0x%02X (%s)", final, string(final))
|
case "?25h":
|
||||||
|
terminal.showCursor()
|
||||||
|
case "?25l":
|
||||||
|
terminal.hideCursor()
|
||||||
|
default:
|
||||||
|
terminal.logger.Errorf("Unknown CSI control sequence: 0x%02X (ESC[%s%s%s)", final, param, intermediate, string(final))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 0x5d: // OSC: Operating System Command
|
case 0x5d: // OSC: Operating System Command
|
||||||
b = <-buffer
|
b = <-buffer
|
||||||
|
@ -364,7 +383,12 @@ func (terminal *Terminal) processInput(buffer chan rune) {
|
||||||
terminal.logger.Errorf("RIS not yet supported")
|
terminal.logger.Errorf("RIS not yet supported")
|
||||||
case rune(')'), rune('('):
|
case rune(')'), rune('('):
|
||||||
b = <-buffer
|
b = <-buffer
|
||||||
terminal.logger.Debugf("Ignoring character set control code )%s", string(b))
|
// todo charset changes
|
||||||
|
//terminal.logger.Debugf("Ignoring character set control code )%s", string(b))
|
||||||
|
case '>':
|
||||||
|
// numeric char selection @todo
|
||||||
|
case '=':
|
||||||
|
//alternate char selection @todo
|
||||||
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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ type Terminal struct {
|
||||||
colourScheme ColourScheme
|
colourScheme ColourScheme
|
||||||
cellAttr CellAttributes
|
cellAttr CellAttributes
|
||||||
defaultCellAttr CellAttributes
|
defaultCellAttr CellAttributes
|
||||||
|
cursorVisible bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Line struct {
|
type Line struct {
|
||||||
|
@ -107,6 +108,10 @@ func New(pty *os.File, logger *zap.SugaredLogger, colourScheme ColourScheme) *Te
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (terminal *Terminal) GetCellAttributes() CellAttributes {
|
||||||
|
return terminal.cellAttr
|
||||||
|
}
|
||||||
|
|
||||||
func (terminal *Terminal) OnUpdate(handler func()) {
|
func (terminal *Terminal) OnUpdate(handler func()) {
|
||||||
terminal.onUpdate = append(terminal.onUpdate, handler)
|
terminal.onUpdate = append(terminal.onUpdate, handler)
|
||||||
}
|
}
|
||||||
|
@ -121,6 +126,18 @@ func (terminal *Terminal) getPosition() Position {
|
||||||
return terminal.position
|
return terminal.position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (terminal *Terminal) IsCursorVisible() bool {
|
||||||
|
return terminal.cursorVisible
|
||||||
|
}
|
||||||
|
|
||||||
|
func (terminal *Terminal) showCursor() {
|
||||||
|
terminal.cursorVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (terminal *Terminal) hideCursor() {
|
||||||
|
terminal.cursorVisible = false
|
||||||
|
}
|
||||||
|
|
||||||
func (terminal *Terminal) incrementPosition() {
|
func (terminal *Terminal) incrementPosition() {
|
||||||
position := terminal.getPosition()
|
position := terminal.getPosition()
|
||||||
if position.Col+1 >= int(terminal.size.Width) {
|
if position.Col+1 >= int(terminal.size.Width) {
|
||||||
|
@ -154,19 +171,6 @@ func (terminal *Terminal) Write(data []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (terminal *Terminal) ClearToEndOfLine() {
|
|
||||||
|
|
||||||
position := terminal.getPosition()
|
|
||||||
|
|
||||||
line := terminal.getBufferedLine(position.Line)
|
|
||||||
if line != nil {
|
|
||||||
if position.Col < len(line.Cells) {
|
|
||||||
line.Cells = line.Cells[:position.Col]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// we have thousands of lines of output. if the terminal is X lines high, we just want to lookat the most recent X lines to render (unless scroll etc)
|
// we have thousands of lines of output. if the terminal is X lines high, we just want to lookat the most recent X lines to render (unless scroll etc)
|
||||||
func (terminal *Terminal) getBufferedLine(line int) *Line {
|
func (terminal *Terminal) getBufferedLine(line int) *Line {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue