refactor: use a more modern writing style to simplify code (#3834)

Signed-off-by: deepdring <deepdrink@icloud.com>
This commit is contained in:
deepdring
2025-08-26 08:00:51 +08:00
committed by GitHub
parent 094b02da4c
commit b8057f28c6
24 changed files with 98 additions and 100 deletions

View File

@@ -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

View File

@@ -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(),