#13722·oh-my-pi

ComposerStyle.renderTop cannot return multiple rows: Editor.render embeds the newline in a single buffer row

Author: 865x44Created Sep 29, 2026Updated Oct 1, 2026
Labelsenhancementtuitriaged

Summary

Editor.render pushes the return value of ComposerStyle.renderTop into the frame buffer as a single row. A style whose renderTop returns a string containing \n therefore does not produce two rows — it produces one row with an embedded newline, which corrupts the composited frame.

This is surprising because verticalChrome: 0 | 1 | 2 is explicitly typed as "Rows consumed by top+bottom chrome", i.e. the ComposerStyle contract already admits multi-row top chrome. renderTop just cannot express it.

Steps to reproduce

typescript
import { getEditorTheme } from "@oh-my-pi/pi-tui";
import { Editor } from "@oh-my-pi/pi-tui/components/editor";
import { getComposerStyle } from "@oh-my-pi/pi-tui/components/composer/registry";

// Stock `rule` style: correct, one row.
const stock = new Editor(getEditorTheme());
stock.setBorderStyle("rule");
stock.setTopBorder({ content: "workflow", width: 8, revision: 1 });
console.log(stock.render(40).length); // 2

// A style that wants the status text on one row and the rule on the next.
const style = getComposerStyle("rule");
style.renderTop = ctx => `workflow\n${ctx.borderColor(ctx.box.horizontal.repeat(ctx.width))}`;

const editor = new Editor(getEditorTheme());
editor.setBorderStyle("rule");
editor.setTopBorder({ content: "workflow", width: 8, revision: 1 });
const rows = editor.render(40);
console.log(rows.length);              // 2, not 3
console.log(rows[0].includes("\n"));   // true — the newline is inside the row

Actual

Row 0 is "workflow\n─────…" — one buffer row holding an embedded newline, so the rule is not a separate line. Downstream consumers diff and compose rows, so the embedded newline either truncates or shifts subsequent rows.

Expected

renderTop returning two logical lines yields three rows, or the contract is documented to forbid newlines and verticalChrome: 2 becomes unreachable from renderTop alone.

Suggested fix

packages/tui/src/components/editor.ts, in render:

typescript
const topRow = style.renderTop(chromeCtx);
if (topRow !== undefined) result.push(topRow);

becomes

typescript
const topRow = style.renderTop(chromeCtx);
if (topRow !== undefined) {
  for (const line of topRow.split("\n")) result.push(line);
}

The same call site exists on the composer-preview path, which needs the same treatment. verticalChrome already budgets these rows, so no height math moves.

Impact

Currently only affects styles that return multi-row top chrome — none of the built-in ones do, so this is latent. It blocks extension-provided composer styles (see registerComposerStyle) from using the shape verticalChrome: 2 was defined for, forcing workarounds that cram a rule and its label onto one row.

Environment

@oh-my-pi/pi-coding-agent 18.4.3