Browse Source

Thinking about an intcode debugger

master
Brian Buller 2 years ago
parent
commit
1a8a0d3099
  1. 1
      2019/intcode-processor/debugger/.gitignore
  2. 44
      2019/intcode-processor/debugger/app_state.go
  3. 14
      2019/intcode-processor/debugger/main.go
  4. 126
      2019/intcode-processor/debugger/screen_main.go
  5. 8
      go.mod
  6. 16
      go.sum

1
2019/intcode-processor/debugger/.gitignore

@ -0,0 +1 @@
debugger

44
2019/intcode-processor/debugger/app_state.go

@ -0,0 +1,44 @@
package main
import (
"fmt"
"github.com/br0xen/termbox-screen"
termbox "github.com/nsf/termbox-go"
)
const (
DefaultFg = termbox.ColorWhite
DefaultBg = termbox.ColorBlack
TitleFg = termbox.ColorWhite
TitleBg = termbox.ColorBlue
CursorFg = termbox.ColorBlack
CursorBg = termbox.ColorGreen
ScreenIdExit = iota - 1
ScreenIdMain
ScreenIdError
)
type AppState struct {
ui *termboxScreen.Manager
}
func NewApp(parms []string) *AppState {
return &AppState{}
}
func (a *AppState) run(parms []string) int {
var err error
a.ui = termboxScreen.NewManager()
if err = a.ui.AddAndInitializeScreen(NewMainScreen()); err != nil {
a.ui.Close()
fmt.Println(err.Error())
return 1
}
if err := a.ui.Loop(); err != nil {
return 1
}
return 0
}

14
2019/intcode-processor/debugger/main.go

@ -0,0 +1,14 @@
package main
import "os"
var app *AppState
func main() {
var parms []string
if len(os.Args) > 1 {
parms = os.Args[1:]
}
app = NewApp(parms)
os.Exit(app.run(parms))
}

126
2019/intcode-processor/debugger/screen_main.go

@ -0,0 +1,126 @@
package main
import (
"fmt"
"strings"
intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor"
"github.com/br0xen/termbox-screen"
"github.com/br0xen/termbox-util"
termbox "github.com/nsf/termbox-go"
)
const (
MS_MODE_WAIT = iota
MS_MODE_LOAD
MS_MODE_RUN
MS_MODES = 15
MS_MODE_MENU = 1 << 4
)
type MainScreen struct {
id int
title string
mode int
filename string
prog *intcode.Program
menu []*MenuItem
}
func NewMainScreen() *MainScreen {
m := &MainScreen{
id: ScreenIdMain,
title: "IntCode Debugger",
mode: MS_MODE_WAIT,
}
m.menu = append(m.menu, NewMenu("File", NewMenu("Load"), NewMenu("Exit")))
return m
}
func (screen *MainScreen) Id() int { return screen.id }
func (screen *MainScreen) Initialize(bundle termboxScreen.Bundle) error {
return nil
}
func (screen *MainScreen) ResizeScreen() {
screen.Initialize(nil)
}
func (screen *MainScreen) HandleNoneEvent(event termbox.Event) int {
return screen.Id()
}
func (screen *MainScreen) HandleKeyEvent(event termbox.Event) int {
if event.Ch == 0 && event.Key == termbox.KeyEsc {
screen.toggleMenu()
}
return screen.Id()
}
// ╭╼╾╮
// │┼━│
// ├┴┬┤
// ╰──╯
func (screen *MainScreen) DrawScreen() {
//w, _ := termbox.Size()
screen.drawHeader()
screen.drawFooter()
}
func (screen *MainScreen) drawHeader() {
w, _ := termbox.Size()
spaces := strings.Repeat(" ", ((w-len(screen.title))/2)+1)
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%s%s%s", spaces, screen.title, spaces), 0, 0, TitleFg, TitleBg)
if screen.menuIsOn() {
}
}
func (screen *MainScreen) drawFooter() {
}
func (screen *MainScreen) getMode() int {
return screen.mode & MS_MODES
}
func (screen *MainScreen) menuIsOn() bool {
return screen.mode&MS_MODE_MENU == MS_MODE_MENU
}
func (screen *MainScreen) toggleMenu() {
if screen.menuIsOn() {
screen.hideMenu()
} else {
screen.showMenu()
}
}
func (screen *MainScreen) showMenu() {
screen.mode = screen.mode | MS_MODE_MENU
}
func (screen *MainScreen) hideMenu() {
screen.mode = screen.mode ^ MS_MODE_MENU
}
type MenuItem struct {
title string
parent string
SubMenu []*MenuItem
}
func NewMenu(title string, items ...*MenuItem) *MenuItem {
m := MenuItem{title: title}
for i := range items {
items[i].parent = title
m.SubMenu = append(m.SubMenu, items[i])
}
return &m
}

8
go.mod

@ -3,12 +3,20 @@ module git.bullercodeworks.com/brian/adventofcode
go 1.13
require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6
github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2 // indirect
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da // indirect
github.com/fatih/color v1.7.0
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72
github.com/google/uuid v1.1.1 // indirect
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975 // indirect
github.com/nlopes/slack v0.6.0 // indirect
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317
)

16
go.sum

@ -1,3 +1,13 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6 h1:QaQWdi0Kgk1v+DW35aaBsEpoig3smyjJy2M6e/dePjM=
github.com/br0xen/termbox-screen v0.0.0-20190712162752-c91f70ac38c6/go.mod h1:g8Iv1LnV2Dg45Bg5uCATrYi5Y57mXWsqlPnfU2BhD5I=
github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca h1:UMJCb+zIdrTX68nP5byq1xjW72UIqMBNxcYPlPFhnOs=
github.com/br0xen/termbox-util v0.0.0-20190325151025-c168c0df31ca/go.mod h1:x9wJlgOj74OFTOBwXOuO8pBguW37EgYNx51Dbjkfzo4=
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2 h1:H/prDPxUZBsK4DQC7ScP3ftSijMtWyetb6ab69DSKrs=
github.com/br0xen/user-config v0.0.0-20170914134719-16e743ec93a2/go.mod h1:lMy7txIyYXt+I/1JgTGBZTdyTNJyNVDCX4Z+lHzNcSM=
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da h1:hjpZV7G49m1bly++F+Gho1Sbf2+eBW/eTLJWuRkH9Uc=
github.com/casimir/xdg-go v0.0.0-20160329195404-372ccc2180da/go.mod h1:dywSSi3sMtJn2IjiYfJciP9tjVVeIVRa7AE7N5WLUBo=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
@ -6,8 +16,12 @@ github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluN
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72 h1:LgLYrxDRSVv3kStk6louYTP1ekZ6t7HZY/X05KUyaeM=
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 h1:EFT6MH3igZK/dIVqgGbTqWVvkZ7wJ5iGN03SVtvvdd8=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25/go.mod h1:sWkGw/wsaHtRsT9zGQ/WyJCotGWG/Anow/9hsAcBWRw=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
@ -15,6 +29,8 @@ github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW1
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975 h1:zm/Rb2OsnLWCY88Njoqgo4X6yt/lx3oBNWhepX0AOMU=
github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975/go.mod h1:4Mct/lWCFf1jzQTTAaWtOI7sXqmG+wBeiBfT4CxoaJk=
github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA=
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 h1:hhGN4SFXgXo61Q4Sjj/X9sBjyeSa2kdpaOzCO+8EVQw=

Loading…
Cancel
Save