Skip to content

eBPF-based security platform

tools/xtop: leave a view that shows no table

John Fastabendad8922f8a6c7
diff --git a/tools/xtop/src/components/NodesView.tsx b/tools/xtop/src/components/NodesView.tsx
index e5034b22..dfdc0c34 100644
--- a/tools/xtop/src/components/NodesView.tsx
+++ b/tools/xtop/src/components/NodesView.tsx
@@ -22,6 +22,7 @@ import {
type Shields,
} from "../lib/fleet.ts";
import { DataTable, Tabs, type Column } from "./DataTable.tsx";
+import { ViewMessage } from "./ViewMessage.tsx";
import { NodeDetail } from "./NodeDetail.tsx";
import { HealthCell } from "./MiniBar.tsx";
import { ago } from "../lib/format.ts";
@@ -312,7 +313,9 @@ export function NodesView({ backend, mode, onModeChange, height, active, onClose
return (
<Box flexDirection="column">
<Tabs labels={tabs.labels} selected={tabs.selected} />
- {fleet.error ? <Text color="red">node query failed: {fleet.error}</Text> : <Text dimColor>querying backend…</Text>}
+ <ViewMessage active={active && !searching} onClose={onClose} color={fleet.error ? "red" : undefined}>
+ {fleet.error ? `node query failed: ${fleet.error}` : "querying backend…"}
+ </ViewMessage>
</Box>
);
const report = fleet.data;
diff --git a/tools/xtop/src/components/SbomView.tsx b/tools/xtop/src/components/SbomView.tsx
index 53ae0265..25563017 100644
--- a/tools/xtop/src/components/SbomView.tsx
+++ b/tools/xtop/src/components/SbomView.tsx
@@ -23,6 +23,7 @@ import {
} from "../lib/sbom.ts";
import { severityRank } from "../lib/shields.ts";
import { DataTable, Tabs, type Column } from "./DataTable.tsx";
+import { ViewMessage } from "./ViewMessage.tsx";
import { FindingDetail } from "./FindingDetail.tsx";
import { FINDING_STATUS_STYLE, IMAGE_STATE_COLOR, SeverityText } from "./style.tsx";
@@ -271,7 +272,9 @@ export function SbomView({ backend, mode, onModeChange, height, active, onClose,
return (
<Box flexDirection="column">
<Tabs labels={tabs.labels} selected={tabs.selected} />
- {query.error ? <Text color="red">{mode} query failed: {query.error}</Text> : <Text dimColor>querying backend…</Text>}
+ <ViewMessage active={active && !searching} onClose={onClose} color={query.error ? "red" : undefined}>
+ {query.error ? `${mode} query failed: ${query.error}` : "querying backend…"}
+ </ViewMessage>
</Box>
);
const status = (generatedAt: Date) => (
diff --git a/tools/xtop/src/components/ShieldsView.tsx b/tools/xtop/src/components/ShieldsView.tsx
index 5754932b..cb6e23cd 100644
--- a/tools/xtop/src/components/ShieldsView.tsx
+++ b/tools/xtop/src/components/ShieldsView.tsx
@@ -6,6 +6,7 @@
import { useState } from "react";
import { Box, Text, useInput } from "ink";
+import type { ReactNode } from "react";
import type { Backend } from "../lib/backend.ts";
import { useRefreshing } from "../lib/useRefreshing.ts";
import {
@@ -19,6 +20,7 @@ import {
type ShieldsReport,
} from "../lib/shields.ts";
import { DataTable, type Column } from "./DataTable.tsx";
+import { ViewMessage } from "./ViewMessage.tsx";
import { MiniBar } from "./MiniBar.tsx";
import { ShieldDetail } from "./ShieldDetail.tsx";
import { SHIELD_STATUS_COLOR, SeverityText } from "./style.tsx";
@@ -161,15 +163,16 @@ export function ShieldsView({ backend, height, active, onClose, onSearchingChang
{ isActive: active && !searching && !detail },
);
+ const message = (color: string | undefined, text: ReactNode) => (
+ <ViewMessage active={active && !searching} onClose={onClose} color={color}>
+ {text}
+ </ViewMessage>
+ );
if (!query.data)
- return query.error ? (
- <Text color="red">shields query failed: {query.error}</Text>
- ) : (
- <Text dimColor>querying backend…</Text>
- );
+ return query.error ? message("red", `shields query failed: ${query.error}`) : message(undefined, "querying backend…");
const report = query.data;
if (report.shields.length === 0)
- return <Text dimColor>no upatch in shirudo.tree_ops: load a tree with jobs/tree-ingest</Text>;
+ return message(undefined, "no upatch in shirudo.tree_ops: load a tree with jobs/tree-ingest");
const tableHeight = Math.max(4, height);
const trees = new Set(report.shields.map((s) => s.treeId));
diff --git a/tools/xtop/src/components/ViewMessage.tsx b/tools/xtop/src/components/ViewMessage.tsx
new file mode 100644
index 00000000..170523d9
--- /dev/null
+++ b/tools/xtop/src/components/ViewMessage.tsx
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: BSD-2-Clause
+// Copyright (c) 2026 Authors of shirudo
+//
+// The line a view shows in place of its table, while it queries, after a
+// failed query or with nothing to list: it closes the view as the table
+// would, or h and esc would do nothing there.
+
+import type { ReactNode } from "react";
+import { Text, useInput } from "ink";
+
+type Props = {
+ active: boolean;
+ onClose: () => void;
+ color?: string;
+ children: ReactNode;
+};
+
+export function ViewMessage({ active, onClose, color, children }: Props) {
+ useInput(
+ (input, key) => {
+ if (key.escape || input === "h") onClose();
+ },
+ { isActive: active },
+ );
+ return (
+ <Text color={color} dimColor={!color}>
+ {children}
+ </Text>
+ );
+}