mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 14:38:19 +00:00
Basic cmd running
This commit is contained in:
@ -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
29
main.go
@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user