keep cleaning the 'msg' stdout handling code

This commit is contained in:
Jeff Carr 2025-02-08 18:21:31 -06:00
parent 2c07da350a
commit bff0943dc5
2 changed files with 60 additions and 55 deletions

View File

@ -84,54 +84,49 @@ func mouseMove(g *gocui.Gui) {
return return
} }
// if me.mouse.globalMouseDown { // drag whatever was set to drag
// log.Info("msgMouseDown == true")
// plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here
var found bool = false
if me.mouse.currentDrag != nil { if me.mouse.currentDrag != nil {
// me.mouse.currentDrag.dumpWidget(fmt.Sprintf("MM (%3d,%3d)", w, h)) // me.mouse.currentDrag.dumpWidget(fmt.Sprintf("MM (%3d,%3d)", w, h))
me.mouse.currentDrag.moveNew() me.mouse.currentDrag.moveNew()
return return
} }
// new function that is smarter log.Info(fmt.Sprintf("gui toolkit error. nothing to drag at (%d,%d)", w, h))
if tk := findWindowUnderMouse(); tk != nil { return
tk.setAsDragging()
return
}
// first look for windows
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Window {
tk.setAsDragging()
return
}
}
// now look for the STDOUT window // if me.mouse.globalMouseDown {
for _, tk := range findByXY(w, h) { // log.Info("msgMouseDown == true")
if tk.node.WidgetType == widget.Flag { // plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here
/*
// new function that is smarter
if tk := findWindowUnderMouse(); tk != nil {
tk.setAsDragging() tk.setAsDragging()
return return
} }
} // first look for windows
for _, tk := range findByXY(w, h) { for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Stdout { if tk.node.WidgetType == widget.Window {
tk.setAsDragging() tk.setAsDragging()
// tk.moveNew() return
return }
} }
/*
if tk.node.WidgetType == widget.Label { // now look for the STDOUT window
me.mouse.currentDrag = tk for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
tk.setAsDragging()
return
}
}
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Stdout {
tk.setAsDragging()
// tk.moveNew() // tk.moveNew()
return return
} }
*/ found = true
found = true }
} */
if !found {
log.Info(fmt.Sprintf("findByXY() empty. nothing to move at (%d,%d)", w, h))
}
} }
func (tk *guiWidget) setAsDragging() { func (tk *guiWidget) setAsDragging() {

View File

@ -156,32 +156,42 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
return len(p), nil return len(p), nil
} }
if tk.v == nil { if tk.v == nil {
// optionally write the output to /tmp
s := fmt.Sprint(string(p))
s = strings.TrimSuffix(s, "\n")
fmt.Fprintln(outf, s)
v, _ := me.baseGui.View("msg") v, _ := me.baseGui.View("msg")
if v != nil { if v != nil {
// fmt.Fprintln(outf, "found msg") // fmt.Fprintln(outf, "found msg")
tk.v = v tk.v = v
} }
} else { return len(p), nil
// display the output in the gocui window
var cur []string
// chop off the last lines in the buffer
chop := len(me.stdout.outputS) - (me.stdout.h - 1)
if chop < 0 {
chop = 0
}
if len(me.stdout.outputS) > chop {
cur = append(cur, me.stdout.outputS[chop:]...)
} else {
cur = append(cur, me.stdout.outputS...)
}
slices.Reverse(cur)
tk.v.Clear()
fmt.Fprintln(tk.v, strings.Join(cur, "\n"))
} }
tk.refreshStdout()
/*
// optionally write the output to /tmp
s := fmt.Sprint(string(p))
s = strings.TrimSuffix(s, "\n")
fmt.Fprintln(outf, s)
v, _ := me.baseGui.View("msg")
if v != nil {
// fmt.Fprintln(outf, "found msg")
tk.v = v
}
} else {
// display the output in the gocui window
var cur []string
// chop off the last lines in the buffer
chop := len(me.stdout.outputS) - (me.stdout.h - 1)
if chop < 0 {
chop = 0
}
if len(me.stdout.outputS) > chop {
cur = append(cur, me.stdout.outputS[chop:]...)
} else {
cur = append(cur, me.stdout.outputS...)
}
slices.Reverse(cur)
tk.v.Clear()
fmt.Fprintln(tk.v, strings.Join(cur, "\n"))
}
*/
return len(p), nil return len(p), nil
} }