47 lines
2.8 KiB
TypeScript
47 lines
2.8 KiB
TypeScript
// PEP-257: tmux's own status-format expansion → one SGR line on the pane width.
|
||
import assert from "node:assert/strict";
|
||
import { test } from "node:test";
|
||
import { charWidth, colourSgr, renderStatusLine } from "../../runner/src/tmux-status.ts";
|
||
|
||
const strip = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
||
// What tmux 3.3 prints for #{T:status-format[0]} of a session «demo» with defaults.
|
||
const DEFAULT =
|
||
'#[align=left range=left default]#[push-default][demo] #[pop-default]#[norange default]#[list=on align=left]#[list=left-marker]<#[list=right-marker]>#[list=on]#[range=window|0 list=focus default]#[push-default]0:bash*#[pop-default]#[norange list=on default]#[nolist align=right range=right default]#[push-default]"host" 12:09 24-Nov-26#[pop-default]#[norange default]';
|
||
|
||
test("Строка статуса: левая часть, окна, правая часть у правого края, ширина — колонки pane", () => {
|
||
const line = renderStatusLine(DEFAULT, 60, "bg=green,fg=black");
|
||
const text = strip(line);
|
||
assert.equal(text.length, 60);
|
||
assert.ok(text.startsWith("[demo] 0:bash*"), text);
|
||
assert.ok(text.endsWith('"host" 12:09 24-Nov-26'), text);
|
||
assert.ok(!text.includes("<") && !text.includes(">"), "list markers are drawn only when the list is cut");
|
||
assert.ok(line.startsWith("\x1b[0;30;42m"), "status-style: black on green");
|
||
});
|
||
|
||
test("Стили: цвета по имени, colourN, #rrggbb, атрибуты, default и push-default", () => {
|
||
assert.equal(colourSgr("red", false), "31");
|
||
assert.equal(colourSgr("brightblue", true), "104");
|
||
assert.equal(colourSgr("colour33", false), "38;5;33");
|
||
assert.equal(colourSgr("#ff8000", true), "48;2;255;128;0");
|
||
assert.equal(colourSgr("default", false), null);
|
||
const line = renderStatusLine("#[fg=red,bold]A#[default]B#[fg=#00ff00]#[push-default]C#[fg=red]#[default]D#[pop-default]#[default]E", 10, "bg=blue");
|
||
assert.match(line, /\x1b\[0;1;31;44mA/);
|
||
assert.match(line, /\x1b\[0;44mB/);
|
||
assert.match(line, /\x1b\[0;38;2;0;255;0;44mCD/, "default after push-default is the pushed style");
|
||
assert.match(line, /\x1b\[0;44mE/, "pop-default restores status-style");
|
||
});
|
||
|
||
test("Узкая строка: правая часть не налезает на левую; по центру — между ними", () => {
|
||
const text = strip(renderStatusLine("LEFT-PART#[align=right]RIGHT-PART-LONG", 15, ""));
|
||
assert.equal(text, "LEFT-PARTT-LONG");
|
||
assert.ok(text.startsWith("LEFT-PART"));
|
||
assert.ok(text.endsWith("LONG"));
|
||
assert.equal(strip(renderStatusLine("#[align=centre]MID", 9, "")), " MID ");
|
||
assert.equal(charWidth("中".codePointAt(0)!), 2);
|
||
assert.equal(strip(renderStatusLine("中x", 4, "")), "中x ");
|
||
});
|
||
|
||
test("Пустой формат — строка из фона status-style", () => {
|
||
assert.equal(strip(renderStatusLine("", 5, "bg=green")), " ");
|
||
});
|