Blessed Tab Container
blessed-tab-container is a specialized UI component designed for the `blessed` command-line interface (CLI) library, enabling developers to create multi-tabbed user interfaces within terminal applications. As of version `1.0.0`, it provides a stable API for managing tabbed content. The package indicates tab 'dirty' states, a key differentiator, by modifying tab labels, along with configurable styling options for active and dirty tabs. Released over 6 years ago, it suggests a mature and stable API without a rapid release cadence. It extends `blessed` functionality by integrating tab navigation directly into the `blessed` screen's label mechanism, offering a unique approach compared to other potential custom container implementations.
Common errors
-
ReferenceError: require is not defined in ES module scope
cause Attempting to use `require()` in an ES module file (e.g., `type: 'module'` in package.json or `.mjs` file).fixEnsure your file is treated as CommonJS (e.g., `.js` file without `type: 'module'` in `package.json`). For `blessed-tab-container@1.0.0`, direct ESM imports are not supported. Stick to CommonJS `require()`. -
TypeError: BlessedTabContainer is not a function
cause Incorrect import statement, typically trying to use named import syntax (`import { BlessedTabContainer } from 'blessed-tab-container'`) instead of default import for a CommonJS module that exports a function.fixIf using CommonJS, ensure `const BlessedTabContainer = require('blessed-tab-container')` is used. If attempting ESM with a bundler, ensure it handles default CJS exports correctly, e.g., `import BlessedTabContainer from 'blessed-tab-container'` after appropriate transpilation/bundling.
Warnings
- gotcha The `blessed` ecosystem, including `blessed-tab-container`, largely predates widespread native ESM support in Node.js. This package is primarily CommonJS, and direct `import` statements will likely fail without a transpiler or ESM loader.
- gotcha The `blessed` library, on which this package depends, has not been actively maintained by its original author (chjj) since around 2016. While `blessed-tab-container` is stable, the underlying `blessed` library itself may have unaddressed bugs or compatibility issues with newer terminal features.
- gotcha The package was last published 6 years ago. While stable at `1.0.0`, lack of recent updates means it may not fully leverage modern JavaScript features, `blessed` advancements (e.g., in `neo-blessed`), or address security concerns found in older dependencies.
Install
-
npm install blessed-tab-container -
yarn add blessed-tab-container -
pnpm add blessed-tab-container
Imports
- BlessedTabContainer
import BlessedTabContainer from 'blessed-tab-container'
const BlessedTabContainer = require('blessed-tab-container') - screen
import { screen } from 'blessed'const blessed = require('blessed'); const screen = blessed.screen({ smartCSR: true });
Quickstart
const BlessedTabContainer = require('blessed-tab-container')
const blessed = require('blessed')
const blessedContrib = require('blessed-contrib')
const colors = require('colors')
const screen = blessed.screen({ smartCSR: true })
screen.enableInput()
screen.key(['escape', 'q', 'C-c'], () => {
screen.destroy()
process.exit(0)
})
const grid = new blessedContrib.grid({
screen: screen,
rows: 1,
cols: 2
})
const tabGroupA = []
const tabGroupB = []
for (let i = 0; i < 2; i += 1) {
tabGroupA.push(grid.set(0, 0, 1, 1, blessed.element, {
content: `Content for Tab ${i + 1}`
}))
}
for (let i = 0; i < 5; i += 1) {
tabGroupB.push(grid.set(0, 1, 1, 1, blessed.element, {
content: `Content for Tab ${i + 1}`
}))
}
const tabContainerSettings = {
screen,
tabSeperator: ' | ',
activeColorFunc: colors.bgBrightBlue.black,
dirtyColorFunc: colors.underline
}
const tabContainerA = BlessedTabContainer({
...tabContainerSettings,
defaultVisible: 'Tab 1',
tabs: tabGroupA.map((t, i) => ({
label: `Tab ${i + 1}`,
component: t
}))
})
const tabContainerB = BlessedTabContainer({
...tabContainerSettings,
defaultVisible: 'Tab 1',
tabs: tabGroupB.map((t, i) => ({
label: `Tab ${i + 1}`,
component: t
}))
})
// Do something with the containers
tabContainerA.setVisibleTab('Tab 2')
tabContainerB.setVisibleTab('Tab 4')
screen.render()