- Fixed sort.ts

- Fixed `cd`
This commit is contained in:
2026-11-10 13:13:38 +01:00
parent 00200b4c75
commit 492f1ba372
7 changed files with 160 additions and 98 deletions
+8 -8
View File
@@ -1,6 +1,6 @@
import type { CommandDescriptor, CommandOutput } from "@core/command";
import type { CommandIO } from "@core/command_io";
import { type DirectoryNode } from "@core/filesystem/node";
import { type DirectoryNode, type NodePointer } from "@core/filesystem/node";
import { createErrorResult, createSuccessResult } from "@core/result";
import { getCurrentSession } from "@core/session_manager";
import type { ShellState } from "@core/shell_state";
@@ -13,7 +13,7 @@ import { convertToUnit } from "@termos/util/format_unit";
export const COMMAND_NAME = "ls";
async function main(io: CommandIO, state: ShellState, args: string[]): Promise<CommandOutput<ShellError>> {
const entries: { inode: number; path: string }[] = [];
const entries: { ptr: NodePointer; path: string }[] = [];
const paths: string[] = [];
const e = new TextEncoder();
@@ -211,11 +211,11 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
const session = getCurrentSession(state);
if (paths.length === 0) {
entries.push({ inode: session.cwd, path: "." });
entries.push({ ptr: session.cwd, path: "." });
} else {
for (const path of paths) {
const inode = resolvePath(state, path);
if (inode === -1) {
const ptr = resolvePath(state, path);
if (!state.filesystem.exists(ptr)) {
return {
state,
result: createErrorResult(
@@ -226,7 +226,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
),
};
}
entries.push({ inode: inode, path });
entries.push({ ptr, path });
}
}
@@ -246,8 +246,8 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
result: createSuccessResult(COMMAND_NAME),
};
function listDirEntries(entry: { inode: number; path: string }): void {
const node = state.filesystem.getNode(entry.inode) as DirectoryNode;
function listDirEntries(entry: { ptr: NodePointer; path: string }): void {
const node = state.filesystem.getNode(entry.ptr) as DirectoryNode;
if (options.recursive) io.writeStdout(e.encode(`${entry.path}:\n`));
io.writeStdout(e.encode(`total ${Object.entries(node.children).length}\n`));