summaryrefslogtreecommitdiff
path: root/toolkit/nocui/stdin.go
blob: 98285c0ebffcc6600b09d9d11eab3c933da90ad1 (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
package main

import (
	"os"
	"fmt"
	"bufio"
	"strings"
	"strconv"

	"go.wit.com/gui/toolkit"
)

func simpleStdin() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		s := scanner.Text()
		s = strings.TrimSuffix(s, "\n")
		switch s {
		case "l":
			log(true, "list widgets")
			me.rootNode.listWidgets()
		case "b":
			log(true, "show buttons")
			me.rootNode.showButtons()
		case "d":
			var a toolkit.Action
			a.ActionType = toolkit.EnableDebug
			callback <- a
		case "":
			fmt.Println("")
			fmt.Println("Enter:")
			fmt.Println("'l': list all widgets")
			fmt.Println("'b': for buttons")
			fmt.Println("'d': enable debugging")
		default:
			i, _ := strconv.Atoi(s)
			log(true, "got input:", i)
			n := me.rootNode.findWidgetId(i)
			if (n != nil) {
				n.dumpWidget("found node")
				n.doUserEvent()
			}
		}
	}
}

func (n *node) showButtons() {
	if n.WidgetType == toolkit.Button {
		n.dumpWidget("Button:")
	}

	for _, child := range n.children {
		child.showButtons()
	}
}

func (n *node) dumpWidget(pad string) {
	log(true, "node:", pad, n.WidgetId, ",", n.WidgetType, ",", n.Name)
}

var depth int = 0

func (n *node) listWidgets() {
	if (n == nil) {
		return
	}

	var pad string
	for i := 0; i < depth; i++ {
		pad = pad + "    "
	}
	n.dumpWidget(pad)

	for _, child := range n.children {
		depth += 1
		child.listWidgets()
		depth -= 1
	}
	return
}