-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (54 loc) · 1.77 KB
/
index.js
File metadata and controls
61 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @git-stunts/git-warp-tui — Interactive terminal graph browser.
*
* Public API: startTui()
*/
import { App } from './src/app/App.js';
import { NodeTerminalAdapter } from './src/adapters/NodeTerminalAdapter.js';
import { loadGraphData } from './src/data/GraphDataSource.js';
import { loadPatchData } from './src/data/PatchDataSource.js';
/**
* Start the interactive TUI.
*
* @param {Object} options
* @param {string} options.repo - path to git repository
* @param {string} options.graph - graph name
* @param {string} [options.mode='list'] - initial mode
* @returns {Promise<void>} resolves when user quits
*/
export async function startTui(options) {
const { repo, graph, mode = 'list' } = options;
let data;
try {
data = await loadGraphData({ repo, graph });
} catch (err) {
const msg = err.message || String(err);
if (msg.includes('Cannot find module') || msg.includes('ERR_MODULE_NOT_FOUND')) {
throw new Error(
'@git-stunts/git-warp is not installed. Install with: npm i @git-stunts/git-warp',
);
}
throw new Error(`Failed to load graph "${graph}" from ${repo}: ${msg}`);
}
// Lazy-load layoutGraph from git-warp's visualization export
let layoutGraph = null;
try {
const viz = await import('@git-stunts/git-warp/visualization');
layoutGraph = viz.layoutGraph;
} catch {
// Visualization module not available — graph mode won't have layout
}
const terminal = new NodeTerminalAdapter();
const app = new App(terminal, {
nodes: data.nodes,
edges: data.edges,
mode,
layoutGraph,
dataSources: {
loadGraphData: () => loadGraphData({ repo, graph }),
loadPatchData: () => loadPatchData({ repo, graph }),
},
});
return app.start();
}
export { App } from './src/app/App.js';