-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (51 loc) · 1.87 KB
/
main.go
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
// Copyright (c) 2018, Mark "Happy-Ferret" Bauermeister
//
// This software may be modified and distributed under the terms
// of the BSD license. See the LICENSE file for details.
// Example input shows how to use an Input prompt from the prompt pacakge.
package main
import (
"log"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/keybind"
"github.com/BurntSushi/xgbutil/xevent"
"github.com/BurntSushi/xgbutil/xwindow"
"github.com/Anima-OS/Wonderland/prompt"
)
// response is the callback that gets executed whenever the user hits
// enter (the "confirm" key). The text parameter contains the string in
// the input box.
func response(inp *prompt.Input, text string) {
// If you type my name, we exit!
if text == "Andrew" {
println("You have the same name as me! Bye!")
canceled(inp)
return
}
println("Hello " + text + "!")
}
// canceled is the callback that gets executed whenever the prompt is canceled.
// This can occur when the user presses escape (the "cancel" key).
func canceled(inp *prompt.Input) {
xevent.Quit(inp.X)
}
func main() {
X, err := xgbutil.NewConn()
if err != nil {
log.Fatalln(err)
}
// The input box uses the keybind module, so we must initialize it.
keybind.Initialize(X)
// Creating a new input prompt is as simple as supply an X connection,
// a theme and a configuration. We use built in defaults here.
inpPrompt := prompt.NewInput(X,
prompt.DefaultInputTheme, prompt.DefaultInputConfig)
// Show maps the input prompt window and sets the focus. It returns
// immediately, and the main X event loop is started.
// Also, we use the root window geometry to make sure the prompt is
// centered in the middle of the screen. 'response' and 'canceled' are
// callback functions. See their respective commends for more details.
inpPrompt.Show(xwindow.RootGeometry(X),
"What is your name?", response, canceled)
xevent.Main(X)
}