-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblessed-simpleform.js
88 lines (78 loc) · 1.2 KB
/
blessed-simpleform.js
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
// jshint esversion: 8
var blessed = require("blessed");
var screen = blessed.screen();
var form = blessed.form({
parent: screen,
keys: true,
left: 0,
top: 0,
width: 30,
height: 4,
bg: "green",
fg: "black",
content: "Submit or Cancel ?"
});
var submit = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 10,
top: 2,
name: "submit",
content: "Submit",
style: {
bg: "blue",
focus: {
bg: "red"
},
hover: {
bg: "red"
}
}
});
var cancel = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 20,
top: 2,
name: "cancel",
content: "Cancel",
style: {
bg: "blue",
focus: {
bg: "red"
},
hover: {
bg: "red"
}
}
});
submit.on("press", function() {
form.submit();
});
cancel.on("press", function() {
form.reset();
});
form.on("submit", function(data) {
form.setContent("Sumitted.");
screen.render();
});
form.on("reset", function(data) {
form.setContent("Canceled.");
screen.render();
});
screen.key("q", function () {
process.exit(0);
});
screen.render();