Avoid unnecessary []byte->string conversions

This commit is contained in:
bloeys
2022-07-16 21:03:57 +04:00
parent 6f1fc396cb
commit 648a9c7500

22
main.go
View File

@ -597,7 +597,7 @@ func (p *program) HandleReturn() {
_, err := p.activeCmd.Stdin.Write([]byte(string(cmdRunes))) _, err := p.activeCmd.Stdin.Write([]byte(string(cmdRunes)))
if err != nil { if err != nil {
p.PrintToTextBuf(fmt.Sprintf("Writing to stdin pipe of '%s' failed. Error: %s\n", p.activeCmd.C.Path, err.Error())) p.WriteToTextBuf([]byte(fmt.Sprintf("Writing to stdin pipe of '%s' failed. Error: %s\n", p.activeCmd.C.Path, err.Error())))
p.ClearActiveCmd() p.ClearActiveCmd()
return return
} }
@ -621,26 +621,26 @@ func (p *program) HandleReturn() {
outPipe, err := cmd.StdoutPipe() outPipe, err := cmd.StdoutPipe()
if err != nil { if err != nil {
p.PrintToTextBuf(fmt.Sprintf("Creating stdout pipe of '%s' failed. Error: %s\n", cmdName, err.Error())) p.WriteToTextBuf([]byte(fmt.Sprintf("Creating stdout pipe of '%s' failed. Error: %s\n", cmdName, err.Error())))
return return
} }
inPipe, err := cmd.StdinPipe() inPipe, err := cmd.StdinPipe()
if err != nil { if err != nil {
p.PrintToTextBuf(fmt.Sprintf("Creating stdin pipe of '%s' failed. Error: %s\n", cmdName, err.Error())) p.WriteToTextBuf([]byte(fmt.Sprintf("Creating stdin pipe of '%s' failed. Error: %s\n", cmdName, err.Error())))
return return
} }
errPipe, err := cmd.StderrPipe() errPipe, err := cmd.StderrPipe()
if err != nil { if err != nil {
p.PrintToTextBuf(fmt.Sprintf("Creating stderr pipe of '%s' failed. Error: %s\n", cmdName, err.Error())) p.WriteToTextBuf([]byte(fmt.Sprintf("Creating stderr pipe of '%s' failed. Error: %s\n", cmdName, err.Error())))
return return
} }
startTime := time.Now() startTime := time.Now()
err = cmd.Start() err = cmd.Start()
if err != nil { if err != nil {
p.PrintToTextBuf(fmt.Sprintf("Running '%s' failed. Error: %s\n", cmdName, err.Error())) p.WriteToTextBuf([]byte(fmt.Sprintf("Running '%s' failed. Error: %s\n", cmdName, err.Error())))
return return
} }
p.activeCmd = &Cmd{ p.activeCmd = &Cmd{
@ -668,7 +668,7 @@ func (p *program) HandleReturn() {
break break
} }
p.PrintToTextBuf("Stdout pipe failed. Error: " + err.Error()) p.WriteToTextBuf([]byte("Stdout pipe failed. Error: " + err.Error()))
return return
} }
@ -676,7 +676,7 @@ func (p *program) HandleReturn() {
continue continue
} }
p.PrintToTextBuf(string(buf[:readBytes])) p.WriteToTextBuf(buf[:readBytes])
// println("Read:", string(buf[:readBytes])) // println("Read:", string(buf[:readBytes]))
} }
}() }()
@ -696,7 +696,7 @@ func (p *program) HandleReturn() {
break break
} }
p.PrintToTextBuf("Stderr pipe failed. Error: " + err.Error()) p.WriteToTextBuf([]byte("Stderr pipe failed. Error: " + err.Error()))
return return
} }
@ -704,7 +704,7 @@ func (p *program) HandleReturn() {
continue continue
} }
p.PrintToTextBuf(string(buf[:readBytes])) p.WriteToTextBuf(buf[:readBytes])
} }
}() }()
} }
@ -718,10 +718,6 @@ func (p *program) ClearActiveCmd() {
p.activeCmd = nil p.activeCmd = nil
} }
func (p *program) PrintToTextBuf(s string) {
p.WriteToTextBuf([]byte(s))
}
func (p *program) DrawCursor() { func (p *program) DrawCursor() {
//Position cursor by placing it at the end of the drawn characters then walking backwards //Position cursor by placing it at the end of the drawn characters then walking backwards