Skip to content

Commit de26f3d

Browse files
x1hanclaude
andcommitted
feat: add forceMaxWidth config override
Allow users to explicitly apply maxWidth even when terminal width detection returns a smaller value, which helps in subprocess-driven statusline environments on Linux. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 64a8099 commit de26f3d

12 files changed

Lines changed: 68 additions & 32 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ After choosing a preset, you can turn individual elements on or off.
146146
### Manual Configuration
147147

148148
Edit `~/.claude/plugins/claude-hud/config.json` directly for advanced settings such as `colors.*`,
149-
`pathLevels`, `maxWidth`, threshold overrides, `display.timeFormat`, and `display.promptCacheTtlSeconds`. Running `/claude-hud:configure`
149+
`pathLevels`, `maxWidth`, `forceMaxWidth`, threshold overrides, `display.timeFormat`, and `display.promptCacheTtlSeconds`. Running `/claude-hud:configure`
150150
preserves those manual settings while still letting you change `language`, layout, and the common
151151
guided toggles.
152152

@@ -159,7 +159,8 @@ Chinese HUD labels are available as an explicit opt-in. English stays the defaul
159159
| `language` | `en` \| `zh` | `en` | HUD label language. English is the default; set `zh` to enable Chinese labels. |
160160
| `lineLayout` | string | `expanded` | Layout: `expanded` (multi-line) or `compact` (single line) |
161161
| `pathLevels` | 1-3 | 1 | Directory levels to show in project path |
162-
| `maxWidth` | number \| `null` | `null` | Optional fallback width used only when terminal width detection fails completely |
162+
| `maxWidth` | number \| `null` | `null` | Optional fallback width used when terminal width detection fails completely, or the explicit width when `forceMaxWidth` is enabled |
163+
| `forceMaxWidth` | boolean | `false` | Force claude-hud to use `maxWidth` even when a terminal width is detected; useful when subprocess width detection is inaccurate |
163164
| `elementOrder` | string[] | `["project","context","usage","promptCache","memory","environment","tools","agents","todos"]` | Expanded-mode element order. Omit entries to hide them in expanded mode. |
164165
| `display.mergeGroups` | string[][] | `[["context","usage"]]` | Expanded-mode groups that should share a line when adjacent. Set `[]` to disable merged lines. |
165166
| `gitStatus.enabled` | boolean | true | Show git branch in HUD |
@@ -329,7 +330,7 @@ Example fallback snapshot:
329330

330331
**Config not applying?**
331332
- Check for JSON syntax errors: invalid JSON silently falls back to defaults
332-
- Ensure valid values: `pathLevels` must be 1, 2, or 3; `lineLayout` must be `expanded` or `compact`; `maxWidth` must be a positive number
333+
- Ensure valid values: `pathLevels` must be 1, 2, or 3; `lineLayout` must be `expanded` or `compact`; `maxWidth` must be a positive number; `forceMaxWidth` must be a boolean
333334
- Delete config and run `/claude-hud:configure` to regenerate
334335

335336
**Git status missing?**

dist/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface HudConfig {
3737
showSeparators: boolean;
3838
pathLevels: 1 | 2 | 3;
3939
maxWidth: number | null;
40+
forceMaxWidth: boolean;
4041
elementOrder: HudElement[];
4142
gitStatus: {
4243
enabled: boolean;

dist/config.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/config.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/config.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/render/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/render/index.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/render/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface HudConfig {
7171
showSeparators: boolean;
7272
pathLevels: 1 | 2 | 3;
7373
maxWidth: number | null;
74+
forceMaxWidth: boolean;
7475
elementOrder: HudElement[];
7576
gitStatus: {
7677
enabled: boolean;
@@ -129,6 +130,7 @@ export const DEFAULT_CONFIG: HudConfig = {
129130
showSeparators: false,
130131
pathLevels: 1,
131132
maxWidth: null,
133+
forceMaxWidth: false,
132134
elementOrder: [...DEFAULT_ELEMENT_ORDER],
133135
gitStatus: {
134136
enabled: true,
@@ -413,6 +415,9 @@ export function mergeConfig(userConfig: Partial<HudConfig>): HudConfig {
413415
: null;
414416

415417
const elementOrder = validateElementOrder(migrated.elementOrder);
418+
const forceMaxWidth = typeof (migrated as Record<string, unknown>).forceMaxWidth === 'boolean'
419+
? (migrated as Record<string, unknown>).forceMaxWidth as boolean
420+
: DEFAULT_CONFIG.forceMaxWidth;
416421

417422
const gitStatus = {
418423
enabled: typeof migrated.gitStatus?.enabled === 'boolean'
@@ -575,7 +580,7 @@ export function mergeConfig(userConfig: Partial<HudConfig>): HudConfig {
575580
: DEFAULT_CONFIG.colors.custom,
576581
};
577582

578-
return { language, lineLayout, showSeparators, pathLevels, maxWidth, elementOrder, gitStatus, display, colors };
583+
return { language, lineLayout, showSeparators, pathLevels, maxWidth, forceMaxWidth, elementOrder, gitStatus, display, colors };
579584
}
580585

581586
export async function loadConfig(): Promise<HudConfig> {

src/render/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ export function render(ctx: RenderContext): void {
486486
const lineLayout = ctx.config?.lineLayout ?? 'expanded';
487487
const showSeparators = ctx.config?.showSeparators ?? false;
488488
const detectedWidth = getTerminalWidth({ preferEnv: true, fallback: UNKNOWN_TERMINAL_WIDTH });
489-
const terminalWidth = detectedWidth ?? ctx.config?.maxWidth ?? UNKNOWN_TERMINAL_WIDTH;
489+
const configuredMaxWidth = ctx.config?.maxWidth ?? UNKNOWN_TERMINAL_WIDTH;
490+
const terminalWidth = ctx.config?.forceMaxWidth && configuredMaxWidth !== UNKNOWN_TERMINAL_WIDTH
491+
? configuredMaxWidth
492+
: (detectedWidth ?? configuredMaxWidth ?? UNKNOWN_TERMINAL_WIDTH);
490493

491494
let lines: string[];
492495

0 commit comments

Comments
 (0)