Blessed Tab Container

1.0.0 · maintenance · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

This example demonstrates setting up two `blessed-tab-container` instances within a `blessed-contrib` grid, populating them with simple `blessed.element` components, and programmatically setting the visible tab. It shows basic initialization and interaction.

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()

view raw JSON →