How to use the form function from blessed

Find comprehensive JavaScript blessed.form code examples handpicked from public code repositorys.

blessed.form is a constructor function in the Blessed library that creates a new form element for use in a Blessed screen.

1
2
3
4
5
6
7
8
9
10

const blessed = require('blessed'),
      os      = require('os');

function login_form(screen, kube_config, kubebox, { closable } = { closable: false }) {
  const form = blessed.form({
    name      : 'form',
    screen    : screen,
    keys      : true,
    clickable : true,
fork icon148
star icon0
watch icon1

6
7
8
9
10
11
12
13
14
15
16
class SetupWizard {
  constructor() {
    this.resolve = null;
    this.screen = blessed.screen();


    this.form = blessed.form({
      parent: this.screen,
      interactive: true,
      keys: true,
      mouse: true,
fork icon7
star icon25
watch icon5

+ 7 other calls in file

How does blessed.form work?

blessed.form is a constructor function provided by the blessed library in Node.js that creates a container widget for a form interface, allowing users to input information into pre-defined fields, and submit or cancel those changes.

110
111
112
113
114
115
116
117
118
119
  , border: {type:'line', bg:17}
  , style: {bg: 17, label: {bg: 17}}
};

function dialog(options, buttons, cb) {
    var dialogElem = blessed.form(combine(dialogOptions, options));
    dialogElem.data.isDialog = true;

    var done = function(data) {
        if (cb(data) || !data) detach(dialogElem)
fork icon2
star icon25
watch icon6

124
125
126
127
128
129
130
131
132
133
  mouse: true,
  tags: true,
  fg: 'white'
})

var form = blessed.form({
  parent: container,
  keys: true,
  left: 0,
  bottom: 0,
fork icon2
star icon18
watch icon11

Ai Example

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
const blessed = require("blessed");

// Create a new screen object
const screen = blessed.screen({
  smartCSR: true,
});

// Create a new form object
const form = blessed.form({
  parent: screen,
  keys: true,
  left: "center",
  top: "center",
  width: "50%",
  height: "50%",
  bg: "black",
  content: "Please enter your information:",
  border: {
    type: "line",
  },
  style: {
    fg: "white",
    border: {
      fg: "#f0f0f0",
    },
  },
});

// Add form elements
const nameLabel = blessed.text({
  parent: form,
  left: 2,
  top: 2,
  content: "Name:",
});

const nameInput = blessed.textbox({
  parent: form,
  left: 8,
  top: 2,
  width: 30,
  height: 1,
  inputOnFocus: true,
  name: "name",
});

const emailLabel = blessed.text({
  parent: form,
  left: 2,
  top: 4,
  content: "Email:",
});

const emailInput = blessed.textbox({
  parent: form,
  left: 8,
  top: 4,
  width: 30,
  height: 1,
  inputOnFocus: true,
  name: "email",
});

const submitButton = blessed.button({
  parent: form,
  left: 2,
  bottom: 2,
  content: "Submit",
  style: {
    fg: "white",
    bg: "blue",
    focus: {
      bg: "green",
    },
  },
});

// Bind form events
form.on("submit", (data) => {
  // Log the form data when the submit button is pressed
  console.log(data);
});

form.on("reset", () => {
  // Reset the form when the reset button is pressed
  nameInput.setValue("");
  emailInput.setValue("");
  nameInput.focus();
});

// Focus the name input when the form is first rendered
nameInput.focus();

// Render the screen and form
screen.render();

This creates a form with two textboxes for the user to enter their name and email, and a submit button to submit the form data. The form data is logged to the console when the submit button is pressed, and the form is reset when the reset button is pressed.

22
23
24
25
26
27
28
29
30
31
  height: '10%',
  border: theme.header.border,
  style: theme.header.style,
});

const searchBox = blessed.form({
  parent: screen,
  top: 0,
  left: '30%+1',
  width: '70%',
fork icon1
star icon4
watch icon2

+ 9 other calls in file

9
10
11
12
13
14
15
16
17
18
 * @return {blessed.Node}
 */
module.exports = function Prompt(text, parent) {
  text = text + ' ';

  var form = new blessed.form({
    top: 'center',
    left: 'center',
    content: text,
    align: 'left',
fork icon0
star icon3
watch icon3

290
291
292
293
294
295
296
297
298
299
  parent: taskScreen,
  style: theme.TEXT_STYLING,
  height: 1,
  orientation: "horizontal"
});
const taskActions = blessed.form({
  parent: taskScreen,
  left: 0,
  bottom: 0,
  height: 5,
fork icon1
star icon1
watch icon0

+ 2 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
  };
};


exports.formImpl = function(options) {
  return function(){
    return blessed.form(options);
  };
};


exports.textboxImpl = function(options) {
fork icon0
star icon10
watch icon0

48
49
50
51
52
53
54
55
56
57
  left: 'center',
  keys: true,
  vi: true
});

this.messageForm = blessed.form({
  parent: this.form,
  width: '100%',
  left: 'center',
  bottom: 4
fork icon0
star icon1
watch icon0

+ 3 other calls in file

175
176
177
178
179
180
181
182
183
184





var ircform = blessed.form({
  title: 'ircform',
  // input:true,
  keys: true,
  left: 0,
fork icon3
star icon0
watch icon3

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382










var barform = blessed.form({
  name: 'barform',
  // parent:barbox,
  // input:true,
  keys: true,
fork icon3
star icon0
watch icon0

50
51
52
53
54
55
56
57
58
59
60
  bg: 'blue',
  tags: true,
  content: ' {cyan-fg}<Up/Down>{/cyan-fg} moves | {cyan-fg}<Enter>{/cyan-fg} selects | {cyan-fg}<q>{/cyan-fg} exits'
});


var inner = blessed.form({
  top: 'center',
  left: 'center',
  mouse: true,
  keys: true,
fork icon2
star icon8
watch icon0

+ 2 other calls in file

711
712
713
714
715
716
717
718
719
720
static screen = blessed.screen({
  smartCSR: true,
  title: 'utility scripts',
});

static pageChooseScriptForm = blessed.form({
  parent: RootElements.screen,
  width: '100%',
  padding: {
    left: 1,
fork icon1
star icon20
watch icon0

299
300
301
302
303
304
305
306
307
308

UI.edit['Cancel'] = UI.buttonfunc.make('Cancel', UI.modal.box, -5 - lang.buttonApply.length, -1, lang.buttonCancel, '#400040');

UI.edit['Close'] = UI.buttonfunc.make('Close', UI.modal.box, -2, -1, lang.buttonApply, 'blue');

UI.modal.box.list = blessed.form({
  parent: UI.modal.box,
  scrollable: true,
  top: 4,
  left: 0,
fork icon0
star icon0
watch icon1

+ 2 other calls in file

149
150
151
152
153
154
155
156
157
158
159
    style: {
        bg: 'black'
    }
});


var form_1 = blessed.form({
    parent: screen,
    keys: true, 
    top: '5%',
    left: '70%',
fork icon0
star icon0
watch icon1

+ 7 other calls in file

695
696
697
698
699
700
701
702
703
704
705
706
707


position.left = 30; // hack
addHorizontalLine(rootLayout, position);


position.left = 30; // hack
var collectionsContainer = blessed.form(HorizontalContainerDefinition);


// collectionsContainer.on("element click", (element, mouse) => {
//   collections.forEach(c => c.uiContainer.emit("clickOutside"));

fork icon0
star icon0
watch icon1

+ 32 other calls in file

131
132
133
134
135
136
137
138
139
140
position.left = 0;

const domainSuperContainerPosition = {...position};

/* TODO abstract away (must it be a form?) */
this.domainSuperContainer = blessed.form({
	...DomainSuperContainerDefinition,
	parent: this.layout,
	...domainSuperContainerPosition,
});
fork icon0
star icon0
watch icon1

+ 14 other calls in file

7
8
9
10
11
12
13
14
15
16
17
const screen = tui.screen({
    smartCSR: true,
    dockBorders: true
});


const form = tui.form({
    top: "0",
    left: "0",
    width: "100%",
    height: "100%",
fork icon0
star icon0
watch icon1

26
27
28
29
30
31
32
33
34
35
36
let mainScreen = blessed.screen({
    smartCSR: true
});


// User login screen
let usernameForm = blessed.form(
{
    top: 'center',
    left: 'center',
    width: '50%',
fork icon0
star icon0
watch icon0

331
332
333
334
335
336
337
338
339
340
341
342
 * =====================| COMMIT PANE |===================== *
 * ========================================================= */


let commitLists = {};


let commitMenu = blessed.form({
    parent: menu,
    label: {
        'text': 'Commit',
        'side': 'left',
fork icon0
star icon0
watch icon0

+ 11 other calls in file