mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
goto command; closes #56
This commit is contained in:
parent
58b7cb9d50
commit
a46f211c0d
@ -1,16 +1,22 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
import "os"
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
type BufferAction struct {
|
type BufferAction struct {
|
||||||
name string
|
name string
|
||||||
proc func(*View, []string) bool
|
proc func(*View, []string) bool
|
||||||
|
showInPalette bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBufferAction(name string, proc func(*View, []string) bool) BufferAction {
|
func NewBufferAction(name string, proc func(*View, []string) bool) BufferAction {
|
||||||
return BufferAction{
|
return BufferAction{
|
||||||
name: name,
|
name: name,
|
||||||
proc: proc,
|
proc: proc,
|
||||||
|
showInPalette: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +33,28 @@ func NewFile(v *View, commands []string) bool {
|
|||||||
return false
|
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{
|
var actions = map[string]BufferAction{
|
||||||
|
"goto": NewBufferAction("goto", GotoLine),
|
||||||
"new": NewBufferAction("new", NewFile),
|
"new": NewBufferAction("new", NewFile),
|
||||||
"save": NewBufferAction("save", Save),
|
"save": NewBufferAction("save", Save),
|
||||||
"delete_line": NewBufferAction("delete_line", DeleteLine),
|
"delete_line": NewBufferAction("delete_line", DeleteLine),
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"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() {
|
func (b *Buffer) moveUp() {
|
||||||
if b.curs.y > 0 {
|
if b.curs.y > 0 {
|
||||||
b.curs.move(0, -1)
|
b.curs.move(0, -1)
|
||||||
|
@ -19,18 +19,33 @@ func NewBufferPane(buff *Buffer) *BufferPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastWidth int
|
||||||
|
|
||||||
func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
|
func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
|
||||||
pad := 10
|
conf := b.Buff.cfg.Theme.Palette
|
||||||
|
|
||||||
|
pad := 6
|
||||||
mpY := (b.y + b.h) - (metaPanelHeight)
|
mpY := (b.y + b.h) - (metaPanelHeight)
|
||||||
|
|
||||||
// panel backdrop
|
// panel backdrop
|
||||||
ctx.SetColor(strife.Black)
|
ctx.SetColor(strife.HexRGB(conf.Suggestion.Background))
|
||||||
ctx.Rect(b.x, mpY, b.w, metaPanelHeight, strife.Fill)
|
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)
|
infoLine := fmt.Sprintf("Line %d, Column %d", b.Buff.curs.y, b.Buff.curs.x)
|
||||||
ctx.SetColor(strife.White)
|
ctx.SetColor(strife.HexRGB(conf.Suggestion.Foreground))
|
||||||
_, strHeight := ctx.String(infoLine, b.x+(pad/2), mpY+(pad/2))
|
_, strHeight := ctx.String(infoLine, b.x+pad, mpY+(pad/2)+1)
|
||||||
metaPanelHeight = strHeight + pad
|
metaPanelHeight = strHeight + pad
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func (b *CommandPalette) processCommand() {
|
|||||||
tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")
|
tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")
|
||||||
command := tokenizedLine[0]
|
command := tokenizedLine[0]
|
||||||
|
|
||||||
log.Println(tokenizedLine)
|
log.Println("command palette: ", tokenizedLine)
|
||||||
|
|
||||||
action, exists := actions[command]
|
action, exists := actions[command]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
Loading…
Reference in New Issue
Block a user