mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
## Why Status line authors can start rows at the leading edge or distribute extra space between items. They also need to center or right-align a group while keeping its configured gaps. ## What changed Add `justify: "center"` and `justify: "end"` to the row renderer and TypeScript contract. Align each wrapped line independently within its available width. Leading padding uses the row background, stays outside hyperlink targets, and leaves blank lines unpainted. When the last visible line fills the width and more lines follow, the renderer can reclaim a padding cell for the overflow ellipsis. ## Testing Add rendering coverage for wrapped and nested rows, wide characters, blank lines, hyperlink boundaries, and overflow. Extend the TypeScript contract check to cover both new values. GitOrigin-RevId: 85dd907fe60b5d2cfb759b32058d0876430dd9e6
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import type {
|
|
Color,
|
|
RowElement,
|
|
StatuslineItemId,
|
|
StatuslineState,
|
|
UiTree,
|
|
} from "../../../../skills/src/assets/samples/create-statusline/references/statusline.js";
|
|
|
|
// Typecheck a provider as an author would: the snapshot arrives over JSON, and
|
|
// each returned element is sent as resource text.
|
|
export function render(state: StatuslineState): UiTree {
|
|
const children: UiTree[] = [];
|
|
const text = (value: string): UiTree => ({ type: "text", children: [value] });
|
|
const { account, config, thread } = state;
|
|
if (config.statusline_items.includes("model")) {
|
|
children.push({
|
|
type: "text",
|
|
props: { color: "status-model", weight: "bold" },
|
|
children: [thread.model.display_name],
|
|
});
|
|
}
|
|
|
|
const workspace = account.workspace?.headline;
|
|
if (workspace) {
|
|
children.push({ type: "italic", children: [workspace] });
|
|
}
|
|
const window = account.rate_limits[0]?.primary_limit;
|
|
if (window && window.resets_at !== null) {
|
|
children.push(
|
|
text(`${window.used_percent}% until ${new Date(window.resets_at * 1_000).toISOString()}`),
|
|
);
|
|
}
|
|
if (thread.usage.total) {
|
|
children.push(text(String(thread.usage.total.output_tokens)));
|
|
}
|
|
if (config.statusline_items.includes("current-dir")) {
|
|
children.push(text(thread.workspace.cwd));
|
|
}
|
|
if (children.length === 0) {
|
|
return null;
|
|
}
|
|
return { type: "row", props: { gap: 1, wrap: "wrap", justify: "between" }, children };
|
|
}
|
|
|
|
// @ts-expect-error The snapshot emits the canonical ID even when config used an alias.
|
|
const alias: StatuslineItemId = "project-root";
|
|
// @ts-expect-error Row props require a gap in terminal columns.
|
|
const missingGap: RowElement = { type: "row", props: {}, children: [] };
|
|
// @ts-expect-error Color literals begin with a hash or match one of the named tokens.
|
|
const invalidColor: Color = "ff00bb";
|
|
|
|
const groupedPositions: RowElement["props"]["justify"][] = ["center", "end"];
|