opentui

Build terminal UIs with OpenTUI. Covers Core, frameworks, components, application APIs, testing, extensions, integrations, deployment, and public API lookup.

Install
npx skills add 'https://github.com/anomalyco/opentui/tree/main/packages/web/src/content'
Download bundle ↓
main · ac753b4Scanned 2026-09-15

Contributors

GitHub-linked commit authors for this SKILL.md at the saved revision. Co-authors and history before file renames are not included.

File history ↗

docs/components/line-number.mdx

docs/components/line-number.mdxBrowse 89 files
View on GitHub
← Back to SKILL.md

title: Line number gutter description: Add a line number gutter to code and editor renderables

Line number gutter

LineNumberRenderable adds a gutter to a renderable that supplies line information. Use it with Code or an editor. Diff manages its own line-number gutters.

Availability

FieldAvailability
Package@opentui/core
Core renderableLineNumberRenderable
React<line-number> (automatic)
Solid<line_number> is runtime built in. Its exact props declaration is missing.
StatusBuilt in with a Solid typing limitation

Basic usage

Renderable API

import {
  CodeRenderable,
  LineNumberRenderable,
  ScrollBoxRenderable,
  SyntaxStyle,
  RGBA,
  createCliRenderer,
} from "@opentui/core"

const renderer = await createCliRenderer()

const syntaxStyle = SyntaxStyle.fromStyles({
  default: { fg: RGBA.fromHex("#E6EDF3") },
})

const code = new CodeRenderable(renderer, {
  id: "code",
  content: "const port = 3000\nserve(port)\nawait ready()",
  filetype: "typescript",
  syntaxStyle,
  width: "100%",
})

const lineNumbers = new LineNumberRenderable(renderer, {
  id: "code-lines",
  target: code,
  minWidth: 3,
  paddingRight: 1,
  fg: "#6b7280",
  bg: "#161b22",
})

const scrollbox = new ScrollBoxRenderable(renderer, {
  id: "scrollbox",
  width: 70,
  height: 18,
})

lineNumbers.setLineSign(1, { before: ">" })
scrollbox.add(lineNumbers)
renderer.root.add(scrollbox)
  1 const port = 3000
> 2 serve(port)
  3 await ready()

Line signs and colors

Set a single background for a line, or split gutter and content colors separately with a LineColorConfig object:

// Shorthand: applies the color to the gutter and a 20%-darker color to the content
lineNumbers.setLineColor(3, "#2b6cb0")

// Split config: different gutter vs content background
lineNumbers.setLineColor(3, {
  gutter: "#2b6cb0",
  content: "#1f2937",
})

lineNumbers.setLineSign(3, { before: ">", beforeColor: "#2b6cb0" })

// Clear
lineNumbers.clearLineColor(3)
lineNumbers.clearLineSign(3)

The shorthand color becomes the gutter background. The content background uses the same color darkened by 20%. A LineColorConfig with only gutter uses the same darkening rule.

Theming the gutter

Gutter text and background colors accept assignments after construction:

lineNumbers.fg = "#6b7280"
lineNumbers.bg = "#161b22"

Assign undefined to reset to the defaults (#888888 foreground, transparent background).

Initial visibility

The constructor currently ignores the showLineNumbers option. Set the property after construction when the initial gutter must be hidden:

const lineNumbers = new LineNumberRenderable(renderer, { target: code })
lineNumbers.showLineNumbers = false

Properties

PropertyTypeDefaultDescription
targetRenderable & LineInfoProvider-Target renderable to number
fgstring or RGBA#888888Gutter text color
bgstring or RGBAtransparentGutter background color
minWidthnumber3Minimum gutter width
paddingRightnumber1Right padding for gutter
lineColorsMap<number, string | RGBA | LineColorConfig>-Per-line background colors
lineSignsMap<number, LineSign>-Per-line signs (before/after)
lineNumberOffsetnumber0Offset for line numbering
hideLineNumbersSet<number>-Lines to hide numbers for
lineNumbersMap<number, number>-Override line numbers per line
showLineNumbersbooleantrueToggle gutter visibility

Methods

MethodDescription
setLineColor()Set a background color for a line
clearLineColor()Clear a line background color
setLineSign()Set a sign before/after a line number
clearLineSign()Clear a line sign
setLineNumbers()Override multiple line numbers
setHideLineNumbers()Hide line numbers for specific lines

Use Code as a syntax-highlighted target. Use Diff when you need patch parsing and paired gutters. Markdown owns fenced code blocks. TextTable displays rows and columns without line semantics.