How to use the Message function from blessed

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

blessed.Message is a constructor function in the blessed library that creates a widget for displaying messages.

49
50
51
52
53
54
55
56
57
this.context.room.on('joinError', function (err) {
  // Log the error.
  logger.error('There was an error joining the room.');

  // Create a new blessed message box instance.
  var message = Blessed.Message();

  // Remove the loading screen.
  self.loading.stop();
fork icon24
star icon238
watch icon12

210
211
212
213
214
215
216
217
218
219
// Widget used to ask for phone number and code
data.promptBox = blessed.Prompt(data.getDefaultPopupStyle())
data.screen.append(data.promptBox)

// Widget used to show pop up read only messages
data.popup = blessed.Message(data.getDefaultPopupStyle())
data.screen.append(data.popup)
data.popup.hide()

// mgsBox holds the chat window instance for every chat
fork icon2
star icon32
watch icon2

+ 2 other calls in file

How does blessed.Message work?

blessed.Message is a widget provided by the blessed library that is used to display a message box with a title and a message, and it allows the user to close it by pressing a button or hitting a key. The blessed.Message constructor takes an object with various configuration options to customize the appearance and behavior of the message box.

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

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

// Create a message box
const msgBox = blessed.message({
  parent: screen,
  top: "center",
  left: "center",
  width: "50%",
  height: "shrink",
  border: "line",
  align: "center",
  valign: "middle",
  label: " Important Message ",
  tags: true,
  keys: true,
  hidden: true,
  style: {
    border: {
      fg: "white",
    },
    label: {
      fg: "white",
      bold: true,
    },
    bg: "black",
    focus: {
      border: {
        fg: "green",
      },
    },
  },
});

// Set message box text
msgBox.setLabel(" Important Message ");
msgBox.display(
  "This is an important message.\nPress Escape to close.",
  0,
  () => {
    // Close message box when Escape is pressed
    msgBox.hide();
  }
);

// Render the screen
screen.render();

This example creates a message box widget and displays a message with the label "Important Message". The widget is hidden by default, but can be displayed by calling the display method. The hide method can be used to hide the widget. The keys option enables keyboard events and the tags option allows the use of tags in the message.