- fixed a bug in dnTaverseTree where children would get pushed into the result in reverse order
- added an inode display to the `printTree` algorithm - removed a redundant type in *`signal.ts`* - improved `resolveInode` to now take `ShellState` instead of `FileSystem` and added an optional `abs` *`boolean`* argument to determine if the retuned path should be normalized or absolute - implemented a builtin `TreeNode` quicksort function - changed the `TreeNodeType` to a numeric enum - added a standalone `Posix` class that holds a const with character weights compliant with posix
This commit is contained in:
+11
-9
@@ -69,8 +69,10 @@ async function main(
|
||||
nodes.push(...treeArray.filter(node => state.filesystem.getNode(node)?.type !== TreeNodeType.File));
|
||||
}
|
||||
|
||||
for (const node of nodes) {
|
||||
const treenode: DirectoryNode = state.filesystem.getNode(node) as DirectoryNode;
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const treenode: DirectoryNode = state.filesystem.getNode(nodes[i]!) as DirectoryNode;
|
||||
|
||||
io.writeStdout(new TextEncoder().encode(`total ${Object.entries(treenode.children).length}\n`));
|
||||
|
||||
// Object.entries returns the touple of Record<string, number> so we get the number by doing c[1] as index 1 in the touple is the number
|
||||
// We do null assertion because we already made sure in the recursive check that all inodes are correct
|
||||
@@ -80,6 +82,7 @@ async function main(
|
||||
|
||||
if (fSet.has("l") || fSet.has("g") || fSet.has("o")) {
|
||||
longMode(io, state, children, fSet);
|
||||
io.writeStdout(new TextEncoder().encode("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,13 +131,12 @@ function longMode(io: CommandIO, state: ShellState, nodes: TreeNode[], flags: Se
|
||||
);
|
||||
// Holy abomination, pad the stringified bytesize number with whitespaces so the actual length of the string matches across all rows
|
||||
// Sets the folder size to an arbitrary 4096, could change it later to smth else
|
||||
io.writeStdout(
|
||||
e.encode(
|
||||
node.type === TreeNodeType.File
|
||||
? node.content.byteSize().toString().padStart(maxSizeWidth, " ") + " "
|
||||
: "4096".padStart(maxSizeWidth, " ") + " ",
|
||||
),
|
||||
);
|
||||
const size =
|
||||
node.type === TreeNodeType.File
|
||||
? node.content.byteSize().toString().padStart(maxSizeWidth, " ") + " "
|
||||
: "4096".padStart(maxSizeWidth, " ") + " ";
|
||||
|
||||
io.writeStdout(e.encode(size));
|
||||
|
||||
// for now only mtime, need a helper function for all the formatting later on
|
||||
const mtime = new Date(node.mtime);
|
||||
|
||||
Reference in New Issue
Block a user