diff options
| author | Jeff Carr <[email protected]> | 2023-04-27 22:21:31 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-04-27 22:21:31 -0500 |
| commit | a1deb9845593e211a1ce6fe4a7f88bbe5acd9981 (patch) | |
| tree | e355d637606f34b2a17da4e9d84292596e175166 /toolkit/nocui/stdin.go | |
| parent | 87b62c98a6ebd9d0e48850d1710de7f39aba41c8 (diff) | |
nocui: simulates button clicks
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/nocui/stdin.go')
| -rw-r--r-- | toolkit/nocui/stdin.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/toolkit/nocui/stdin.go b/toolkit/nocui/stdin.go new file mode 100644 index 0000000..ed71206 --- /dev/null +++ b/toolkit/nocui/stdin.go @@ -0,0 +1,76 @@ +package main + +import ( + "os" + "fmt" + "bufio" + "strings" + "strconv" + + "git.wit.org/wit/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") + rootNode.listWidgets() + case "b": + log(true, "show buttons") + rootNode.showButtons() + case "": + fmt.Println("") + fmt.Println("Enter:") + fmt.Println("'l': list all widgets") + fmt.Println("'b': for buttons") + fmt.Println("") + default: + i, _ := strconv.Atoi(s) + log(true, "got input:", i) + n := 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 +} |
