- Fixed default inode sorting order from being highest to lowes to lowest to highest (bug)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { Signal } from "./signal";
|
||||
import type { Signal, SIGNAL_MAP } from "./signal";
|
||||
|
||||
export interface CommandIO {
|
||||
writeStdout(data: Uint8Array): void;
|
||||
writeStderr(data: Uint8Array): void;
|
||||
getSignal(): Promise<Signal>;
|
||||
sendSignal(sig: SIGNAL_MAP): void;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ import type { CommandDescriptor, CommandOutput } from "@core/command";
|
||||
import type { CommandIO } from "@core/command_io";
|
||||
import { createSuccessResult, type ResultSuccess } from "@core/result";
|
||||
import type { ShellState } from "@core/shell_state";
|
||||
import { SIGNAL_MAP } from "@core/signal";
|
||||
import type { ShellError } from "@core/util/errors";
|
||||
|
||||
export const COMMAND_NAME = "clear";
|
||||
|
||||
async function main(io: CommandIO, state: ShellState, __args: string[]): Promise<CommandOutput<ShellError>> {
|
||||
io.writeStdout(new TextEncoder().encode("\x1b[2J\x1b[0;0H"));
|
||||
io.sendSignal(SIGNAL_MAP.CLR);
|
||||
|
||||
const result: ResultSuccess = createSuccessResult(COMMAND_NAME);
|
||||
|
||||
|
||||
+10
-14
@@ -237,15 +237,8 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
}
|
||||
}
|
||||
|
||||
if (options.long) {
|
||||
for (const entry of entries) {
|
||||
listDirEntries(entry);
|
||||
}
|
||||
} else {
|
||||
for (const entry of entries) {
|
||||
//shortDirEntries(entry);
|
||||
}
|
||||
io.writeStdout(e.encode(`No support for short format yet\n`));
|
||||
for (const entry of entries) {
|
||||
listDirEntries(entry);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -257,7 +250,7 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
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`));
|
||||
if (options.long) io.writeStdout(e.encode(`total ${Object.entries(node.children).length}\n`));
|
||||
|
||||
let children: DirEntry[] = Array.from(node.children.entries()).map(([name, inode]) => ({
|
||||
name,
|
||||
@@ -271,11 +264,15 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
|
||||
if (options.long) {
|
||||
longMode(io, state, children);
|
||||
if (options.recursive) io.writeStdout(e.encode("\n"));
|
||||
} else {
|
||||
//shortMode(io, state, children);
|
||||
}
|
||||
|
||||
if (options.recursive) {
|
||||
io.writeStdout(e.encode("\n"));
|
||||
|
||||
for (const c of children) {
|
||||
// Skip if names match . or ..
|
||||
if (c.name.match(/^[.]{1,2}$/)) continue;
|
||||
const child = state.filesystem.getNode(c.ptr)!;
|
||||
if (child.type === NodeType.Directory) {
|
||||
@@ -291,8 +288,9 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
}
|
||||
}
|
||||
|
||||
function shortMode(io: CommandIO, state: ShellState, children: DirEntry[]): void {}
|
||||
|
||||
function longMode(io: CommandIO, state: ShellState, children: DirEntry[]): void {
|
||||
const e = new TextEncoder();
|
||||
const buff: Uint8Array[] = [];
|
||||
const nodes: DirEntry[] = [...children];
|
||||
|
||||
@@ -440,8 +438,6 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
||||
}
|
||||
}
|
||||
|
||||
//function normalMode(io: CommandIO, state: ShellState, flags: string[], args: string[]): void {}
|
||||
|
||||
export const descriptor: CommandDescriptor = {
|
||||
fn: main,
|
||||
flags: [
|
||||
|
||||
@@ -6,6 +6,7 @@ export type Signal = {
|
||||
};
|
||||
|
||||
export enum SIGNAL_MAP {
|
||||
CLR = 0,
|
||||
SIGINT = 2,
|
||||
SIGTERM = 3,
|
||||
SIGKILL = 9,
|
||||
|
||||
@@ -131,7 +131,7 @@ function compareNode(
|
||||
}
|
||||
|
||||
case SortNodeBy.INODE: {
|
||||
return r ? a.ptr.inode - b.ptr.inode : b.ptr.inode - a.ptr.inode;
|
||||
return r ? b.ptr.inode - a.ptr.inode : a.ptr.inode - b.ptr.inode;
|
||||
}
|
||||
|
||||
case SortNodeBy.TYPE: {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import { SIGNAL_MAP } from "@core/signal";
|
||||
import { resolvePointerToHome } from "@core/util/path_resolver";
|
||||
import { Termos } from "./entry";
|
||||
|
||||
@@ -34,6 +35,10 @@ shell.on("result", payload => {
|
||||
process.stdout.write("\n" + resolvePointerToHome(payload.state, getCurrentSession(payload.state).cwd) + "\n> ");
|
||||
});
|
||||
|
||||
shell.on("signal", payload => {
|
||||
if (payload.sig === SIGNAL_MAP.CLR) console.clear();
|
||||
});
|
||||
|
||||
shell.on("stdout", payload => {
|
||||
const decoded = new TextDecoder().decode(payload.data);
|
||||
process.stdout.write(decoded);
|
||||
|
||||
@@ -52,8 +52,13 @@ export class Process {
|
||||
}
|
||||
}
|
||||
|
||||
private _sendSignal(sig: SIGNAL_MAP): void {
|
||||
this._EventEmitter.emit("signal", { pid: this.PID, sig: sig });
|
||||
}
|
||||
|
||||
public execute(): void {
|
||||
const io: CommandIO = {
|
||||
sendSignal: (sig: SIGNAL_MAP) => this._sendSignal(sig),
|
||||
writeStdout: (data: Uint8Array) => this.writeToOutput(this._StdoutChunks, "stdout", data),
|
||||
writeStderr: (data: Uint8Array) => this.writeToOutput(this._StderrChunks, "stderr", data),
|
||||
getSignal: () => {
|
||||
|
||||
@@ -16,6 +16,7 @@ export class ProcessManager {
|
||||
const process = new Process(pid, state, descriptor, args);
|
||||
this._Processes.set(pid, process);
|
||||
|
||||
process.on("signal", payload => this._EventEmitter.emit("signal", payload));
|
||||
process.on("stdout", payload => this._EventEmitter.emit("stdout", payload));
|
||||
process.on("stderr", payload => this._EventEmitter.emit("stderr", payload));
|
||||
process.on("result", payload => {
|
||||
|
||||
@@ -9,6 +9,11 @@ import { tokenize } from "@core/util/parser";
|
||||
import { EventEmitter } from "./event_emitter";
|
||||
import { ProcessManager } from "./process_manager";
|
||||
|
||||
export interface TTYState {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export class Shell {
|
||||
private _State: Readonly<ShellState>;
|
||||
private _Session: SessionState;
|
||||
@@ -42,6 +47,7 @@ export class Shell {
|
||||
if (this.BoundPID === payload.pid) this.BoundPID = null;
|
||||
this._EventEmitter.emit("result", payload);
|
||||
});
|
||||
this._ProcessManager.on("signal", payload => this._EventEmitter.emit("signal", payload));
|
||||
}
|
||||
|
||||
public async execute(input: string): Promise<void> {
|
||||
@@ -130,4 +136,5 @@ export interface ShellEventMap {
|
||||
stdout: { pid: number; data: Uint8Array };
|
||||
stderr: { pid: number; data: Uint8Array };
|
||||
result: { pid: number; result: Result<ShellError>; state: ShellState };
|
||||
signal: { pid: number; sig: SIGNAL_MAP };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user