@space-lens/cli 0.2.3 → 0.2.7
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 +4 -2
- package/dist/assets/index_noop-CjCJPyfq.js +2 -0
- package/dist/assets/{model-BICd3EQ5.js → model-bnrjCFAW.js} +26 -7
- package/dist/cli.mjs +61132 -2171
- package/dist/index.mjs +1 -1
- package/package.json +6 -2
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.
|
|
@@ -45,6 +45,7 @@ function createInitialTuiState() {
|
|
|
45
45
|
mode: "scan",
|
|
46
46
|
scanCursor: 0,
|
|
47
47
|
cleanCursor: 0,
|
|
48
|
+
expandedScanPaths: /* @__PURE__ */ new Set(),
|
|
48
49
|
selectedPaths: /* @__PURE__ */ new Set(),
|
|
49
50
|
confirmExecute: false,
|
|
50
51
|
status: ""
|
|
@@ -69,12 +70,13 @@ function createCleanViewModel(plan, options) {
|
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
function createScanViewModel(trees, state) {
|
|
72
|
-
const rows = trees.flatMap((tree) => flattenTree(tree));
|
|
73
|
+
const rows = [...trees].sort(compareTreeNodes).flatMap((tree) => flattenTree(tree, state.expandedScanPaths));
|
|
73
74
|
const totalSize = trees.reduce((total, tree) => total + tree.size, 0);
|
|
75
|
+
const nodeCount = trees.reduce((total, tree) => total + countTreeNodes(tree), 0);
|
|
74
76
|
const cursor = clampCursor(state.scanCursor, rows.length);
|
|
75
77
|
return {
|
|
76
78
|
title: "Space Lens",
|
|
77
|
-
summary: `${
|
|
79
|
+
summary: `${nodeCount} ${nodeCount === 1 ? "node" : "nodes"} | ${formatBytes(totalSize)}`,
|
|
78
80
|
rows: rows.map((row, index) => ({
|
|
79
81
|
...row,
|
|
80
82
|
index: index + 1,
|
|
@@ -94,6 +96,11 @@ function applyTuiAction(state, action) {
|
|
|
94
96
|
else state.cleanCursor = moveCursor(state.cleanCursor, action.delta, action.rowCount);
|
|
95
97
|
state.confirmExecute = false;
|
|
96
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;
|
|
97
104
|
case "toggle-selected":
|
|
98
105
|
if (state.selectedPaths.has(action.path)) state.selectedPaths.delete(action.path);
|
|
99
106
|
else state.selectedPaths.add(action.path);
|
|
@@ -141,7 +148,7 @@ function formatBytes(input) {
|
|
|
141
148
|
value /= 1024;
|
|
142
149
|
unit += 1;
|
|
143
150
|
}
|
|
144
|
-
return `${value.toFixed(1)} ${units[unit]}
|
|
151
|
+
return `${value.toFixed(1)} ${units[unit]}`;
|
|
145
152
|
}
|
|
146
153
|
function compareEntries(sort) {
|
|
147
154
|
return (left, right) => {
|
|
@@ -149,17 +156,29 @@ function compareEntries(sort) {
|
|
|
149
156
|
return right.size - left.size || left.path.localeCompare(right.path);
|
|
150
157
|
};
|
|
151
158
|
}
|
|
152
|
-
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));
|
|
153
163
|
const suffix = [node.ignored ? "[ignored]" : "", node.collapsed ? "[collapsed]" : ""].filter(Boolean).join(" ");
|
|
164
|
+
const marker = hasChildren ? expanded ? "▾ " : "▸ " : " ";
|
|
154
165
|
return [{
|
|
155
|
-
label: `${" ".repeat(depth)}${node.name}${suffix ? ` ${suffix}` : ""}`,
|
|
166
|
+
label: `${" ".repeat(depth)}${marker}${node.name}${suffix ? ` ${suffix}` : ""}`,
|
|
156
167
|
path: node.path,
|
|
157
168
|
size: node.size,
|
|
158
169
|
sizeLabel: formatBytes(node.size),
|
|
159
170
|
depth,
|
|
160
171
|
ignored: node.ignored,
|
|
161
|
-
collapsed: node.collapsed
|
|
162
|
-
|
|
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);
|
|
163
182
|
}
|
|
164
183
|
function moveCursor(cursor, delta, rowCount) {
|
|
165
184
|
if (rowCount <= 0) return 0;
|