@space-lens/cli 0.2.2 → 0.2.6
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
CHANGED
|
@@ -21,5 +21,7 @@ The package uses `@uniview/tui-solid` and requires Node.js 20 or newer.
|
|
|
21
21
|
|
|
22
22
|
## Controls
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
`
|
|
24
|
+
In Scan mode, use `j/k` or arrows to move and `enter` to expand or collapse
|
|
25
|
+
the active folder. In Clean mode, use `space` to select, `a` to select all,
|
|
26
|
+
and `x` followed by `enter` to delete. `tab` switches modes; `esc`, `q`, and
|
|
27
|
+
Ctrl-C cancel or exit.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
//#region src/cli-config.ts
|
|
2
3
|
var PRESETS = [
|
|
3
4
|
"node",
|
|
@@ -44,6 +45,7 @@ function createInitialTuiState() {
|
|
|
44
45
|
mode: "scan",
|
|
45
46
|
scanCursor: 0,
|
|
46
47
|
cleanCursor: 0,
|
|
48
|
+
expandedScanPaths: /* @__PURE__ */ new Set(),
|
|
47
49
|
selectedPaths: /* @__PURE__ */ new Set(),
|
|
48
50
|
confirmExecute: false,
|
|
49
51
|
status: ""
|
|
@@ -68,12 +70,13 @@ function createCleanViewModel(plan, options) {
|
|
|
68
70
|
};
|
|
69
71
|
}
|
|
70
72
|
function createScanViewModel(trees, state) {
|
|
71
|
-
const rows = trees.flatMap((tree) => flattenTree(tree));
|
|
73
|
+
const rows = [...trees].sort(compareTreeNodes).flatMap((tree) => flattenTree(tree, state.expandedScanPaths));
|
|
72
74
|
const totalSize = trees.reduce((total, tree) => total + tree.size, 0);
|
|
75
|
+
const nodeCount = trees.reduce((total, tree) => total + countTreeNodes(tree), 0);
|
|
73
76
|
const cursor = clampCursor(state.scanCursor, rows.length);
|
|
74
77
|
return {
|
|
75
78
|
title: "Space Lens",
|
|
76
|
-
summary: `${
|
|
79
|
+
summary: `${nodeCount} ${nodeCount === 1 ? "node" : "nodes"} | ${formatBytes(totalSize)}`,
|
|
77
80
|
rows: rows.map((row, index) => ({
|
|
78
81
|
...row,
|
|
79
82
|
index: index + 1,
|
|
@@ -93,6 +96,11 @@ function applyTuiAction(state, action) {
|
|
|
93
96
|
else state.cleanCursor = moveCursor(state.cleanCursor, action.delta, action.rowCount);
|
|
94
97
|
state.confirmExecute = false;
|
|
95
98
|
return;
|
|
99
|
+
case "toggle-expanded":
|
|
100
|
+
if (state.expandedScanPaths.has(action.path)) state.expandedScanPaths.delete(action.path);
|
|
101
|
+
else state.expandedScanPaths.add(action.path);
|
|
102
|
+
state.confirmExecute = false;
|
|
103
|
+
return;
|
|
96
104
|
case "toggle-selected":
|
|
97
105
|
if (state.selectedPaths.has(action.path)) state.selectedPaths.delete(action.path);
|
|
98
106
|
else state.selectedPaths.add(action.path);
|
|
@@ -140,7 +148,7 @@ function formatBytes(input) {
|
|
|
140
148
|
value /= 1024;
|
|
141
149
|
unit += 1;
|
|
142
150
|
}
|
|
143
|
-
return `${value.toFixed(1)} ${units[unit]}
|
|
151
|
+
return `${value.toFixed(1)} ${units[unit]}`;
|
|
144
152
|
}
|
|
145
153
|
function compareEntries(sort) {
|
|
146
154
|
return (left, right) => {
|
|
@@ -148,17 +156,29 @@ function compareEntries(sort) {
|
|
|
148
156
|
return right.size - left.size || left.path.localeCompare(right.path);
|
|
149
157
|
};
|
|
150
158
|
}
|
|
151
|
-
function flattenTree(node, depth = 0) {
|
|
159
|
+
function flattenTree(node, expandedPaths, depth = 0) {
|
|
160
|
+
const hasChildren = node.children.length > 0;
|
|
161
|
+
const expandable = hasChildren && depth > 0;
|
|
162
|
+
const expanded = hasChildren && (depth === 0 || expandedPaths.has(node.path));
|
|
152
163
|
const suffix = [node.ignored ? "[ignored]" : "", node.collapsed ? "[collapsed]" : ""].filter(Boolean).join(" ");
|
|
164
|
+
const marker = hasChildren ? expanded ? "▾ " : "▸ " : " ";
|
|
153
165
|
return [{
|
|
154
|
-
label: `${" ".repeat(depth)}${node.name}${suffix ? ` ${suffix}` : ""}`,
|
|
166
|
+
label: `${" ".repeat(depth)}${marker}${node.name}${suffix ? ` ${suffix}` : ""}`,
|
|
155
167
|
path: node.path,
|
|
156
168
|
size: node.size,
|
|
157
169
|
sizeLabel: formatBytes(node.size),
|
|
158
170
|
depth,
|
|
159
171
|
ignored: node.ignored,
|
|
160
|
-
collapsed: node.collapsed
|
|
161
|
-
|
|
172
|
+
collapsed: node.collapsed,
|
|
173
|
+
expandable,
|
|
174
|
+
expanded
|
|
175
|
+
}, ...expanded ? [...node.children].sort(compareTreeNodes).flatMap((child) => flattenTree(child, expandedPaths, depth + 1)) : []];
|
|
176
|
+
}
|
|
177
|
+
function compareTreeNodes(left, right) {
|
|
178
|
+
return right.size - left.size || left.name.localeCompare(right.name);
|
|
179
|
+
}
|
|
180
|
+
function countTreeNodes(node) {
|
|
181
|
+
return 1 + node.children.reduce((total, child) => total + countTreeNodes(child), 0);
|
|
162
182
|
}
|
|
163
183
|
function moveCursor(cursor, delta, rowCount) {
|
|
164
184
|
if (rowCount <= 0) return 0;
|