From 368c25107a9343d3368182efbe203acb4fbf8d5e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 13 Nov 2024 21:32:44 -0600 Subject: [PATCH] test writes to stdout widget kinda work --- fakefile.go | 7 ++++++- gocui.go | 12 +++++++++++- keybindings.go | 10 ++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fakefile.go b/fakefile.go index 47ef529..9c74daa 100644 --- a/fakefile.go +++ b/fakefile.go @@ -4,12 +4,15 @@ import ( "bytes" "errors" "io" + + "github.com/awesome-gocui/gocui" ) type FakeFile struct { reader *bytes.Reader buffer *bytes.Buffer offset int64 + view *gocui.View } func (f *FakeFile) Read(p []byte) (n int, err error) { @@ -22,6 +25,7 @@ func (f *FakeFile) Write(p []byte) (n int, err error) { n, err = f.buffer.Write(p) f.offset += int64(n) f.reader.Reset(f.buffer.Bytes()) + f.view.Write(p) return n, err } @@ -48,11 +52,12 @@ func (f *FakeFile) Seek(offset int64, whence int) (int64, error) { return f.offset, nil } -func NewFakeFile() *FakeFile { +func NewFakeFile(v *gocui.View) *FakeFile { buf := &bytes.Buffer{} return &FakeFile{ reader: bytes.NewReader(buf.Bytes()), buffer: buf, offset: 0, + view: v, } } diff --git a/gocui.go b/gocui.go index 1118a7d..bdb3bb4 100644 --- a/gocui.go +++ b/gocui.go @@ -6,12 +6,15 @@ package main import ( "errors" + "fmt" "github.com/awesome-gocui/gocui" "go.wit.com/log" ) +var ecount int = 3 + // Thanks to the gocui developers -- your package kicks ass // This function is called on every event. It is a callback function from the gocui package // which has an excellent implementation. While gocui handles things like text highlighting @@ -19,6 +22,7 @@ import ( // complicated console handling, it sends events here in a clean way. // This is equivalent to the linux command xev (apt install x11-utils) func gocuiEvent(g *gocui.Gui) error { + ecount += 1 maxX, maxY := g.Size() mx, my := g.MousePosition() log.Verbose("handleEvent() START", maxX, maxY, mx, my, msgMouseDown) @@ -32,7 +36,13 @@ func gocuiEvent(g *gocui.Gui) error { // setOutput(me.logStdout) // me.logStdout.Write("test out") w := me.logStdout.TK.(*guiWidget) - w.Write([]byte("test out")) + msg := fmt.Sprintf("test out %d\n", ecount) + msg += fmt.Sprintf("test out %d\n", ecount) + msg += fmt.Sprintf("test out %d\n", ecount) + w.Write([]byte(msg + msg + msg)) + w.Write([]byte(msg + msg + msg)) + w.Write([]byte(msg + msg + msg)) + w.Write([]byte(msg + msg + msg)) // log.CaptureMode(w) log.Log(NOW, "logStdout test out") } diff --git a/keybindings.go b/keybindings.go index a4f33dc..5cf8c2f 100644 --- a/keybindings.go +++ b/keybindings.go @@ -5,6 +5,7 @@ package main import ( + "fmt" "syscall" "github.com/awesome-gocui/gocui" @@ -132,6 +133,15 @@ func addDebugKeys(g *gocui.Gui) { g.SetKeybinding("", 'L', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { me.treeRoot.ListWidgets() + + w := me.logStdout.TK.(*guiWidget) + msg := fmt.Sprintf("test out %d\n", ecount) + msg += fmt.Sprintf("test out %d\n", ecount) + msg += fmt.Sprintf("test out %d\n", ecount) + w.Write([]byte(msg + msg + msg)) + w.Write([]byte(msg + msg + msg)) + w.Write([]byte(msg + msg + msg)) + w.Write([]byte(msg + msg + msg)) return nil })