gloomberb 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -19
- package/bin/gloomberb +3 -0
- package/package.json +5 -4
- package/patches/@opentui%2Fcore@0.1.90.patch +356 -0
- package/src/app.tsx +1330 -0
- package/src/brokers/sync-broker-instance.test.ts +100 -0
- package/src/brokers/sync-broker-instance.ts +341 -0
- package/src/cli/commands/plugins.ts +173 -0
- package/src/cli/commands/portfolio.ts +210 -0
- package/src/cli/commands/search.ts +120 -0
- package/src/cli/commands/ticker.ts +375 -0
- package/src/cli/commands/watchlist.ts +210 -0
- package/src/cli/context.ts +62 -0
- package/src/cli/errors.ts +13 -0
- package/src/cli/helpers.ts +85 -0
- package/src/cli/index.ts +143 -0
- package/src/cli/ticker-resolution.ts +39 -0
- package/src/cli/types.ts +15 -0
- package/src/cli.test.ts +361 -0
- package/src/components/chart/chart-data.ts +239 -0
- package/src/components/chart/chart-renderer.ts +1199 -0
- package/src/components/chart/chart-types.ts +82 -0
- package/src/components/chart/chart-viewport.ts +21 -0
- package/src/components/chart/chart.test.ts +439 -0
- package/src/components/chart/comparison-chart-data.test.ts +109 -0
- package/src/components/chart/comparison-chart-data.ts +316 -0
- package/src/components/chart/comparison-chart-renderer.test.ts +84 -0
- package/src/components/chart/comparison-chart-renderer.ts +354 -0
- package/src/components/chart/comparison-stock-chart.tsx +1486 -0
- package/src/components/chart/cursor-motion.ts +48 -0
- package/src/components/chart/native/chart-rasterizer.ts +732 -0
- package/src/components/chart/native/kitty-adapter.ts +12 -0
- package/src/components/chart/native/kitty-manager.ts +142 -0
- package/src/components/chart/native/kitty-protocol.ts +110 -0
- package/src/components/chart/native/kitty-support.ts +71 -0
- package/src/components/chart/native/kitty.test.ts +620 -0
- package/src/components/chart/native/renderer-selection.ts +24 -0
- package/src/components/chart/native/surface-manager.ts +225 -0
- package/src/components/chart/native/surface-sync.ts +34 -0
- package/src/components/chart/stock-chart-renderer-switch.test.tsx +165 -0
- package/src/components/chart/stock-chart.test.ts +107 -0
- package/src/components/chart/stock-chart.tsx +1556 -0
- package/src/components/command-bar/__snapshots__/command-bar.test.tsx.snap +137 -0
- package/src/components/command-bar/command-bar.test.tsx +1524 -0
- package/src/components/command-bar/command-bar.tsx +4823 -0
- package/src/components/command-bar/command-registry.ts +261 -0
- package/src/components/command-bar/helpers.test.ts +224 -0
- package/src/components/command-bar/helpers.ts +371 -0
- package/src/components/command-bar/root-shortcuts.ts +158 -0
- package/src/components/command-bar/view-model.test.ts +152 -0
- package/src/components/command-bar/view-model.ts +185 -0
- package/src/components/command-bar/workflow-ops.test.ts +70 -0
- package/src/components/command-bar/workflow-ops.ts +433 -0
- package/src/components/command-bar/workflow-types.ts +127 -0
- package/src/components/detail-feed-view.test.tsx +105 -0
- package/src/components/detail-feed-view.tsx +295 -0
- package/src/components/index.ts +32 -0
- package/src/components/layout/floating-pane.tsx +49 -0
- package/src/components/layout/header.tsx +129 -0
- package/src/components/layout/pane-header.tsx +44 -0
- package/src/components/layout/pane.tsx +49 -0
- package/src/components/layout/pixel-mouse-mode.test.ts +122 -0
- package/src/components/layout/pixel-mouse.test.ts +40 -0
- package/src/components/layout/shell.test.tsx +625 -0
- package/src/components/layout/shell.tsx +1200 -0
- package/src/components/layout/status-bar.test.tsx +173 -0
- package/src/components/layout/status-bar.tsx +138 -0
- package/src/components/markdown-editor.tsx +134 -0
- package/src/components/onboarding/onboarding-wizard.test.tsx +184 -0
- package/src/components/onboarding/onboarding-wizard.tsx +1365 -0
- package/src/components/pane-settings-dialog.tsx +468 -0
- package/src/components/pane-template-wizard.test.tsx +52 -0
- package/src/components/pane-template-wizard.tsx +199 -0
- package/src/components/price-selector-dialog.tsx +195 -0
- package/src/components/spinner.tsx +2 -0
- package/src/components/tab-bar.tsx +17 -0
- package/src/components/ticker-badge-text.test.tsx +160 -0
- package/src/components/ticker-badge-text.tsx +58 -0
- package/src/components/ticker-badge.tsx +88 -0
- package/src/components/ticker-list-table.tsx +188 -0
- package/src/components/toggle-list.tsx +74 -0
- package/src/components/ui/button.tsx +77 -0
- package/src/components/ui/data-table.tsx +210 -0
- package/src/components/ui/external-link.tsx +22 -0
- package/src/components/ui/fields.tsx +187 -0
- package/src/components/ui/frame.tsx +73 -0
- package/src/components/ui/index.ts +53 -0
- package/src/components/ui/list-view.tsx +166 -0
- package/src/components/ui/loading.tsx +70 -0
- package/src/components/ui/status.tsx +83 -0
- package/src/components/ui/tabs.tsx +47 -0
- package/src/components/ui/toggle.tsx +164 -0
- package/src/components/ui/ui.test.tsx +134 -0
- package/src/data/app-persistence.ts +25 -0
- package/src/data/config-store.test.ts +310 -0
- package/src/data/config-store.ts +469 -0
- package/src/data/plugin-state-store.ts +102 -0
- package/src/data/resource-store.ts +323 -0
- package/src/data/session-store.ts +52 -0
- package/src/data/sqlite-cache.test.ts +103 -0
- package/src/data/sqlite-database.ts +62 -0
- package/src/data/sqlite-json.ts +19 -0
- package/src/data/ticker-repository.ts +45 -0
- package/src/data/ticker-store.ts +46 -0
- package/src/index.tsx +67 -0
- package/src/market-data/coordinator.test.ts +369 -0
- package/src/market-data/coordinator.ts +580 -0
- package/src/market-data/hooks.tsx +234 -0
- package/src/market-data/query-store.ts +28 -0
- package/src/market-data/request-types.test.ts +64 -0
- package/src/market-data/request-types.ts +70 -0
- package/src/market-data/result-types.ts +56 -0
- package/src/market-data/selectors.ts +166 -0
- package/src/market-data/trace.ts +7 -0
- package/src/pane-settings.test.ts +71 -0
- package/src/pane-settings.ts +73 -0
- package/src/plugins/builtin/ai/ask-ai-detail-tab.tsx +338 -0
- package/src/plugins/builtin/ai/gloomberb-cli.ts +70 -0
- package/src/plugins/builtin/ai/index.test.tsx +139 -0
- package/src/plugins/builtin/ai/index.tsx +86 -0
- package/src/plugins/builtin/ai/providers.ts +99 -0
- package/src/plugins/builtin/ai/runner.ts +82 -0
- package/src/plugins/builtin/ai/screener-contract.test.ts +117 -0
- package/src/plugins/builtin/ai/screener-contract.ts +174 -0
- package/src/plugins/builtin/ai/screener-pane.test.tsx +365 -0
- package/src/plugins/builtin/ai/screener-pane.tsx +1161 -0
- package/src/plugins/builtin/ai/settings.ts +79 -0
- package/src/plugins/builtin/ai/ticker-context.ts +64 -0
- package/src/plugins/builtin/ai/utils.ts +71 -0
- package/src/plugins/builtin/ask-ai.test.tsx +258 -0
- package/src/plugins/builtin/ask-ai.tsx +9 -0
- package/src/plugins/builtin/chat-controller.test.ts +217 -0
- package/src/plugins/builtin/chat-controller.ts +340 -0
- package/src/plugins/builtin/chat.test.tsx +451 -0
- package/src/plugins/builtin/chat.tsx +620 -0
- package/src/plugins/builtin/comparison-chart.test.tsx +277 -0
- package/src/plugins/builtin/comparison-chart.tsx +169 -0
- package/src/plugins/builtin/data-providers.ts +16 -0
- package/src/plugins/builtin/debug.tsx +351 -0
- package/src/plugins/builtin/help.test.tsx +110 -0
- package/src/plugins/builtin/help.tsx +281 -0
- package/src/plugins/builtin/layout-manager.tsx +264 -0
- package/src/plugins/builtin/manual-entry.tsx +25 -0
- package/src/plugins/builtin/news.tsx +143 -0
- package/src/plugins/builtin/notes-files.ts +58 -0
- package/src/plugins/builtin/notes.tsx +396 -0
- package/src/plugins/builtin/options-availability.test.tsx +179 -0
- package/src/plugins/builtin/options-availability.ts +158 -0
- package/src/plugins/builtin/options.tsx +364 -0
- package/src/plugins/builtin/portfolio-list/header.tsx +227 -0
- package/src/plugins/builtin/portfolio-list/index.tsx +99 -0
- package/src/plugins/builtin/portfolio-list/metrics.ts +436 -0
- package/src/plugins/builtin/portfolio-list/pane.tsx +533 -0
- package/src/plugins/builtin/portfolio-list/settings.ts +280 -0
- package/src/plugins/builtin/portfolio-list/summary.tsx +270 -0
- package/src/plugins/builtin/portfolio-list/table.tsx +64 -0
- package/src/plugins/builtin/portfolio-list.test.ts +74 -0
- package/src/plugins/builtin/portfolio-list.test.tsx +1164 -0
- package/src/plugins/builtin/portfolio-metrics.test.ts +153 -0
- package/src/plugins/builtin/quote-monitor.test.tsx +114 -0
- package/src/plugins/builtin/sec.tsx +250 -0
- package/src/plugins/builtin/ticker-detail/chart-tab.tsx +43 -0
- package/src/plugins/builtin/ticker-detail/financials-tab.tsx +390 -0
- package/src/plugins/builtin/ticker-detail/index.tsx +80 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +242 -0
- package/src/plugins/builtin/ticker-detail/pane.tsx +183 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor.tsx +83 -0
- package/src/plugins/builtin/ticker-detail/settings.ts +132 -0
- package/src/plugins/builtin/ticker-detail-chart-tab-switch.test.tsx +193 -0
- package/src/plugins/builtin/ticker-detail.test.tsx +578 -0
- package/src/plugins/builtin/yahoo.ts +18 -0
- package/src/plugins/event-bus.ts +37 -0
- package/src/plugins/ibkr/__snapshots__/trade-tab.test.tsx.snap +35 -0
- package/src/plugins/ibkr/account-cache.test.ts +101 -0
- package/src/plugins/ibkr/account-cache.ts +137 -0
- package/src/plugins/ibkr/broker-adapter.ts +168 -0
- package/src/plugins/ibkr/config.test.ts +68 -0
- package/src/plugins/ibkr/config.ts +262 -0
- package/src/plugins/ibkr/dialogs.tsx +83 -0
- package/src/plugins/ibkr/flex.test.ts +107 -0
- package/src/plugins/ibkr/flex.ts +267 -0
- package/src/plugins/ibkr/fundamental-parser.ts +149 -0
- package/src/plugins/ibkr/gateway-helpers.ts +28 -0
- package/src/plugins/ibkr/gateway-selection.ts +51 -0
- package/src/plugins/ibkr/gateway-service.test.ts +450 -0
- package/src/plugins/ibkr/gateway-service.ts +2228 -0
- package/src/plugins/ibkr/index.test.tsx +183 -0
- package/src/plugins/ibkr/index.tsx +153 -0
- package/src/plugins/ibkr/instance-selection.test.ts +121 -0
- package/src/plugins/ibkr/instance-selection.ts +36 -0
- package/src/plugins/ibkr/price-normalization.test.ts +38 -0
- package/src/plugins/ibkr/price-normalization.ts +59 -0
- package/src/plugins/ibkr/trade-badge.tsx +27 -0
- package/src/plugins/ibkr/trade-tab.test.tsx +225 -0
- package/src/plugins/ibkr/trade-tab.tsx +1050 -0
- package/src/plugins/ibkr/trade-utils.test.ts +175 -0
- package/src/plugins/ibkr/trade-utils.ts +149 -0
- package/src/plugins/ibkr/trading-pane.tsx +438 -0
- package/src/plugins/ibkr/trading-state.test.ts +109 -0
- package/src/plugins/ibkr/trading-state.ts +339 -0
- package/src/plugins/loader.ts +71 -0
- package/src/plugins/pane-manager.test.ts +103 -0
- package/src/plugins/pane-manager.ts +974 -0
- package/src/plugins/plugin-persistence.ts +85 -0
- package/src/plugins/plugin-runtime.test.tsx +185 -0
- package/src/plugins/plugin-runtime.tsx +175 -0
- package/src/plugins/prediction-markets/cache.ts +114 -0
- package/src/plugins/prediction-markets/categories.ts +223 -0
- package/src/plugins/prediction-markets/chart.tsx +512 -0
- package/src/plugins/prediction-markets/columns.ts +133 -0
- package/src/plugins/prediction-markets/controller-data.ts +614 -0
- package/src/plugins/prediction-markets/controller.ts +725 -0
- package/src/plugins/prediction-markets/detail/book.tsx +118 -0
- package/src/plugins/prediction-markets/detail/outcomes.tsx +102 -0
- package/src/plugins/prediction-markets/detail/overview.tsx +73 -0
- package/src/plugins/prediction-markets/detail/pane.tsx +308 -0
- package/src/plugins/prediction-markets/detail/rules.tsx +16 -0
- package/src/plugins/prediction-markets/detail/shared.tsx +29 -0
- package/src/plugins/prediction-markets/detail/trades.tsx +30 -0
- package/src/plugins/prediction-markets/detail.test.tsx +47 -0
- package/src/plugins/prediction-markets/index.tsx +102 -0
- package/src/plugins/prediction-markets/keyboard.ts +64 -0
- package/src/plugins/prediction-markets/launch.test.ts +126 -0
- package/src/plugins/prediction-markets/launch.ts +240 -0
- package/src/plugins/prediction-markets/metrics.ts +311 -0
- package/src/plugins/prediction-markets/navigation.ts +90 -0
- package/src/plugins/prediction-markets/outcome-order.ts +19 -0
- package/src/plugins/prediction-markets/pane.test.tsx +425 -0
- package/src/plugins/prediction-markets/pane.tsx +294 -0
- package/src/plugins/prediction-markets/plugin.test.tsx +570 -0
- package/src/plugins/prediction-markets/rows.ts +229 -0
- package/src/plugins/prediction-markets/services/fetch.ts +97 -0
- package/src/plugins/prediction-markets/services/kalshi-adapter.ts +555 -0
- package/src/plugins/prediction-markets/services/polymarket-adapter.ts +660 -0
- package/src/plugins/prediction-markets/services/polymarket-ws.ts +108 -0
- package/src/plugins/prediction-markets/settings.ts +164 -0
- package/src/plugins/prediction-markets/status.ts +24 -0
- package/src/plugins/prediction-markets/table.tsx +84 -0
- package/src/plugins/prediction-markets/test-helpers.tsx +636 -0
- package/src/plugins/prediction-markets/types.ts +186 -0
- package/src/plugins/registry.ts +633 -0
- package/src/sources/exchange-rates.ts +18 -0
- package/src/sources/gloomberb-cloud.test.ts +199 -0
- package/src/sources/gloomberb-cloud.ts +326 -0
- package/src/sources/provider-errors.ts +19 -0
- package/src/sources/provider-router.test.ts +1476 -0
- package/src/sources/provider-router.ts +1405 -0
- package/src/sources/sec-edgar.test.ts +286 -0
- package/src/sources/sec-edgar.ts +526 -0
- package/src/sources/yahoo-finance.test.ts +14 -0
- package/src/sources/yahoo-finance.ts +1017 -0
- package/src/state/app-activity.test.ts +41 -0
- package/src/state/app-activity.ts +106 -0
- package/src/state/app-bootstrap.test.ts +471 -0
- package/src/state/app-bootstrap.ts +308 -0
- package/src/state/app-context.test.ts +406 -0
- package/src/state/app-context.test.tsx +132 -0
- package/src/state/app-context.tsx +969 -0
- package/src/state/selectors.ts +67 -0
- package/src/state/session-persistence.test.ts +128 -0
- package/src/state/session-persistence.ts +161 -0
- package/src/state/ticker-refresh-queue.test.ts +46 -0
- package/src/state/ticker-refresh-queue.ts +40 -0
- package/src/state/use-inline-tickers.ts +174 -0
- package/src/state/use-quote-streaming.test.ts +37 -0
- package/src/state/use-quote-streaming.test.tsx +70 -0
- package/src/state/use-quote-streaming.ts +80 -0
- package/src/state/use-session-snapshot.ts +84 -0
- package/src/test-support/data-provider.ts +22 -0
- package/src/theme/color-utils.ts +67 -0
- package/src/theme/colors.ts +128 -0
- package/src/theme/themes.test.ts +45 -0
- package/src/theme/themes.ts +491 -0
- package/src/types/broker.ts +105 -0
- package/src/types/config.ts +434 -0
- package/src/types/data-provider.ts +81 -0
- package/src/types/financials.ts +142 -0
- package/src/types/instrument.ts +29 -0
- package/src/types/persistence.ts +21 -0
- package/src/types/plugin.ts +354 -0
- package/src/types/ticker.ts +58 -0
- package/src/types/trading.ts +85 -0
- package/src/updater.test.ts +162 -0
- package/src/updater.ts +247 -0
- package/src/utils/api-client.ts +666 -0
- package/src/utils/ascii-chart.ts +172 -0
- package/src/utils/broker-instances.ts +47 -0
- package/src/utils/cli-output.ts +83 -0
- package/src/utils/currency-units.test.ts +49 -0
- package/src/utils/currency-units.ts +82 -0
- package/src/utils/debug-log.ts +133 -0
- package/src/utils/exchange-rate-map.ts +8 -0
- package/src/utils/format.ts +158 -0
- package/src/utils/fuzzy-search.ts +34 -0
- package/src/utils/market-status.ts +95 -0
- package/src/utils/options.ts +86 -0
- package/src/utils/price-history.ts +39 -0
- package/src/utils/quote-time.test.ts +22 -0
- package/src/utils/quote-time.ts +50 -0
- package/src/utils/sec.test.ts +55 -0
- package/src/utils/sec.ts +45 -0
- package/src/utils/ticker-list.test.ts +22 -0
- package/src/utils/ticker-list.ts +35 -0
- package/src/utils/ticker-metadata.ts +51 -0
- package/src/utils/ticker-search.test.ts +227 -0
- package/src/utils/ticker-search.ts +764 -0
- package/src/utils/ticker-tokenizer.test.ts +48 -0
- package/src/utils/ticker-tokenizer.ts +72 -0
- package/src/version.ts +1 -0
- package/install.mjs +0 -68
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from "react";
|
|
2
|
+
import { useKeyboard } from "@opentui/react";
|
|
3
|
+
import { TextAttributes } from "@opentui/core";
|
|
4
|
+
import type { GloomPlugin, PaneProps } from "../../types/plugin";
|
|
5
|
+
import { useAppState } from "../../state/app-context";
|
|
6
|
+
import { colors, hoverBg } from "../../theme/colors";
|
|
7
|
+
import { debugLog, type LogEntry, type LogLevel } from "../../utils/debug-log";
|
|
8
|
+
import { writeFileSync } from "fs";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
import { homedir } from "os";
|
|
11
|
+
|
|
12
|
+
function levelColor(level: LogLevel): string {
|
|
13
|
+
switch (level) {
|
|
14
|
+
case "debug": return colors.textDim;
|
|
15
|
+
case "info": return colors.positive;
|
|
16
|
+
case "warn": return "#e5c07b";
|
|
17
|
+
case "error": return colors.negative;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const LEVEL_LABELS: Record<LogLevel, string> = {
|
|
22
|
+
debug: "DBG",
|
|
23
|
+
info: "INF",
|
|
24
|
+
warn: "WRN",
|
|
25
|
+
error: "ERR",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ALL_LEVELS: LogLevel[] = ["debug", "info", "warn", "error"];
|
|
29
|
+
|
|
30
|
+
function formatTimestamp(ts: number): string {
|
|
31
|
+
const d = new Date(ts);
|
|
32
|
+
return d.toISOString().slice(11, 23);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function DebugPane({ focused, width, height, close }: PaneProps) {
|
|
36
|
+
const { dispatch } = useAppState();
|
|
37
|
+
const [entries, setEntries] = useState<LogEntry[]>(() => debugLog.getEntries());
|
|
38
|
+
const [filterLevel, setFilterLevel] = useState<LogLevel | null>(null);
|
|
39
|
+
const [filterSource, setFilterSource] = useState<string | null>(null);
|
|
40
|
+
const [autoScroll, setAutoScroll] = useState(true);
|
|
41
|
+
const [scrollOffset, setScrollOffset] = useState(0);
|
|
42
|
+
const [selectedIdx, setSelectedIdx] = useState(-1);
|
|
43
|
+
const [hoveredIdx, setHoveredIdx] = useState<number | null>(null);
|
|
44
|
+
const [showDetail, setShowDetail] = useState(false);
|
|
45
|
+
const sourcesRef = useRef<string[]>(debugLog.getSources());
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const unsub = debugLog.subscribe(() => {
|
|
49
|
+
const filtered = debugLog.getEntries(
|
|
50
|
+
filterLevel || filterSource
|
|
51
|
+
? { level: filterLevel ?? undefined, source: filterSource ?? undefined }
|
|
52
|
+
: undefined,
|
|
53
|
+
);
|
|
54
|
+
setEntries(filtered);
|
|
55
|
+
sourcesRef.current = debugLog.getSources();
|
|
56
|
+
if (autoScroll) setScrollOffset(0);
|
|
57
|
+
});
|
|
58
|
+
return unsub;
|
|
59
|
+
}, [filterLevel, filterSource, autoScroll]);
|
|
60
|
+
|
|
61
|
+
const exportLogs = useCallback(() => {
|
|
62
|
+
const text = debugLog.exportAsText(
|
|
63
|
+
filterLevel || filterSource
|
|
64
|
+
? { level: filterLevel ?? undefined, source: filterSource ?? undefined }
|
|
65
|
+
: undefined,
|
|
66
|
+
);
|
|
67
|
+
const downloadsDir = join(homedir(), "Downloads");
|
|
68
|
+
const filename = `gloomberb-debug-${new Date().toISOString().slice(0, 19).replace(/:/g, "-")}.log`;
|
|
69
|
+
const filepath = join(downloadsDir, filename);
|
|
70
|
+
try {
|
|
71
|
+
writeFileSync(filepath, text);
|
|
72
|
+
const registry = (globalThis as any).__gloomRegistry;
|
|
73
|
+
registry?.showToastFn?.(`Exported to ~/Downloads/${filename}`, { type: "success" });
|
|
74
|
+
} catch {
|
|
75
|
+
const registry = (globalThis as any).__gloomRegistry;
|
|
76
|
+
registry?.showToastFn?.("Failed to export logs", { type: "error" });
|
|
77
|
+
}
|
|
78
|
+
}, [filterLevel, filterSource]);
|
|
79
|
+
|
|
80
|
+
const clearLogs = useCallback(() => {
|
|
81
|
+
debugLog.clear();
|
|
82
|
+
setEntries([]);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
useKeyboard((event) => {
|
|
86
|
+
if (!focused) return;
|
|
87
|
+
|
|
88
|
+
// Level filter cycling
|
|
89
|
+
if (event.name === "l") {
|
|
90
|
+
const currentIdx = filterLevel ? ALL_LEVELS.indexOf(filterLevel) : -1;
|
|
91
|
+
const nextIdx = currentIdx + 1;
|
|
92
|
+
setFilterLevel(nextIdx >= ALL_LEVELS.length ? null : ALL_LEVELS[nextIdx] ?? null);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Source filter cycling
|
|
97
|
+
if (event.name === "s") {
|
|
98
|
+
const sources = sourcesRef.current;
|
|
99
|
+
if (sources.length === 0) return;
|
|
100
|
+
const currentIdx = filterSource ? sources.indexOf(filterSource) : -1;
|
|
101
|
+
const nextIdx = currentIdx + 1;
|
|
102
|
+
setFilterSource(nextIdx >= sources.length ? null : sources[nextIdx] ?? null);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Export
|
|
107
|
+
if (event.name === "e") {
|
|
108
|
+
exportLogs();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Clear
|
|
113
|
+
if (event.name === "x") {
|
|
114
|
+
clearLogs();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Auto-scroll toggle
|
|
119
|
+
if (event.name === "a") {
|
|
120
|
+
setAutoScroll((prev) => !prev);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Detail toggle
|
|
125
|
+
if (event.name === "return" && selectedIdx >= 0) {
|
|
126
|
+
setShowDetail((prev) => !prev);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Navigation
|
|
131
|
+
if (event.name === "j" || event.name === "down") {
|
|
132
|
+
setAutoScroll(false);
|
|
133
|
+
setSelectedIdx((prev) => Math.min(prev + 1, entries.length - 1));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (event.name === "k" || event.name === "up") {
|
|
137
|
+
setAutoScroll(false);
|
|
138
|
+
setSelectedIdx((prev) => Math.max(prev - 1, 0));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (event.name === "g" && !event.shift) {
|
|
143
|
+
setSelectedIdx(0);
|
|
144
|
+
setAutoScroll(false);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (event.name === "g" && event.shift) {
|
|
148
|
+
setSelectedIdx(entries.length - 1);
|
|
149
|
+
setAutoScroll(true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (event.name === "escape") {
|
|
154
|
+
if (showDetail) {
|
|
155
|
+
setShowDetail(false);
|
|
156
|
+
} else {
|
|
157
|
+
close?.();
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const headerHeight = 2;
|
|
164
|
+
const footerHeight = 1;
|
|
165
|
+
const contentWidth = Math.max(1, width - 2);
|
|
166
|
+
const messageAreaHeight = Math.max(1, height - headerHeight - footerHeight);
|
|
167
|
+
|
|
168
|
+
// Compute visible window
|
|
169
|
+
const visibleCount = showDetail ? Math.max(1, messageAreaHeight - 4) : messageAreaHeight;
|
|
170
|
+
const totalEntries = entries.length;
|
|
171
|
+
|
|
172
|
+
// Keep selected entry visible
|
|
173
|
+
let viewStart: number;
|
|
174
|
+
if (autoScroll) {
|
|
175
|
+
viewStart = Math.max(0, totalEntries - visibleCount);
|
|
176
|
+
// In auto-scroll, selected follows bottom
|
|
177
|
+
} else {
|
|
178
|
+
if (selectedIdx < 0) {
|
|
179
|
+
viewStart = Math.max(0, totalEntries - visibleCount);
|
|
180
|
+
} else {
|
|
181
|
+
viewStart = Math.max(0, Math.min(selectedIdx - Math.floor(visibleCount / 2), totalEntries - visibleCount));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const visibleEntries = entries.slice(viewStart, viewStart + visibleCount);
|
|
185
|
+
|
|
186
|
+
const selectedEntry = selectedIdx >= 0 && selectedIdx < entries.length ? entries[selectedIdx] : null;
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<box flexDirection="column" width={width} height={height}>
|
|
190
|
+
{/* Header */}
|
|
191
|
+
<box height={1} width={contentWidth} flexDirection="row" paddingLeft={1}>
|
|
192
|
+
<text fg={colors.textBright} attributes={TextAttributes.BOLD}>Debug Log</text>
|
|
193
|
+
<text fg={colors.textDim}> ({totalEntries})</text>
|
|
194
|
+
<box flexGrow={1} />
|
|
195
|
+
{filterLevel && (
|
|
196
|
+
<text fg={levelColor(filterLevel)} attributes={TextAttributes.BOLD}>
|
|
197
|
+
{" "}{filterLevel.toUpperCase()}{" "}
|
|
198
|
+
</text>
|
|
199
|
+
)}
|
|
200
|
+
{filterSource && (
|
|
201
|
+
<text fg={colors.positive}>
|
|
202
|
+
{" "}{filterSource}{" "}
|
|
203
|
+
</text>
|
|
204
|
+
)}
|
|
205
|
+
{autoScroll && <text fg={colors.textDim}> AUTO </text>}
|
|
206
|
+
</box>
|
|
207
|
+
<box height={1} width={contentWidth}>
|
|
208
|
+
<text fg={colors.border}>{"-".repeat(contentWidth)}</text>
|
|
209
|
+
</box>
|
|
210
|
+
|
|
211
|
+
{/* Log entries */}
|
|
212
|
+
<box
|
|
213
|
+
height={visibleCount}
|
|
214
|
+
flexDirection="column"
|
|
215
|
+
onMouseScroll={(event: any) => {
|
|
216
|
+
const dir = event.scroll?.direction;
|
|
217
|
+
if (!dir) return;
|
|
218
|
+
if (dir === "up" || dir === "down") {
|
|
219
|
+
setAutoScroll(false);
|
|
220
|
+
setSelectedIdx((prev) => {
|
|
221
|
+
const next = dir === "up" ? prev - 3 : prev + 3;
|
|
222
|
+
return Math.max(0, Math.min(next, entries.length - 1));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
{visibleEntries.length === 0 && (
|
|
228
|
+
<box alignItems="center" justifyContent="center" flexGrow={1}>
|
|
229
|
+
<text fg={colors.textDim}>No log entries{filterLevel || filterSource ? " matching filter" : ""}</text>
|
|
230
|
+
</box>
|
|
231
|
+
)}
|
|
232
|
+
{visibleEntries.map((entry, i) => {
|
|
233
|
+
const globalIdx = viewStart + i;
|
|
234
|
+
const isSelected = globalIdx === selectedIdx;
|
|
235
|
+
const isHovered = globalIdx === hoveredIdx && !isSelected;
|
|
236
|
+
const bgColor = isSelected ? colors.selected : isHovered ? hoverBg() : undefined;
|
|
237
|
+
const ts = formatTimestamp(entry.timestamp);
|
|
238
|
+
const lvl = LEVEL_LABELS[entry.level];
|
|
239
|
+
const sourceTag = entry.source;
|
|
240
|
+
const maxMsg = Math.max(0, contentWidth - ts.length - lvl.length - sourceTag.length - 8);
|
|
241
|
+
const msg = entry.message.length > maxMsg
|
|
242
|
+
? entry.message.slice(0, maxMsg - 1) + "…"
|
|
243
|
+
: entry.message;
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<box
|
|
247
|
+
key={entry.id}
|
|
248
|
+
height={1}
|
|
249
|
+
width={contentWidth}
|
|
250
|
+
flexDirection="row"
|
|
251
|
+
backgroundColor={bgColor}
|
|
252
|
+
onMouseMove={() => setHoveredIdx(globalIdx)}
|
|
253
|
+
onMouseDown={() => { setSelectedIdx(globalIdx); setAutoScroll(false); }}
|
|
254
|
+
>
|
|
255
|
+
<text fg={colors.textMuted}> {ts} </text>
|
|
256
|
+
<text fg={levelColor(entry.level)} attributes={TextAttributes.BOLD}>{lvl}</text>
|
|
257
|
+
<text fg={colors.textDim}> [{sourceTag}] </text>
|
|
258
|
+
<text fg={isSelected ? colors.selectedText ?? colors.textBright : colors.text}>
|
|
259
|
+
{msg}
|
|
260
|
+
</text>
|
|
261
|
+
</box>
|
|
262
|
+
);
|
|
263
|
+
})}
|
|
264
|
+
</box>
|
|
265
|
+
|
|
266
|
+
{/* Detail panel */}
|
|
267
|
+
{showDetail && selectedEntry && (
|
|
268
|
+
<box flexDirection="column" height={4} width={contentWidth}>
|
|
269
|
+
<box height={1} width={contentWidth}>
|
|
270
|
+
<text fg={colors.border}>{"-".repeat(contentWidth)}</text>
|
|
271
|
+
</box>
|
|
272
|
+
<box paddingLeft={1} flexDirection="column">
|
|
273
|
+
<text fg={colors.text}>{selectedEntry.message}</text>
|
|
274
|
+
{selectedEntry.data !== undefined && (
|
|
275
|
+
<text fg={colors.textDim}>
|
|
276
|
+
{JSON.stringify(selectedEntry.data, null, 2).slice(0, contentWidth * 2)}
|
|
277
|
+
</text>
|
|
278
|
+
)}
|
|
279
|
+
</box>
|
|
280
|
+
</box>
|
|
281
|
+
)}
|
|
282
|
+
|
|
283
|
+
{/* Footer */}
|
|
284
|
+
<box height={1} width={contentWidth} flexDirection="row" paddingLeft={1}>
|
|
285
|
+
<text fg={colors.textMuted}>
|
|
286
|
+
<span fg={colors.text}>l</span>evel
|
|
287
|
+
{" "}
|
|
288
|
+
<span fg={colors.text}>s</span>ource
|
|
289
|
+
{" "}
|
|
290
|
+
<span fg={colors.text}>e</span>xport
|
|
291
|
+
{" "}
|
|
292
|
+
<span fg={colors.text}>x</span> clear
|
|
293
|
+
{" "}
|
|
294
|
+
<span fg={colors.text}>a</span>uto-scroll
|
|
295
|
+
</text>
|
|
296
|
+
</box>
|
|
297
|
+
</box>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export const debugPlugin: GloomPlugin = {
|
|
302
|
+
id: "debug",
|
|
303
|
+
name: "Debug",
|
|
304
|
+
version: "1.0.0",
|
|
305
|
+
description: "View and export debug logs",
|
|
306
|
+
toggleable: true,
|
|
307
|
+
|
|
308
|
+
setup(ctx) {
|
|
309
|
+
ctx.registerPane({
|
|
310
|
+
id: "debug",
|
|
311
|
+
name: "Debug Log",
|
|
312
|
+
icon: "D",
|
|
313
|
+
component: DebugPane,
|
|
314
|
+
defaultPosition: "right",
|
|
315
|
+
defaultMode: "floating",
|
|
316
|
+
defaultFloatingSize: { width: 120, height: 30 },
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
ctx.registerCommand({
|
|
320
|
+
id: "open-debug-log",
|
|
321
|
+
label: "Debug Log",
|
|
322
|
+
description: "Open the debug log viewer",
|
|
323
|
+
keywords: ["debug", "log", "logs", "console", "errors"],
|
|
324
|
+
category: "navigation",
|
|
325
|
+
execute: () => {
|
|
326
|
+
ctx.showWidget("debug");
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
ctx.registerCommand({
|
|
331
|
+
id: "export-debug-log",
|
|
332
|
+
label: "Export Debug Log",
|
|
333
|
+
description: "Export debug logs to ~/Downloads",
|
|
334
|
+
keywords: ["export", "debug", "log", "download", "save"],
|
|
335
|
+
category: "config",
|
|
336
|
+
execute: () => {
|
|
337
|
+
const text = debugLog.exportAsText();
|
|
338
|
+
const downloadsDir = join(homedir(), "Downloads");
|
|
339
|
+
const filename = `gloomberb-debug-${new Date().toISOString().slice(0, 19).replace(/:/g, "-")}.log`;
|
|
340
|
+
const filepath = join(downloadsDir, filename);
|
|
341
|
+
try {
|
|
342
|
+
writeFileSync(filepath, text);
|
|
343
|
+
ctx.showToast(`Exported to ~/Downloads/${filename}`, { type: "success" });
|
|
344
|
+
} catch {
|
|
345
|
+
ctx.showToast("Failed to export logs", { type: "error" });
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
},
|
|
351
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
import { testRender } from "@opentui/react/test-utils";
|
|
4
|
+
import { HelpPane } from "./help";
|
|
5
|
+
import { setSharedRegistryForTests } from "../registry";
|
|
6
|
+
|
|
7
|
+
let testSetup: Awaited<ReturnType<typeof testRender>> | undefined;
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
if (testSetup) {
|
|
11
|
+
testSetup.renderer.destroy();
|
|
12
|
+
testSetup = undefined;
|
|
13
|
+
}
|
|
14
|
+
setSharedRegistryForTests(undefined);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe("HelpPane", () => {
|
|
18
|
+
test("renders shortcut, layout, and bug-report guidance", async () => {
|
|
19
|
+
setSharedRegistryForTests({
|
|
20
|
+
paneTemplates: new Map([
|
|
21
|
+
["quote-monitor-pane", {
|
|
22
|
+
id: "quote-monitor-pane",
|
|
23
|
+
paneId: "quote-monitor",
|
|
24
|
+
label: "Quote Monitor",
|
|
25
|
+
description: "Open a compact quote monitor",
|
|
26
|
+
shortcut: { prefix: "QQ", argPlaceholder: "ticker" },
|
|
27
|
+
}],
|
|
28
|
+
["notes-pane", {
|
|
29
|
+
id: "notes-pane",
|
|
30
|
+
paneId: "notes",
|
|
31
|
+
label: "Quick Notes",
|
|
32
|
+
description: "Open a notes window",
|
|
33
|
+
shortcut: { prefix: "NOTE" },
|
|
34
|
+
}],
|
|
35
|
+
]),
|
|
36
|
+
allPlugins: new Map([
|
|
37
|
+
["ticker-detail", { id: "ticker-detail", name: "Ticker Detail" }],
|
|
38
|
+
["notes", { id: "notes", name: "Notes" }],
|
|
39
|
+
]),
|
|
40
|
+
getPaneTemplatePluginId: (templateId: string) => (
|
|
41
|
+
templateId === "quote-monitor-pane" ? "ticker-detail" : "notes"
|
|
42
|
+
),
|
|
43
|
+
getConfigFn: () => ({ disabledPlugins: [] }),
|
|
44
|
+
} as any);
|
|
45
|
+
|
|
46
|
+
testSetup = await testRender(
|
|
47
|
+
<HelpPane
|
|
48
|
+
paneId="help:main"
|
|
49
|
+
paneType="help"
|
|
50
|
+
focused
|
|
51
|
+
width={88}
|
|
52
|
+
height={36}
|
|
53
|
+
close={() => {}}
|
|
54
|
+
/>,
|
|
55
|
+
{ width: 88, height: 36 },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await testSetup.renderOnce();
|
|
59
|
+
|
|
60
|
+
const frame = testSetup.captureCharFrame();
|
|
61
|
+
expect(frame).toContain("How To Use Gloomberb");
|
|
62
|
+
expect(frame).toContain("Window Templates");
|
|
63
|
+
expect(frame).toContain("QQ");
|
|
64
|
+
expect(frame).toContain("Quote Monitor");
|
|
65
|
+
expect(frame).toContain("Layout System");
|
|
66
|
+
expect(frame).toContain("Ctrl+W");
|
|
67
|
+
expect(frame).toContain("Open Debug Log");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("opens the debug log from the mouse action", async () => {
|
|
71
|
+
const calls: string[] = [];
|
|
72
|
+
let closed = 0;
|
|
73
|
+
|
|
74
|
+
setSharedRegistryForTests({
|
|
75
|
+
showWidget: (paneId: string) => calls.push(`widget:${paneId}`),
|
|
76
|
+
openCommandBarFn: (query?: string) => calls.push(`command:${query ?? ""}`),
|
|
77
|
+
} as any);
|
|
78
|
+
|
|
79
|
+
testSetup = await testRender(
|
|
80
|
+
<HelpPane
|
|
81
|
+
paneId="help:main"
|
|
82
|
+
paneType="help"
|
|
83
|
+
focused
|
|
84
|
+
width={88}
|
|
85
|
+
height={36}
|
|
86
|
+
close={() => {
|
|
87
|
+
closed += 1;
|
|
88
|
+
}}
|
|
89
|
+
/>,
|
|
90
|
+
{ width: 88, height: 36 },
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
await testSetup.renderOnce();
|
|
94
|
+
|
|
95
|
+
const lines = testSetup.captureCharFrame().split("\n");
|
|
96
|
+
const row = lines.findIndex((line) => line.includes("Open Debug Log"));
|
|
97
|
+
const col = lines[row]?.indexOf("Open Debug Log") ?? -1;
|
|
98
|
+
|
|
99
|
+
expect(row).toBeGreaterThanOrEqual(0);
|
|
100
|
+
expect(col).toBeGreaterThanOrEqual(0);
|
|
101
|
+
|
|
102
|
+
await act(async () => {
|
|
103
|
+
await testSetup!.mockMouse.click(col + 1, row);
|
|
104
|
+
await testSetup!.renderOnce();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(closed).toBe(1);
|
|
108
|
+
expect(calls).toEqual(["widget:debug"]);
|
|
109
|
+
});
|
|
110
|
+
});
|