JanDeDobbeleer/oh-my-posh · warning
terminal width must be greater than zero
Error message
terminal width must be greater than zero
What it means
resolveTerminalWidth parses the COLUMNS environment variable (via the shell) into a terminal width. The shared terminalErr covers failures, and this specific error is joined onto it when the parsed value is zero or negative, since a non-positive width would break prompt rendering math. It means the width source supplied a nonsensical value.
Source
Thrown at src/runtime/terminal_unix.go:90
}
term.CmdFlags.TerminalWidth = int(width)
log.Debugf("terminal width: %d", term.CmdFlags.TerminalWidth)
return term.CmdFlags.TerminalWidth, err
}
func resolveTerminalWidth(width uint, terminalErr error, columns string) (uint, error) {
if width != 0 {
return width, terminalErr
}
columnWidth, err := strconv.Atoi(columns)
if err != nil {
return 0, errors.Join(terminalErr, err)
}
if columnWidth <= 0 {
return 0, errors.Join(terminalErr, errors.New("terminal width must be greater than zero"))
}
return uint(columnWidth), nil
}
func (term *Terminal) Platform() string {
const key = "environment_platform"
if val, found := cache.Device.Get[string](key); found {
return val
}
var platform string
defer func() {
cache.Device.Set(key, platform, cache.INFINITE)
}()
if wsl := term.Getenv("WSL_DISTRO_NAME"); len(wsl) != 0 {
platform, _, _ = strings.Cut(wsl, "-")View on GitHub (pinned to 0976794618)
Solutions
- Check the COLUMNS value in the shell where the prompt renders: `echo $COLUMNS` — unset or fix it if 0/negative.
- Remove any `export COLUMNS=...` from shell startup files that sets a bogus value.
- Run the prompt in a real TTY so COLUMNS reflects actual terminal size.
- Update oh-my-posh if you need different fallback behavior for missing/invalid COLUMNS.
Example fix
// before (shell rc) export COLUMNS=0 // after: let oh-my-posh/tput detect width, or set a positive value export COLUMNS=120
Defensive patterns
Strategy: validation
Validate before calling
// validate before rendering
cols := os.Getenv("COLUMNS")
if n, err := strconv.Atoi(cols); err != nil || n <= 0 {
cols = "80" // safe fallback
} Type guard
func validWidth(s string) bool {
n, err := strconv.Atoi(s)
return err == nil && n > 0
} Try / catch
w, err := term.TerminalWidth()
if err != nil {
w = 80 // default width fallback
} Prevention
- Never export COLUMNS=0 or negative values in shell startup files.
- Verify `echo $COLUMNS` in the shell used for prompt rendering.
- Render in a real TTY so COLUMNS reflects the actual terminal size.
When it happens
Trigger: TerminalWidth (or an anonymous helper wrapping it) read a COLUMNS value that parsed to <= 0, e.g. COLUMNS=0 or COLUMNS=-1, on unix systems.
Common situations: Non-interactive shells or CI environments exporting COLUMNS=0; badly configured shell startup scripts exporting COLUMNS; tmux/screen edge cases; running under a wrapper that fakes terminal size.
Related errors
- environment access is disabled: rendering from recorded data
- failed to get shell config path: %w
- failed to get home directory
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/6cb03d40d7fcd0ad.
Report an issue: GitHub.