-
Notifications
You must be signed in to change notification settings - Fork 0
npm Package
Alex Neamtu edited this page Jan 16, 2026
·
1 revision
The htoprc parser is available as a standalone npm package for use in your own projects.
npm install @htoprc/parser
# or
pnpm add @htoprc/parser
# or
yarn add @htoprc/parser- Parse htoprc files into typed TypeScript objects
- Serialize config objects back to htoprc format
- Support for htop 2.x and 3.x config formats
- Zero runtime dependencies
- Full TypeScript support
import { parseHtoprc } from '@htoprc/parser'
import { readFileSync } from 'fs'
const content = readFileSync('~/.config/htop/htoprc', 'utf-8')
const result = parseHtoprc(content)
console.log(result.config.colorScheme) // 0-6
console.log(result.config.treeView) // true/false
console.log(result.config.leftMeters) // [{ type: 'CPU', mode: 'bar' }, ...]
console.log(result.version) // 'v3' | 'v2' | 'unknown'
console.log(result.warnings) // Any parsing warningsimport { serializeHtoprc, parseHtoprc } from '@htoprc/parser'
const result = parseHtoprc(content)
// Modify the config
result.config.colorScheme = 5
result.config.treeView = true
// Serialize back to htoprc format
const output = serializeHtoprc(result.config)
// Write to ~/.config/htop/htoprcParses an htoprc configuration string.
Returns:
interface ParseResult {
config: HtopConfig // Parsed configuration
warnings: ParseWarning[] // Non-fatal parsing issues
errors: ParseError[] // Fatal parsing errors
version: 'v2' | 'v3' | 'unknown'
score: number // Config customization score
}Serializes an HtopConfig object back to htoprc format.
Options:
interface SerializeOptions {
includeVersion?: boolean // Include htop_version (default: true)
onlyNonDefaults?: boolean // Only non-default options (default: false)
includeUnknown?: boolean // Include unknown options (default: true)
}The default htoprc configuration values. Useful for comparison or creating new configs.
The main configuration interface includes:
| Category | Properties |
|---|---|
| Display |
colorScheme, headerLayout, showProgramPath, highlightBaseName, etc. |
| Meters |
leftMeters, rightMeters
|
| Process List |
columns, sortKey, sortDirection, treeView
|
| Threading |
hideKernelThreads, hideUserlandThreads
|
| Screens |
screens (htop 3.x screen definitions) |
interface Meter {
type: string // e.g., 'CPU', 'Memory', 'LoadAverage'
mode: MeterMode // 'bar' | 'text' | 'graph' | 'led'
}Supported layouts:
-
two_50_50(default) -
two_33_67,two_67_33 -
three_33_34_33,three_25_25_50,three_25_50_25,three_50_25_25 four_25_25_25_25
- Dotfiles managers - Parse and validate htoprc in dotfiles tools
- Config generators - Generate htoprc programmatically
- Visualization tools - Build htop config previewers
- Migration scripts - Convert between htop versions
- Backup tools - Extract and store htop settings