1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# Debugging Techniques
In no particular order, here is a list of tricks for debugging gowid applications.
## Run on a different tty
- Make a local clone of the `tcell` repo:
```bash
git clone https://github.com/gdamore/tcell
cd tcell
```
- Apply the patch from this gist: https://gist.github.com/gcla/29628006828e57ece336554f26e0bde9
```bash
patch -p1 < gowidtty.patch
```
- Make your gowid application compile against your local clone of `tcell`. Adjust your application's `go.mod` like this, replacing `<me>` with your username (or adjust to where you cloned `tcell`)
```bash
replace github.com/gdamore/tcell => /home/<me>/tcell
```
- Run your application in tmux - make a split screen.
- On one side, determine the tty, then block input
- On the other side, set the environment variable `GOWID_TTY`

- Run your gowid application e.g. using [tm.sh](https://gist.github.com/gcla/e52ea391c4001cedcfa2cf22d124a750)
```bash
tm.sh 1 go run examples/gowid-fib/fib.go
```

Then you can add `fmt.Printf(...)` calls to quickly debug and not have them interfere with your application's tty.
## Watch Flow of User Input Events
Gowid widgets are arranged in a hierarchy, with outer widgets passing events through to inner widgets for processing,
possibly altering them or handling them themselves on the way. Outer widgets could call
```go
child.UserInput(ev, ...)
```
to determine whether or not the child is handling the event. But instead, all gowid widgets currently call
```go
gowid.UserInput(child, ev, ...)
```
instead. This has the same effect, but means that `gowid.UserInput()` can be used to inspect events flowing through
the application. For example, you can modify the function in `support.go`:
```go
func UserInput(w IWidget, ev interface{}, size IRenderSize, focus Selector, app IApp) bool {
if evm, ok := ev.(*tcell.EventMouse); ok {
// Do something
fmt.Printf("Sending event %v of type %T to widget %v", ev, ev, w)
}
return w.UserInput(ev, size, focus, app)
}
|