goto command; closes #56

This commit is contained in:
Felix Angell 2018-05-06 14:33:13 +01:00
parent 58b7cb9d50
commit a46f211c0d
4 changed files with 65 additions and 10 deletions

View File

@ -1,16 +1,22 @@
package gui
import "os"
import (
"log"
"os"
"strconv"
)
type BufferAction struct {
name string
proc func(*View, []string) bool
name string
proc func(*View, []string) bool
showInPalette bool
}
func NewBufferAction(name string, proc func(*View, []string) bool) BufferAction {
return BufferAction{
name: name,
proc: proc,
name: name,
proc: proc,
showInPalette: true,
}
}
@ -27,7 +33,28 @@ func NewFile(v *View, commands []string) bool {
return false
}
func GotoLine(v *View, commands []string) bool {
if len(commands) == 0 {
return false
}
lineNum, err := strconv.ParseInt(commands[0], 10, 64)
if err != nil {
log.Println("goto line invalid argument ", err.Error())
return false
}
b := v.getCurrentBuff()
if b == nil {
return false
}
b.gotoLine(lineNum)
return false
}
var actions = map[string]BufferAction{
"goto": NewBufferAction("goto", GotoLine),
"new": NewBufferAction("new", NewFile),
"save": NewBufferAction("save", Save),
"delete_line": NewBufferAction("delete_line", DeleteLine),

View File

@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"log"
"math"
"os"
"path"
"runtime"
@ -438,6 +439,18 @@ func (b *Buffer) moveToEndOfLine() {
}
}
// TODO make this scroll auto magically.
func (b *Buffer) gotoLine(num int64) {
distToMove := float64(num - int64(b.curs.y))
for i := int64(0); i < int64(math.Abs(distToMove)); i++ {
if distToMove < 0 {
b.moveUp()
} else {
b.moveDown()
}
}
}
func (b *Buffer) moveUp() {
if b.curs.y > 0 {
b.curs.move(0, -1)

View File

@ -19,18 +19,33 @@ func NewBufferPane(buff *Buffer) *BufferPane {
}
}
var lastWidth int
func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
pad := 10
conf := b.Buff.cfg.Theme.Palette
pad := 6
mpY := (b.y + b.h) - (metaPanelHeight)
// panel backdrop
ctx.SetColor(strife.Black)
ctx.SetColor(strife.HexRGB(conf.Suggestion.Background))
ctx.Rect(b.x, mpY, b.w, metaPanelHeight, strife.Fill)
// tab info etc. on right hand side
{
tabSize := b.Buff.cfg.Editor.Tab_Size
syntaxName := "Undefined"
infoLine := fmt.Sprintf("Tab Size: %d Syntax: %s", tabSize, syntaxName)
ctx.SetColor(strife.HexRGB(conf.Suggestion.Foreground))
lastWidth, _ = ctx.String(infoLine, ((b.x + b.w) - (lastWidth + (pad))), mpY+(pad/2)+1)
}
{
infoLine := fmt.Sprintf("Line %d, Column %d", b.Buff.curs.y, b.Buff.curs.x)
ctx.SetColor(strife.White)
_, strHeight := ctx.String(infoLine, b.x+(pad/2), mpY+(pad/2))
ctx.SetColor(strife.HexRGB(conf.Suggestion.Foreground))
_, strHeight := ctx.String(infoLine, b.x+pad, mpY+(pad/2)+1)
metaPanelHeight = strHeight + pad
}

View File

@ -123,7 +123,7 @@ func (b *CommandPalette) processCommand() {
tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")
command := tokenizedLine[0]
log.Println(tokenizedLine)
log.Println("command palette: ", tokenizedLine)
action, exists := actions[command]
if !exists {