mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-24 17:50:15 +09:00
refactor: use a more modern writing style to simplify code (#3834)
Signed-off-by: deepdring <deepdrink@icloud.com>
This commit is contained in:
@@ -24,17 +24,17 @@ func init() {
|
||||
// JobFunction is a representation of a job (this data structure is what is loaded
|
||||
// into the jobs channel)
|
||||
type JobFunction struct {
|
||||
Function func(string, []interface{})
|
||||
Function func(string, []any)
|
||||
Output string
|
||||
Args []interface{}
|
||||
Args []any
|
||||
}
|
||||
|
||||
// A CallbackFile is the data structure that makes it possible to catch stderr and stdout write events
|
||||
type CallbackFile struct {
|
||||
io.Writer
|
||||
|
||||
callback func(string, []interface{})
|
||||
args []interface{}
|
||||
callback func(string, []any)
|
||||
args []any
|
||||
}
|
||||
|
||||
// Job stores the executing command for the job, and the stdin pipe
|
||||
@@ -53,13 +53,13 @@ func (f *CallbackFile) Write(data []byte) (int, error) {
|
||||
|
||||
// JobStart starts a shell command in the background with the given callbacks
|
||||
// It returns an *exec.Cmd as the job id
|
||||
func JobStart(cmd string, onStdout, onStderr, onExit func(string, []interface{}), userargs ...interface{}) *Job {
|
||||
func JobStart(cmd string, onStdout, onStderr, onExit func(string, []any), userargs ...any) *Job {
|
||||
return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...)
|
||||
}
|
||||
|
||||
// JobSpawn starts a process with args in the background with the given callbacks
|
||||
// It returns an *exec.Cmd as the job id
|
||||
func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func(string, []interface{}), userargs ...interface{}) *Job {
|
||||
func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func(string, []any), userargs ...any) *Job {
|
||||
// Set up everything correctly if the functions have been provided
|
||||
proc := exec.Command(cmdName, cmdArgs...)
|
||||
var outbuf bytes.Buffer
|
||||
|
||||
@@ -69,7 +69,7 @@ func (t *Terminal) GetSelection(width int) string {
|
||||
}
|
||||
|
||||
// Start begins a new command in this terminal with a given view
|
||||
func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback func(out string, userargs []interface{}), userargs []interface{}) error {
|
||||
func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback func(out string, userargs []any), userargs []any) error {
|
||||
if len(execCmd) <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func (t *Terminal) Close() {
|
||||
if t.getOutput {
|
||||
if t.callback != nil {
|
||||
Jobs <- JobFunction{
|
||||
Function: func(out string, args []interface{}) {
|
||||
Function: func(out string, args []any) {
|
||||
t.callback(out)
|
||||
},
|
||||
Output: t.output.String(),
|
||||
|
||||
Reference in New Issue
Block a user