Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
"assignments"
],
"author": "alreadybored",
"license": "ISC"
"license": "ISC",
"dependencies": {
"redline": "^1.0.1",
"tar-stream": "^3.1.8"
}
}
58 changes: 54 additions & 4 deletions src/cli/interactive.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
import readline from "node:readline";
import { stdin as input, stdout as output } from "node:process";

const interactive = () => {
// Write your code here
// Use readline module for interactive CLI
// Support commands: uptime, cwd, date, exit
// Handle Ctrl+C and unknown commands
const rl = readline.createInterface({
input,
output,
prompt: "> ",
});

function handleCommand(cmd) {
const command = cmd.trim();

switch (command) {
case "uptime":
console.log(`Uptime: ${process.uptime().toFixed(2)}s`);
break;

case "cwd":
console.log(process.cwd());
break;

case "date":
console.log(new Date().toISOString());
break;

case "exit":
console.log("Goodbye!");
rl.close();
return;

case "":
break;

default:
console.log("Unknown command");
}

rl.prompt();
}

rl.prompt();

rl.on("line", handleCommand);

rl.on("close", () => {
console.log("Goodbye!");
process.exit(0);
});

// Handle Ctrl+C
rl.on("SIGINT", () => {
console.log("Goodbye!");
rl.close();
});
};

interactive();
58 changes: 54 additions & 4 deletions src/cli/progress.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
const progress = () => {
// Write your code here
// Simulate progress bar from 0% to 100% over ~5 seconds
// Update in place using \r every 100ms
// Format: [████████████████████ ] 67%
const args = process.argv.slice(2);

const getArg = (name, def) => {
const index = args.indexOf(name);
if (index !== -1 && args[index + 1]) {
return args[index + 1];
}
return def;
};

const duration = Number(getArg("--duration", 5000));
const interval = Number(getArg("--interval", 100));
const length = Number(getArg("--length", 30));
const colorHex = getArg("--color", null);

let colorStart = "";
const colorEnd = "\x1b[0m";

// Validate hex color
if (colorHex && /^#([0-9a-fA-F]{6})$/.test(colorHex)) {
const r = parseInt(colorHex.slice(1, 3), 16);
const g = parseInt(colorHex.slice(3, 5), 16);
const b = parseInt(colorHex.slice(5, 7), 16);

// ANSI 24-bit color
colorStart = `\x1b[38;2;${r};${g};${b}m`;
}

const steps = Math.ceil(duration / interval);
let currentStep = 0;

const timer = setInterval(() => {
currentStep++;

const percent = Math.min(Math.round((currentStep / steps) * 100), 100);
const filledLength = Math.round((percent / 100) * length);
const emptyLength = length - filledLength;

const filledBarRaw = "█".repeat(filledLength);
const filledBar = colorStart
? `${colorStart}${filledBarRaw}${colorEnd}`
: filledBarRaw;

const emptyBar = " ".repeat(emptyLength);

const bar = `[${filledBar}${emptyBar}] ${percent}%`;

process.stdout.write("\r" + bar);

if (percent >= 100) {
clearInterval(timer);
process.stdout.write("\nDone!\n");
}
}, interval);
};

progress();
36 changes: 30 additions & 6 deletions src/cp/execCommand.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import { spawn } from "node:child_process";

const execCommand = () => {
// Write your code here
// Take command from CLI argument
// Spawn child process
// Pipe child stdout/stderr to parent stdout/stderr
// Pass environment variables
// Exit with same code as child
const commandString = process.argv[2];

if (!commandString) {
console.error("No command provided.");
process.exit(1);
}

const parts = commandString.split(" ");
const command = parts[0];
const args = parts.slice(1);

const child = spawn(command, args, {
stdio: ["inherit", "pipe", "pipe"],
env: process.env,
shell: false,
});

child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);

child.on("close", (code) => {
process.exit(code ?? 0);
});

child.on("error", (err) => {
console.error(err.message);
process.exit(1);
});
};

execCommand();
1 change: 1 addition & 0 deletions src/fs/files/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asdasd
1 change: 1 addition & 0 deletions src/fs/files/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aaa123
Loading