diff --git a/buffer/buffer.go b/buffer/buffer.go index 1a2d12d..aa74f46 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -188,24 +188,12 @@ func (buffer *Buffer) Backspace() { line := buffer.getCurrentLine() if line.wrapped { buffer.MovePosition(int16(buffer.Width()-1), -1) - line := buffer.getCurrentLine() - if int(buffer.cursorX) < len(line.cells) { - fmt.Printf("Deleting (end) %s\n", string(line.cells[buffer.cursorX].Rune())) - line.cells[buffer.cursorX].erase() - } } else { //@todo ring bell or whatever fmt.Println("BELL?") } } else { buffer.MovePosition(-1, 0) - line := buffer.getCurrentLine() - if int(buffer.cursorX) < len(line.cells) { - fmt.Printf("Deleting %s\n", string(line.cells[buffer.cursorX].Rune())) - line.cells[buffer.cursorX].erase() - } else { - fmt.Println("Wat?") - } } } diff --git a/buffer/buffer_test.go b/buffer/buffer_test.go index 06825df..4bf8163 100644 --- a/buffer/buffer_test.go +++ b/buffer/buffer_test.go @@ -410,7 +410,7 @@ func TestBackspace(t *testing.T) { b.Backspace() b.Write([]rune("l")...) lines := b.GetVisibleLines() - assert.Equal(t, "hell", lines[0].String()) + assert.Equal(t, "hell\x00", lines[0].String()) } func TestBackspaceWithWrap(t *testing.T) { diff --git a/config/defaults.go b/config/defaults.go index c459e76..6e14b02 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -10,11 +10,11 @@ var DefaultConfig = Config{ Red: strToColourNoErr("#c2454e"), Green: strToColourNoErr("#7cbf9e"), Yellow: strToColourNoErr("#8a7a63"), - Blue: strToColourNoErr("#2e3340"), + Blue: strToColourNoErr("#065f73"), Magenta: strToColourNoErr("#ff5879"), Cyan: strToColourNoErr("#44b5b1"), LightGrey: strToColourNoErr("#f2f1b9"), - DarkGrey: strToColourNoErr("#065f73"), + DarkGrey: strToColourNoErr("#3e4360"), LightRed: strToColourNoErr("#ef5847"), LightGreen: strToColourNoErr("#a2db91"), LightYellow: strToColourNoErr("#beb090"), diff --git a/gui/gui.go b/gui/gui.go index d5d8c46..b2f9db9 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -113,6 +113,12 @@ func (gui *GUI) Render() error { gui.window.SetFramebufferSizeCallback(gui.resize) gui.window.SetKeyCallback(gui.key) gui.window.SetCharCallback(gui.char) + gui.window.SetRefreshCallback(func(w *glfw.Window) { + select { + case changeChan <- true: + default: + } + }) gui.window.SetFocusCallback(func(w *glfw.Window, focused bool) { if focused { select { @@ -190,12 +196,19 @@ func (gui *GUI) Render() error { } } - gui.font.SetColor(1, 0.5, 0.5, 0.5) - fpsData := "" - if gui.config.Rendering.AlwaysRepaint { - fpsData = fmt.Sprintf("%d FPS | %d,%d", fps, gui.terminal.GetLogicalCursorX(), gui.terminal.GetLogicalCursorY()) - } - gui.font.Print(10, float32(gui.height-20), 1.5, fmt.Sprintf("%s", fpsData)) + cx := int(gui.terminal.GetLogicalCursorX()) + cy := int(gui.terminal.GetLogicalCursorY()) + gui.renderer.DrawCursor(cx, cy, gui.config.ColourScheme.Cursor) + + _ = fps + /* + gui.font.SetColor(1, 0.5, 0.5, 0.5) + fpsData := "" + if gui.config.Rendering.AlwaysRepaint { + fpsData = fmt.Sprintf("%d FPS | %d,%d", fps, gui.terminal.GetLogicalCursorX(), gui.terminal.GetLogicalCursorY()) + } + gui.font.Print(10, float32(gui.height-20), 1.5, fmt.Sprintf("%s", fpsData)) + */ } if gui.config.Rendering.AlwaysRepaint || frames > 0 { @@ -204,7 +217,7 @@ func (gui *GUI) Render() error { frames-- } - glfw.WaitEventsTimeout(0.02) // every 20ms = 50fps on nothing changing + glfw.WaitEventsTimeout(0.02) // up to 50fps on no input, otherwise higher } gui.logger.Debugf("Stopping render...") diff --git a/gui/renderer.go b/gui/renderer.go index 35daf7b..f83664c 100644 --- a/gui/renderer.go +++ b/gui/renderer.go @@ -13,6 +13,7 @@ import ( type Renderer interface { SetArea(areaX int, areaY int, areaWidth int, areaHeight int) DrawCell(cell *buffer.Cell, col int, row int) + DrawCursor(col int, row int, colour config.Colour) GetTermSize() (int, int) } @@ -54,12 +55,13 @@ func (r *OpenGLRenderer) newRectangle(x float32, y float32, colourAttr uint32) * rect := &rectangle{ colour: [3]float32{0, 0, 1}, points: []float32{ - x, y + h, 0, x, y, 0, - x + w, y, 0, x, y + h, 0, x + w, y + h, 0, + x + w, y, 0, + x, y, 0, + x + w, y + h, 0, }, colourAttr: colourAttr, } @@ -151,7 +153,7 @@ func (r *OpenGLRenderer) SetFontScale(fontScale int32) { func (r *OpenGLRenderer) SetFont(font *glfont.Font) { // @todo check for monospace and return error if not? r.font = font - r.verticalCellPadding = (0.3 * float32(r.fontScale)) + r.verticalCellPadding = (0.25 * float32(r.fontScale)) r.cellWidth = font.Width(1, "X") r.cellHeight = font.Height(1, "X") + (r.verticalCellPadding * 2) // vertical padding r.termCols = int(math.Floor(float64(float32(r.areaWidth) / r.cellWidth))) @@ -191,9 +193,34 @@ func (r *OpenGLRenderer) generateRectangles() { } } +func (r *OpenGLRenderer) DrawCursor(col int, row int, colour config.Colour) { + + rect, ok := r.rectangles[[2]int{col, row}] + if !ok { // probably trying to draw during resize - perhaps add a mutex? + return + } + + solid := true + + mode := uint32(gl.LINE_LOOP) // gl.TRIANGES for solid cursor + points := int32(4) + + if solid { + mode = gl.TRIANGLES + points = 6 + } + + gl.UseProgram(r.program) + rect.setColour(colour) + gl.BindVertexArray(rect.vao) + //gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL) + gl.DrawArrays(mode, 0, points) + //gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL) +} + func (r *OpenGLRenderer) DrawCell(cell *buffer.Cell, col int, row int) { - if cell == nil || cell.Attr().Hidden || cell.Rune() == 0x00 { + if cell == nil || cell.Attr().Hidden || (cell.Rune() == 0x00) { return } @@ -208,61 +235,34 @@ func (r *OpenGLRenderer) DrawCell(cell *buffer.Cell, col int, row int) { bg = cell.Bg() } - var alpha float32 = 1 - if cell.Attr().Dim { - alpha = 0.5 - } - r.font.SetColor(fg[0], fg[1], fg[2], alpha) - pos, ok := r.cellPositions[[2]int{col, row}] if !ok { panic(fmt.Sprintf("Missing position data for cell at %d,%d", col, row)) } - rect, ok := r.rectangles[[2]int{col, row}] - if !ok { - panic(fmt.Sprintf("Missing rectangle data for cell at %d,%d", col, row)) - } - gl.UseProgram(r.program) // don't bother rendering rectangles that are the same colour as the background if bg != r.config.ColourScheme.Background { + + rect, ok := r.rectangles[[2]int{col, row}] + if !ok { + panic(fmt.Sprintf("Missing rectangle data for cell at %d,%d", col, row)) + } rect.setColour(bg) gl.BindVertexArray(rect.vao) gl.DrawArrays(gl.TRIANGLES, 0, 6) } + var alpha float32 = 1 + if cell.Attr().Dim { + alpha = 0.5 + } + r.font.SetColor(fg[0], fg[1], fg[2], alpha) + if cell.Attr().Bold { // bold means draw text again one pixel to right, so it's fatter r.font.Print(pos[0]+1, pos[1], 1, string(cell.Rune())) } r.font.Print(pos[0], pos[1], 1, string(cell.Rune())) - /* - this was passed into cell - x := ((float32(col) * gui.charWidth) - (float32(gui.width) / 2)) + (gui.charWidth / 2) - y := -(((float32(row) * gui.charHeight) - (float32(gui.height) / 2)) + (gui.charHeight / 2)) - - this was in cell: - x: x + (float32(gui.width) / 2) - float32(gui.charWidth/2), - y: float32(gui.height) - (y + (float32(gui.height) / 2)) + (gui.charHeight / 2) - (gui.verticalPadding / 2), - - - and then points: - - x = (x - (w / 2)) / (float32(gui.width) / 2) - y = (y - (h / 2)) / (float32(gui.height) / 2) - w = (w / float32(gui.width/2)) - h = (h / float32(gui.height/2)) - cell.points = []float32{ - x, y + h, 0, - x, y, 0, - x + w, y, 0, - x, y + h, 0, - x + w, y + h, 0, - x + w, y, 0, - } - - */ - }