Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add debugger #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/SimonBaeumer/commander/debugger"
"github.com/SimonBaeumer/commander/pkg/app"
"github.com/urfave/cli"
"io/ioutil"
Expand Down Expand Up @@ -38,10 +39,27 @@ func createCliApp() *cli.App {
cliapp.Commands = []cli.Command{
createTestCommand(),
createAddCommand(),
createShellCommand(),
}
return cliapp
}

func createShellCommand() cli.Command {
return cli.Command{
Name: "shell",
Usage: "Get a shell with the current test and monitor the execution",
ArgsUsage: "[file] [title]",
Action: func(c *cli.Context) error {
if c.Args().First() != "" {

}

debugger.Start()
return nil
},
}
}

func createTestCommand() cli.Command {
return cli.Command{
Name: "test",
Expand Down
116 changes: 116 additions & 0 deletions debugger/debugger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package debugger

import (
"fmt"
"github.com/jroimartin/gocui"
"log"
"os/exec"
)

var View *gocui.View

func Start() {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()

g.SetManagerFunc(layout)

if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyCtrl2, gocui.ModNone, write); err != nil {
log.Panicln(err)
}

if err := g.SetKeybinding("", gocui.KeyCtrl3, gocui.ModNone, loop); err != nil {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err)
}
}

func loop(gui *gocui.Gui, view *gocui.View) error {
v, _ := gui.View("shell")
v.Write([]byte(`test`))
return nil
}

func write(gui *gocui.Gui, view *gocui.View) error {
v, _ := gui.View("shell")
d := Debugger{
View: v,
Gui: gui,
}
fmt.Fprintln(v, "hey")

cmd := exec.Command("/bin/bash", "-c", "tmp/test.sh")
cmd.Stdout = &d
cmd.Stderr = &d

done := make(chan error)
go func() {
done <- cmd.Wait()
}()

return nil
}

type Debugger struct {
Gui *gocui.Gui
View *gocui.View
}

func (w Debugger) Write(p []byte) (n int, err error) {
_, err = fmt.Fprintln(w.View, p)
if err != nil {
return 0, err
}

w.Gui.Update(func(gui *gocui.Gui) error {
return nil
})
return len(p), nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
fourthX := maxX / 4
halfX := maxX / 2

if v, err := g.SetView("shell", 0, 0, maxX/2, maxY-20); err != nil {
v.Title = "Shell"
v.Wrap = true
v.Editable = true
View = v
}

if v, err := g.SetView("env", halfX+1, 0, halfX+(fourthX-1), maxY-20); err != nil {
v.Title = "Environment"
v.Editable = true
fmt.Fprintln(v, "KEY: VALUE")
fmt.Fprintln(v, "HELLO: TRUE")
fmt.Fprintln(v, "PATH: /home")
fmt.Fprintln(v, "USER: root")
}

if v, err := g.SetView("config", halfX+fourthX, 0, halfX+(fourthX+fourthX-1), maxY-20); err != nil {
v.Title = "Configuration"
v.Editable = true
fmt.Fprintln(v, "Command: echo hello")
fmt.Fprintln(v, "Working Directory: /home")
fmt.Fprintln(v, "User: root")
fmt.Fprintln(v, "Env: ")
fmt.Fprintln(v, "USER: root")
}
return nil
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module github.com/SimonBaeumer/commander

require (
github.com/jroimartin/gocui v0.4.0
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 // indirect
github.com/pmezard/go-difflib v1.0.0
github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 h1:hhGN4SFXgXo61Q4Sjj/X9sBjyeSa2kdpaOzCO+8EVQw=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
8 changes: 8 additions & 0 deletions tmp/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

echo "sleep please ..."
sleep 1
echo "sleep please ..."
sleep 1
echo "sleep please ..."
sleep 1
1 change: 1 addition & 0 deletions vendor/github.com/jroimartin/gocui/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vendor/github.com/jroimartin/gocui/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions vendor/github.com/jroimartin/gocui/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions vendor/github.com/jroimartin/gocui/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions vendor/github.com/jroimartin/gocui/attribute.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading