`
);
}
/**
* The body under a head, on the panel colour. A padded body scrolls as a
* whole; the other kind lays out its own parts, one of which scrolls.
*/
const body = (html, padded = true) =>
padded ? `
${html}
` : `
${html}
`;
/**
* A table. Each column is `[label, width]`, with `'num'` as a third member
* for right-aligned numbers; the one column without a width takes what the
* others leave. `tall` rows have room for two lines.
*/
function table(columns, rows, tall = false) {
// Columns are 8 apart: half of the gap is on each side of a cell, and the
// table's two edges have none.
const GAP = 8;
const last = columns.length - 1;
const outer = (width, index) => width + (index === 0 || index === last ? GAP / 2 : GAP);
const grow = columns.findIndex(([, width]) => width == null);
const fixed = columns.reduce((sum, [, width], index) => sum + (width == null ? 0 : outer(width, index)), 0);
const cols = columns.map(([, width], index) =>
width == null ? '
`;
}
/** The log tab: a filter bar and the lines below it. */
function logTab(lines) {
const levels = LOG_LEVELS.map(
([key, label]) =>
``,
);
return (
`
${levels.join('')}
` +
`
${logBox(lines, true)}`
);
}
/** The log the selection has: a group's last run, or an input's. */
function selectedLog() {
const current = state.selected && find(state.selected);
if (current?.group) return current.group.lastRun?.log ?? [];
return current?.item?.log ?? [];
}
/** Log lines as plain text, independent of what's selected or filtered. */
export function formatLog(lines) {
return lines.map((line) => `${localClock(line.at)} ${levelLabel(line).padEnd(6)} ${lineText(line)}\n`).join('');
}
/** The visible log as plain text, for the clipboard. */
export function logText() {
return formatLog(selectedLog().filter(keep));
}
// ---------- stages ----------
const STAGE_ICON = { ok: ['✓', 'ok'], skipped: ['–', 'skip'], failed: ['✕', 'err'], blocked: ['⏸', 'warn'] };
const ARROW = '→';
function stageChip({ icon = '', tone = 'skip', name, duration = '', status = '', detail = '', dimmed = false }) {
return (
`
`
);
}
/** The stages of a finished input. `shown` holds the messages already on the page. */
function stagesCard(item, shown) {
const stages = stagesOf(item);
if (stages.length === 0) return '';
const lang = item.result?.lang;
const chips = stages.map((stage) => {
const [icon, tone] = STAGE_ICON[stage.status];
// A path is in the identity card, and a message the page shows is above.
const hidden = !stage.detail || stage.detail.path || shown.has(stage.detail.text);
return stageChip({
icon,
tone,
name: tv('stage', stage.stage),
duration: stage.durationMs > 0 ? formatDuration(stage.durationMs) : '',
status: tv('stageStatus', stage.status),
detail: hidden ? '' : show(stage.detail, lang),
});
});
return card(t('ov.stages'), `
${chips.join(ARROW)}
`, { wide: true });
}
/** The stages of a running input: where it is, and what is still to come. */
function progressCard(step) {
const detected = Boolean(step);
const chips = [
stageChip({
icon: detected ? '✓' : '●',
tone: detected ? 'ok' : 'info',
name: tv('stage', 'detection'),
status: detected ? tv('stageStatus', 'ok') : t('run.running'),
}),
stageChip({ icon: '●', tone: 'info', name: tv('stage', 'recovery'), status: stepText(step), dimmed: !detected }),
stageChip({ name: tv('stage', 'static_validation'), dimmed: true }),
stageChip({ name: tv('stage', 'output_write'), dimmed: true }),
];
return card(t('run.progress'), `
${chips.join(ARROW)}
`, { wide: true });
}
// ---------- groups ----------
const groupPath = (group) => (group.kind === 'folder' ? shownPath(`${group.name}/`) : '');
function groupTable(group) {
const rows = group.items.map((item) => {
// The same state the inputs pane shows for this row.
const row = rowState(item);
let route = '';
if (isDone(item)) {
// A package that could not be listed has no targets to count.
route = item.kind === 'package' && item.container
? t('EntriesSummary', { n: targetEntries(item).length })
: (routeOf(item) ?? '—');
}
return (
`
`,
)
);
}
function packageDetail(item) {
const named = item.container.archives.find((archive) => archive.identity);
const pills = statePill(item) + (named ? pill('skip', named.identity[0]) : '');
const tabs = ['overview', 'entries', 'log'];
const top = head({
title: item.name,
tagText: typeTag(item),
pills,
path: lastRunLine(item),
tabs,
badge: { entries: item.entries.length },
exports: true,
});
const shown = activeTab(tabs);
if (shown === 'log') return top + body(logTab(item.log ?? []), false);
return top + body(shown === 'entries' ? entriesTab(item) : packageOverview(item));
}
function entryDetail(entry) {
const result = entry.result;
const info = result?.info;
const { tone, key } = outcomeOf(entry);
const plan = messagePlan(entry);
const blocks = [...plan.top, ...plan.validation];
const image = result?.outputs.find((output) => !output.embedded);
const version = info?.metadata?.version ?? entry.metadataVersion;
const remapped = remappedOf(entry);
// What an entry is, is known once it was probed: one that is no target has
// only its name.
const kind = isNonTarget(entry) ? null : entry.kind === 'so' ? 'shared_library' : 'metadata';
const rows = [
[t('col.status'), toned(t(key), tone)],
kind && [t('col.type'), esc(tv('entryKind', kind))],
routeOf(entry) && [t('col.route'), esc(routeOf(entry))],
kind === 'metadata' && version != null && [t('ov.metadata_version'), esc(version)],
remapped != null && [t('entries.remapped_label'), counted(remapped)],
result?.inputSha256 && [t('ov.source'), hash(result.inputSha256)],
image && [t('ov.recovered'), stack([esc(formatBytes(image.size)), hash(image.sha256)])],
...(result?.outputs ?? []).map((output, index) => [t('ov.output'), outputValue(entry, output, index)]),
];
// The label column is as wide for one entry as for any other.
const labels = ['col.status', 'col.type', 'col.route', 'ov.metadata_version', 'entries.remapped_label', 'ov.source', 'ov.recovered', 'ov.output'];
const cards = [];
if (blocks.length) {
cards.push(card(t('ov.messages'), messages(blocks, result?.lang, entry.state === 'skipped'), { wide: true }));
}
cards.push(card(t('entries.title'), kv(rows, labels.map((label) => t(label)))));
if (info?.elf) cards.push(elfCard(info.elf));
const top = head({
title: entry.name,
tagText: typeTag(entry),
pills: pill(tone, t(key)),
path: shownPath(fullPath(entry)),
tabs: ['overview'],
});
return top + body(grid(cards));
}
// ---------- dispatch ----------
function empty() {
const kinds = ['.exe', '.dll', '.exe._ / .dll._', 'global-metadata.dat', '.so', '.apk', '.apks', '.xapk', t('empty.folders')];
return (
`
` +
`
${esc(t('empty.title'))}
` +
`
${kinds.map((kind) => `${esc(kind)}`).join('')}
` +
`
` +
`
` +
`
${esc(t('empty.local'))}
`
);
}
const pick = () => `
${esc(t('detail.pick'))}
`;
/** The detail pane for the selection. */
export function detail() {
if (state.groups.length === 0) return empty();
const current = state.selected && find(state.selected);
if (!current) return pick();
if (current.group) return groupDetail(current.group);
let item = current.item;
if (item.isEntry) {
if (isDone(item) && !isBusy(item.parent)) return entryDetail(item);
// An entry that is running again is shown as its package.
item = item.parent;
}
if (isBusy(item) || item.state === 'cancelled') return runDetail(item);
if (!isDone(item)) return pendingDetail(item);
// A package that could not be listed is shown as the input that failed.
return item.kind === 'package' && item.container ? packageDetail(item) : itemDetail(item);
}