test writes to stdout widget kinda work
This commit is contained in:
parent
2ace17294c
commit
368c25107a
|
@ -4,12 +4,15 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/awesome-gocui/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeFile struct {
|
type FakeFile struct {
|
||||||
reader *bytes.Reader
|
reader *bytes.Reader
|
||||||
buffer *bytes.Buffer
|
buffer *bytes.Buffer
|
||||||
offset int64
|
offset int64
|
||||||
|
view *gocui.View
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeFile) Read(p []byte) (n int, err error) {
|
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)
|
n, err = f.buffer.Write(p)
|
||||||
f.offset += int64(n)
|
f.offset += int64(n)
|
||||||
f.reader.Reset(f.buffer.Bytes())
|
f.reader.Reset(f.buffer.Bytes())
|
||||||
|
f.view.Write(p)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +52,12 @@ func (f *FakeFile) Seek(offset int64, whence int) (int64, error) {
|
||||||
return f.offset, nil
|
return f.offset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFakeFile() *FakeFile {
|
func NewFakeFile(v *gocui.View) *FakeFile {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
return &FakeFile{
|
return &FakeFile{
|
||||||
reader: bytes.NewReader(buf.Bytes()),
|
reader: bytes.NewReader(buf.Bytes()),
|
||||||
buffer: buf,
|
buffer: buf,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
|
view: v,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
gocui.go
12
gocui.go
|
@ -6,12 +6,15 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ecount int = 3
|
||||||
|
|
||||||
// Thanks to the gocui developers -- your package kicks ass
|
// 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
|
// 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
|
// 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.
|
// complicated console handling, it sends events here in a clean way.
|
||||||
// This is equivalent to the linux command xev (apt install x11-utils)
|
// This is equivalent to the linux command xev (apt install x11-utils)
|
||||||
func gocuiEvent(g *gocui.Gui) error {
|
func gocuiEvent(g *gocui.Gui) error {
|
||||||
|
ecount += 1
|
||||||
maxX, maxY := g.Size()
|
maxX, maxY := g.Size()
|
||||||
mx, my := g.MousePosition()
|
mx, my := g.MousePosition()
|
||||||
log.Verbose("handleEvent() START", maxX, maxY, mx, my, msgMouseDown)
|
log.Verbose("handleEvent() START", maxX, maxY, mx, my, msgMouseDown)
|
||||||
|
@ -32,7 +36,13 @@ func gocuiEvent(g *gocui.Gui) error {
|
||||||
// setOutput(me.logStdout)
|
// setOutput(me.logStdout)
|
||||||
// me.logStdout.Write("test out")
|
// me.logStdout.Write("test out")
|
||||||
w := me.logStdout.TK.(*guiWidget)
|
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.CaptureMode(w)
|
||||||
log.Log(NOW, "logStdout test out")
|
log.Log(NOW, "logStdout test out")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
|
@ -132,6 +133,15 @@ func addDebugKeys(g *gocui.Gui) {
|
||||||
g.SetKeybinding("", 'L', gocui.ModNone,
|
g.SetKeybinding("", 'L', gocui.ModNone,
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
me.treeRoot.ListWidgets()
|
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
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue