mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 07:45:30 +03:00
package cleanups
This commit is contained in:
parent
ec7e6902f5
commit
4ef2b08405
@ -1,13 +0,0 @@
|
||||
package action
|
||||
|
||||
import "github.com/felixangell/phi/buff"
|
||||
|
||||
func DeleteLine(v *buff.BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
b.deleteLine()
|
||||
return true
|
||||
}
|
@ -1,20 +1,18 @@
|
||||
package action
|
||||
package buff
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/felixangell/phi/buff"
|
||||
)
|
||||
|
||||
type BufferAction struct {
|
||||
name string
|
||||
proc func(*buff.BufferView, []string) bool
|
||||
proc func(*BufferView, []string) bool
|
||||
showInPalette bool
|
||||
}
|
||||
|
||||
func NewBufferAction(name string, proc func(*buff.BufferView, []string) bool) BufferAction {
|
||||
func NewBufferAction(name string, proc func(*BufferView, []string) bool) BufferAction {
|
||||
return BufferAction{
|
||||
name: name,
|
||||
proc: proc,
|
||||
@ -22,7 +20,7 @@ func NewBufferAction(name string, proc func(*buff.BufferView, []string) bool) Bu
|
||||
}
|
||||
}
|
||||
|
||||
func OpenFile(v *buff.BufferView, commands []string) bool {
|
||||
func OpenFile(v *BufferView, commands []string) bool {
|
||||
path := ""
|
||||
if path == "" {
|
||||
panic("unimplemented")
|
||||
@ -44,7 +42,7 @@ func OpenFile(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func NewFile(v *buff.BufferView, commands []string) bool {
|
||||
func NewFile(v *BufferView, commands []string) bool {
|
||||
// TODO some nice error stuff
|
||||
// have an error roll thing in the view?
|
||||
|
||||
@ -57,7 +55,7 @@ func NewFile(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func GotoLine(v *buff.BufferView, commands []string) bool {
|
||||
func GotoLine(v *BufferView, commands []string) bool {
|
||||
if len(commands) == 0 {
|
||||
return false
|
||||
}
|
||||
@ -77,7 +75,7 @@ func GotoLine(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func focusLeft(v *buff.BufferView, commands []string) bool {
|
||||
func focusLeft(v *BufferView, commands []string) bool {
|
||||
if v == nil {
|
||||
return false
|
||||
}
|
||||
@ -85,7 +83,7 @@ func focusLeft(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func focusRight(v *buff.BufferView, commands []string) bool {
|
||||
func focusRight(v *BufferView, commands []string) bool {
|
||||
if v == nil {
|
||||
return false
|
||||
}
|
||||
@ -93,7 +91,7 @@ func focusRight(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func pageDown(v *buff.BufferView, commands []string) bool {
|
||||
func pageDown(v *BufferView, commands []string) bool {
|
||||
if v == nil {
|
||||
return false
|
||||
}
|
||||
@ -109,7 +107,7 @@ func pageDown(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func pageUp(v *buff.BufferView, commands []string) bool {
|
||||
func pageUp(v *BufferView, commands []string) bool {
|
||||
if v == nil {
|
||||
return false
|
||||
}
|
@ -473,17 +473,14 @@ func (b *Buffer) processTextInput(r rune) bool {
|
||||
key = string(unicode.ToLower(r))
|
||||
}
|
||||
|
||||
log.Println("warning, unimplemented shortcut", shortcutName, "+", unicode.ToLower(r), "#", int(r), actionName)
|
||||
|
||||
/*
|
||||
actionName, actionExists := source[key]
|
||||
if actionExists {
|
||||
if action, ok := action.Register[actionName]; ok {
|
||||
return action.proc(b.parent, []string{})
|
||||
}
|
||||
} else {
|
||||
}
|
||||
*/
|
||||
actionName, actionExists := source[key]
|
||||
if actionExists {
|
||||
if action, ok := register[actionName]; ok {
|
||||
return action.proc(b.parent, []string{})
|
||||
}
|
||||
} else {
|
||||
log.Println("warning, unimplemented shortcut", shortcutName, "+", unicode.ToLower(r), "#", int(r), actionName)
|
||||
}
|
||||
}
|
||||
|
||||
if shiftDown {
|
||||
|
@ -1,12 +1,10 @@
|
||||
package action
|
||||
package buff
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/felixangell/phi/buff"
|
||||
)
|
||||
|
||||
func CloseBuffer(v *buff.BufferView, commands []string) bool {
|
||||
func CloseBuffer(v *BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
11
buff/delete_line.go
Normal file
11
buff/delete_line.go
Normal file
@ -0,0 +1,11 @@
|
||||
package buff
|
||||
|
||||
func DeleteLine(v *BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
b.deleteLine()
|
||||
return true
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
package action
|
||||
package buff
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/felixangell/phi/buff"
|
||||
)
|
||||
|
||||
func ExitPhi(v *buff.BufferView, commands []string) bool {
|
||||
func ExitPhi(v *BufferView, commands []string) bool {
|
||||
// todo this probably wont work...
|
||||
// would also be nice to have a thing
|
||||
// that asks if we want to save all buffers
|
@ -115,7 +115,7 @@ func NewCommandPalette(conf cfg.TomlConfig, view *BufferView) *CommandPalette {
|
||||
}
|
||||
palette.buff.appendLine("")
|
||||
|
||||
vW, vH := view.GetSize()
|
||||
vW, _ := view.GetSize()
|
||||
pW, pH := palette.GetSize()
|
||||
|
||||
palette.Resize(vW/3, 48)
|
||||
@ -154,14 +154,12 @@ func (b *CommandPalette) processCommand() {
|
||||
|
||||
log.Println("command palette: ", tokenizedLine)
|
||||
|
||||
/*
|
||||
action, exists := action.Register[command]
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
action, exists := register[command]
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
|
||||
action.proc(b.parent, tokenizedLine[1:])
|
||||
*/
|
||||
action.proc(b.parent, tokenizedLine[1:])
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,12 @@
|
||||
package action
|
||||
|
||||
const Register = map[string]BufferAction{
|
||||
"page_down": NewBufferAction("page_down", pageDown),
|
||||
"page_up": NewBufferAction("page_up", pageUp),
|
||||
|
||||
"undo": NewBufferAction("undo", Undo),
|
||||
"redo": NewBufferAction("redo", Redo),
|
||||
|
||||
"focus_left": NewBufferAction("focus_left", focusLeft),
|
||||
"focus_right": NewBufferAction("focus_right", focusRight),
|
||||
package buff
|
||||
|
||||
var register = map[string]BufferAction{
|
||||
"page_down": NewBufferAction("page_down", pageDown),
|
||||
"page_up": NewBufferAction("page_up", pageUp),
|
||||
"undo": NewBufferAction("undo", Undo),
|
||||
"redo": NewBufferAction("redo", Redo),
|
||||
"focus_left": NewBufferAction("focus_left", focusLeft),
|
||||
"focus_right": NewBufferAction("focus_right", focusRight),
|
||||
"goto": NewBufferAction("goto", GotoLine),
|
||||
"new": NewBufferAction("new", NewFile),
|
||||
"open": NewBufferAction("open", OpenFile),
|
@ -1,4 +1,4 @@
|
||||
package action
|
||||
package buff
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -10,17 +10,16 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/felixangell/phi/buff"
|
||||
)
|
||||
|
||||
func ShowPalette(v *buff.BufferView, commands []string) bool {
|
||||
func ShowPalette(v *BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
v.UnfocusBuffers()
|
||||
v.focusPalette(b)
|
||||
return true
|
||||
}
|
||||
|
||||
func Paste(v *buff.BufferView, commands []string) bool {
|
||||
func Paste(v *BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
@ -38,7 +37,7 @@ func Paste(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func Undo(v *buff.BufferView, commands []string) bool {
|
||||
func Undo(v *BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
@ -47,7 +46,7 @@ func Undo(v *buff.BufferView, commands []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func Redo(v *buff.BufferView, commands []string) bool {
|
||||
func Redo(v *BufferView, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
@ -68,7 +67,7 @@ func genFileName(dir, prefix, suffix string) string {
|
||||
// if the buffer is modified it will be
|
||||
// re-rendered.
|
||||
|
||||
func Save(v *buff.BufferView, commands []string) bool {
|
||||
func Save(v *BufferView, commands []string) bool {
|
||||
// TODO Config option for this.
|
||||
atomicFileSave := true
|
||||
|
20
buff/view.go
20
buff/view.go
@ -304,17 +304,15 @@ func (n *BufferView) OnUpdate() bool {
|
||||
key = string(unicode.ToLower(r))
|
||||
}
|
||||
|
||||
/*
|
||||
actionName, actionExists := source[key]
|
||||
if actionExists {
|
||||
if action, ok := action.Register[actionName]; ok {
|
||||
log.Println("Executing action '" + actionName + "'")
|
||||
return action.proc(n, []string{})
|
||||
}
|
||||
} else {
|
||||
log.Println("view: unimplemented shortcut", shortcutName, "+", string(unicode.ToLower(r)), "#", int(r), actionName, key)
|
||||
}
|
||||
*/
|
||||
actionName, actionExists := source[key]
|
||||
if actionExists {
|
||||
if action, ok := register[actionName]; ok {
|
||||
log.Println("Executing action '" + actionName + "'")
|
||||
return action.proc(n, []string{})
|
||||
}
|
||||
} else {
|
||||
log.Println("view: unimplemented shortcut", shortcutName, "+", string(unicode.ToLower(r)), "#", int(r), actionName, key)
|
||||
}
|
||||
}
|
||||
|
||||
buff := n.getCurrentBuffPane()
|
||||
|
3
main.go
3
main.go
@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/felixangell/phi/buff"
|
||||
"github.com/felixangell/phi/cfg"
|
||||
"github.com/felixangell/phi/gui"
|
||||
"github.com/felixangell/strife"
|
||||
)
|
||||
|
||||
@ -34,7 +33,7 @@ func (n *PhiEditor) handleEvent(evt strife.StrifeEvent) {
|
||||
}
|
||||
|
||||
func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
||||
mainView := gui.NewView(1280, 720, cfg)
|
||||
mainView := buff.NewView(1280, 720, cfg)
|
||||
|
||||
args := os.Args
|
||||
if len(args) > 1 {
|
||||
|
Loading…
Reference in New Issue
Block a user