Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blessed: Make a log widget scrollable

I'm using the Blessed library to make a dashboard in the terminal.

I'm logging things into a log widget, and would like to make the widget scrollable. With the below code, the scrollbar is appearing, but I can't actually scroll using my mouse wheel, or by dragging the scroll bar.

var logPanel = blessed.log({
    top: '0',
    left: '0',
    width: '60%',
    height: '100%',
    tags: true,
    border: {
        type: 'line'
    },
    scrollable: true,
    alwaysScroll: true,
      scrollbar: {
        ch: ' ',
        inverse: true
    },
    style: {
        fg: 'green',
        bg: 'black',
        border: {
            fg: '#f0f0f0'
        }
    }
});

How can I get the scroll working?

like image 339
Rich Avatar asked Mar 09 '17 12:03

Rich


1 Answers

According to Blessed's documentation, there are three ways to scroll that you can enable by setting corresponding properties to true in your options object:

  • mouse - Whether to enable automatic mouse support for this element [scrollwheel]
  • keys - Use predefined keys for navigating the text [arrow keys]
  • vi - Use vi keys with the keys option [j/k keys]

(as found in the deprecated ScrollableBox, but applicable to a plain box too)

I had some trouble figuring this out myself from the docs. I guess sometimes if there's a lot of text it doesn't means it's good.

Another problem that you might encounter if that once a box overflows with text, it doesn't scrolls automatically. You need to enable that yourself by calling setScrollPerc(100) function on you Box object right after you add a new line.

like image 74
Almighty Baka Avatar answered Sep 29 '22 08:09

Almighty Baka