Add shell command support

This commit is contained in:
Zachary Yedidia
2019-01-10 16:37:05 -05:00
parent 103527f38f
commit 16038c388e
9 changed files with 186 additions and 36 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/zyedidia/micro/cmd/micro/buffer"
"github.com/zyedidia/micro/cmd/micro/config"
"github.com/zyedidia/micro/cmd/micro/screen"
"github.com/zyedidia/micro/cmd/micro/shell"
"github.com/zyedidia/micro/cmd/micro/util"
"github.com/zyedidia/tcell"
)
@@ -370,16 +371,6 @@ func (h *BufHandler) SelectToEnd() bool {
return true
}
// InsertSpace inserts a space
func (h *BufHandler) InsertSpace() bool {
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
}
h.Buf.Insert(h.Cursor.Loc, " ")
return true
}
// InsertNewline inserts a newline plus possible some whitespace if autoindent is on
func (h *BufHandler) InsertNewline() bool {
if h.Buf.Type == buffer.BTInfo {
@@ -984,6 +975,13 @@ func (h *BufHandler) ToggleKeyMenu() bool {
// ShellMode opens a terminal to run a shell command
func (h *BufHandler) ShellMode() bool {
InfoBar.Prompt("$ ", "", "Shell", nil, func(resp string, canceled bool) {
if !canceled {
// The true here is for openTerm to make the command interactive
shell.RunInteractiveShell(resp, true, false)
}
})
return false
}

View File

@@ -13,7 +13,7 @@ import (
// This only works on linux and has no default binding.
// This code was adapted from the suspend code in nsf/godit
func (*BufHandler) Suspend() bool {
screen.TempFini()
screenb := screen.TempFini()
// suspend the process
pid := syscall.Getpid()
@@ -22,7 +22,7 @@ func (*BufHandler) Suspend() bool {
util.TermMessage(err)
}
screen.TempStart()
screen.TempStart(screenb)
return false
}

View File

@@ -261,7 +261,6 @@ var BufKeyActions = map[string]BufKeyAction{
"ParagraphPrevious": (*BufHandler).ParagraphPrevious,
"ParagraphNext": (*BufHandler).ParagraphNext,
"InsertNewline": (*BufHandler).InsertNewline,
"InsertSpace": (*BufHandler).InsertSpace,
"Backspace": (*BufHandler).Backspace,
"Delete": (*BufHandler).Delete,
"InsertTab": (*BufHandler).InsertTab,
@@ -370,7 +369,6 @@ var MultiActions = []string{
"ParagraphPrevious",
"ParagraphNext",
"InsertNewline",
"InsertSpace",
"Backspace",
"Delete",
"InsertTab",

View File

@@ -4,6 +4,8 @@ import (
"os"
"github.com/zyedidia/micro/cmd/micro/buffer"
"github.com/zyedidia/micro/cmd/micro/screen"
"github.com/zyedidia/micro/cmd/micro/shell"
"github.com/zyedidia/micro/cmd/micro/shellwords"
"github.com/zyedidia/micro/cmd/micro/util"
)
@@ -260,6 +262,15 @@ func Bind(args []string) {
// Run runs a shell command in the background
func Run(args []string) {
runf, err := shell.RunBackgroundShell(shellwords.Join(args...))
if err != nil {
InfoBar.Error(err)
} else {
go func() {
InfoBar.Message(runf())
screen.Redraw()
}()
}
}
// Quit closes the main view