mirror of
https://github.com/EnumeratedDev/Typer.git
synced 2025-07-01 07:48:20 +00:00
Add key binding and command to run any other command through input bar
This commit is contained in:
parent
e25916228c
commit
a3138a9e86
@ -37,4 +37,7 @@ keybindings:
|
||||
command: "menu-edit"
|
||||
- keybinding: "F3"
|
||||
cursor_modes: ["buffer","dropdown"]
|
||||
command: "menu-buffers"
|
||||
command: "menu-buffers"
|
||||
- keybinding: "Ctrl-E"
|
||||
cursor_modes: ["buffer"]
|
||||
command: "execute"
|
@ -246,6 +246,47 @@ func initCommands() {
|
||||
},
|
||||
}
|
||||
|
||||
executeCmd := Command{
|
||||
cmd: "execute",
|
||||
run: func(window *Window, args ...string) {
|
||||
inputChannel := RequestInput(window, "Run:", "")
|
||||
|
||||
go func() {
|
||||
input := strings.TrimSpace(<-inputChannel)
|
||||
|
||||
if input == "" {
|
||||
return
|
||||
}
|
||||
|
||||
var arguments []string
|
||||
|
||||
builder := &strings.Builder{}
|
||||
quoted := false
|
||||
for _, r := range input {
|
||||
if r == '"' {
|
||||
quoted = !quoted
|
||||
} else if !quoted && r == ' ' {
|
||||
arguments = append(arguments, builder.String())
|
||||
builder.Reset()
|
||||
} else {
|
||||
builder.WriteRune(r)
|
||||
}
|
||||
}
|
||||
if builder.Len() > 0 {
|
||||
arguments = append(arguments, builder.String())
|
||||
}
|
||||
|
||||
window.CursorMode = CursorModeBuffer
|
||||
|
||||
if len(arguments) == 1 {
|
||||
RunCommand(window, arguments[0])
|
||||
} else {
|
||||
RunCommand(window, arguments[0], arguments[1:]...)
|
||||
}
|
||||
}()
|
||||
},
|
||||
}
|
||||
|
||||
// Register commands
|
||||
commands["copy"] = ©Cmd
|
||||
commands["paste"] = &pasteCmd
|
||||
@ -260,6 +301,7 @@ func initCommands() {
|
||||
commands["menu-edit"] = &menuEditCmd
|
||||
commands["menu-buffers"] = &menuBuffersCmd
|
||||
commands["quit"] = &quitCmd
|
||||
commands["execute"] = &executeCmd
|
||||
}
|
||||
|
||||
func RunCommand(window *Window, cmd string, args ...string) bool {
|
||||
|
@ -38,9 +38,11 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
for window.screen != nil {
|
||||
for !window.closed {
|
||||
window.Draw()
|
||||
window.ProcessEvents()
|
||||
}
|
||||
|
||||
window.screen.Fini()
|
||||
window.screen = nil
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ type Window struct {
|
||||
CurrentBuffer *Buffer
|
||||
|
||||
screen tcell.Screen
|
||||
|
||||
closed bool
|
||||
}
|
||||
|
||||
var mouseHeld = false
|
||||
@ -637,8 +639,11 @@ func (window *Window) handleMouseInput(ev *tcell.EventMouse) {
|
||||
}
|
||||
|
||||
func (window *Window) Close() {
|
||||
window.screen.Fini()
|
||||
window.screen = nil
|
||||
window.closed = true
|
||||
err := window.screen.PostEvent(tcell.NewEventInterrupt(nil))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (window *Window) GetTextAreaDimensions() (int, int, int, int) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user