summaryrefslogtreecommitdiff
path: root/libnotify.go
blob: 7cd68dfd5d36d3c0098e7aa27ddd59a3df4ed5da (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
128
129
// Copyright 2014 The gocui Authors. All rights reserved.
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"time"

	"github.com/awesome-gocui/gocui"
	log "go.wit.com/log"
	"go.wit.com/toolkits/tree"
	"go.wit.com/widget"
)

// create a new widget in the binary tree
func makeNewInternalWidget(wId int) *guiWidget {
	if me.treeRoot == nil {
		log.Info("GOGUI Init ERROR. treeRoot == nil")
		return nil
	}
	n := new(tree.Node)
	n.WidgetType = widget.Flag
	n.WidgetId = wId
	n.ParentId = 0

	// store the internal toolkit information
	tk := new(guiWidget)
	tk.frame = true

	tk.node = n
	tk.node.Parent = me.treeRoot

	// set the name used by gocui to the id
	tk.cuiName = fmt.Sprintf("%d DR", wId)

	tk.setColorInput()

	// add this new widget on the binary tree
	tk.parent = me.treeRoot.TK.(*guiWidget)
	if tk.parent == nil {
		panic("makeNewFlagWidget() didn't get treeRoot guiWidget")
	} else {
		tk.parent.children = append(tk.parent.children, tk)
	}

	n.TK = tk
	return tk
}

func makeClock(wId int) {
	if me.treeRoot == nil {
		log.Info("gogui makeClock() error. treeRoot == nil")
		return
	}
	me.notify.clock.tk = makeNewInternalWidget(wId)
	me.notify.clock.tk.dumpWidget("init() clock")
	w, h := me.baseGui.MousePosition()
	me.notify.clock.tk.MoveToOffset(w, h)
	me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
	me.notify.clock.tk.frame = false
	me.notify.clock.tk.setColorLabel()
	me.notify.clock.tk.Show()
	me.notify.clock.active = true
	me.notify.clock.tk.dumpWidget("showClock()")
}

// in the very end of redrawing things, this will place the help and stdout on the top or botton
// depending on the state the user has chosen
func setThingsOnTop() {
	if me.showHelp { // terrible variable name. FIXME
		// log.Info("help does not exist")
	} else {
		me.baseGui.SetViewOnTop("help")
	}
	if me.notify.clock.tk != nil {
		me.baseGui.SetViewOnTop(me.notify.clock.tk.v.Name())
	}

	if me.stdout.tk == nil {
		makeOutputWidget(me.baseGui, "from setThingsOnTop()")
	}
	if me.stdout.tk == nil {
		return
	}
	if me.stdout.tk.v == nil {
		return
	}
	if me.dark {
		me.stdout.tk.v.FgColor = gocui.ColorWhite
		me.stdout.tk.v.BgColor = gocui.ColorBlack
	} else {
		me.stdout.tk.v.FgColor = gocui.ColorBlack
		me.stdout.tk.v.BgColor = gocui.AttrNone
	}

	if me.stdout.outputOnTop {
		me.baseGui.SetViewOnTop("msg")
	} else {
		me.baseGui.SetViewOnBottom("msg")
	}
	if me.stdout.startOnscreen {
		// log.Info("THIS TRIGGERS STDOUT") // todo: make a proper init() & move this there
		me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
		me.stdout.startOnscreen = false
	}
	setBottomBG()
}

func setBottomBG() {
	// this attempts to find the "BG" widget and set it to the background on the very very bottom
	rootTK := me.treeRoot.TK.(*guiWidget)
	if tk := rootTK.findBG(); tk != nil {
		// log.Info("found BG. setting to bottom", tk.cuiName)
		if me.dark {
			tk.v.BgColor = gocui.ColorBlack
		} else {
			tk.v.BgColor = gocui.ColorWhite
		}
		tk.v.Clear()
		me.baseGui.SetViewOnBottom(tk.cuiName)
		w, h := me.baseGui.Size()
		me.baseGui.SetView(tk.cuiName, -1, -1, w+1, h+1, 0)
	}
}