test writes to stdout widget kinda work
This commit is contained in:
parent
2ace17294c
commit
368c25107a
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
12
gocui.go
12
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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue