summaryrefslogtreecommitdiff
path: root/stdoutShow.go
blob: 6d36861fcd0a070cb8921849688648e5d904dc74 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"errors"
	"fmt"

	"github.com/awesome-gocui/gocui"

	"go.wit.com/log"
	"go.wit.com/widget"
)

func showMsg(g *gocui.Gui, v *gocui.View) error {
	var l string
	var err error

	log.Log(NOW, "showMsg() v.name =", v.Name())
	if _, err := g.SetCurrentView(v.Name()); err != nil {
		return err
	}

	_, cy := v.Cursor()
	if l, err = v.Line(cy); err != nil {
		l = ""
	}

	outv := makeOutputWidget(g, l)
	outv.Write([]byte("test out2"))
	log.Info("test out2")
	return nil
}

func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
	if me.treeRoot == nil {
		// keep skipping this until the binary tree is initialized
		return nil
	}

	if me.stdout.tk == nil {
		a := new(widget.Action)
		a.ProgName = "stdout"
		a.WidgetType = widget.Stdout
		a.WidgetId = -3
		a.ParentId = 0
		// n := addNode(a)
		n := me.myTree.AddNode(a)
		me.stdout.tk = initWidget(n)

		tk := me.stdout.tk
		tk.gocuiSize.w0 = me.stdout.lastW
		tk.gocuiSize.h0 = me.stdout.lastH
		tk.gocuiSize.w1 = tk.gocuiSize.w0 + me.stdout.w
		tk.gocuiSize.h1 = tk.gocuiSize.h0 + me.stdout.h

	}

	v, err := g.View("msg")
	if v == nil {
		log.Log(NOW, "makeoutputwindow() this is supposed to happen. v == nil", err)
	} else {
		log.Log(NOW, "makeoutputwindow() msg != nil. WTF now? err =", err)
	}

	rect := me.stdout.tk.gocuiSize
	v, err = g.SetView("msg", rect.w0, rect.h0, rect.w1, rect.h1, 0)

	if errors.Is(err, gocui.ErrUnknownView) {
		log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err)
	}

	if err != nil {
		log.Log(NOW, "makeoutputwindow() create output window failed", err)
		return nil
	}

	if v == nil {
		log.Log(NOW, "makeoutputwindow() msg == nil. WTF now? err =", err)
		return nil
	} else {
		me.stdout.tk.v = v
	}

	v.Clear()
	v.SelBgColor = gocui.ColorCyan
	v.SelFgColor = gocui.ColorBlack
	fmt.Fprintln(v, "figure out how to capture STDOUT to here\n"+stringFromMouseClick)
	g.SetViewOnBottom("msg")

	me.stdout.tk.v = v
	me.stdout.tk.DrawAt(me.stdout.lastW, me.stdout.lastH)
	relocateStdoutOffscreen()
	return v
}

func relocateStdoutOffscreen() {
	if me.stdout.tk == nil {
		return
	}
	log.CaptureMode(me.stdout.tk)
	log.Log(ERROR, "setting log.CaptureMode(tk.v) in relocateStdoutOffscreen()")
	newW := 10
	newH := 0 - me.stdout.h - 4
	me.stdout.tk.relocateStdout(newW, newH)
}

func (tk *guiWidget) relocateStdout(w int, h int) {
	w0 := w
	h0 := h
	w1 := w + me.stdout.w
	h1 := h + me.stdout.h

	tk.gocuiSize.w0 = w0
	tk.gocuiSize.w1 = w1
	tk.gocuiSize.h0 = h0
	tk.gocuiSize.h1 = h1

	tk.full.w0 = w0
	tk.full.w1 = w1
	tk.full.h0 = h0
	tk.full.h1 = h1

	me.baseGui.SetView("msg", w0, h0, w1, h1, 0)
	// me.baseGui.SetViewOnBottom("msg")
}