Basic cmd running

This commit is contained in:
bloeys
2022-07-12 17:12:20 +04:00
parent 2821505d47
commit 755770d3be
2 changed files with 29 additions and 2 deletions

View File

@ -1,5 +1,5 @@
[Window][Debug##Default] [Window][Debug##Default]
Pos=814,53 Pos=869,418
Size=368,157 Size=368,157
Collapsed=0 Collapsed=0

29
main.go
View File

@ -4,7 +4,9 @@ import (
"fmt" "fmt"
"math" "math"
"os" "os"
"os/exec"
"runtime/pprof" "runtime/pprof"
"strings"
"github.com/bloeys/gglm/gglm" "github.com/bloeys/gglm/gglm"
"github.com/bloeys/nmage/engine" "github.com/bloeys/nmage/engine"
@ -247,8 +249,32 @@ func (p *program) MainUpdate() {
} }
func (p *program) RunCmd() { func (p *program) RunCmd() {
p.WriteToTextBuf(p.cmdBuf[:p.cmdBufHead])
cmdRunes := p.cmdBuf[:p.cmdBufHead]
p.WriteToTextBuf(cmdRunes)
p.cmdBufHead = 0 p.cmdBufHead = 0
cmdStr := strings.TrimSpace(string(cmdRunes))
cmdSplit := strings.SplitN(cmdStr, " ", 2)
cmdName := cmdSplit[0]
args := ""
if len(cmdSplit) == 2 {
args = cmdSplit[1]
}
cmd := exec.Command(cmdName, args)
combOutBytes, err := cmd.CombinedOutput()
if err != nil {
p.PrintToTextBuf(fmt.Sprintf("Running '%s' failed. Error: %s\n", cmdName, err.Error()))
return
}
p.WriteToTextBuf([]rune(string(combOutBytes)))
}
func (p *program) PrintToTextBuf(s string) {
p.WriteToTextBuf([]rune(s))
} }
func (p *program) DrawCursor() { func (p *program) DrawCursor() {
@ -281,6 +307,7 @@ func (p *program) DebugUpdate() {
if input.KeyDown(sdl.K_LCTRL) && input.KeyClicked(sdl.K_SPACE) { if input.KeyDown(sdl.K_LCTRL) && input.KeyClicked(sdl.K_SPACE) {
drawGrid = !drawGrid drawGrid = !drawGrid
} }
return
//UI //UI
imgui.InputText("", &textToShow) imgui.InputText("", &textToShow)