From cf04d4da15faf83e48803fd8b8cf59a3679b782d Mon Sep 17 00:00:00 2001 From: b1ek Date: Thu, 4 May 2023 23:44:10 +1000 Subject: [PATCH] improve ps --- src/emulator/commands/ps.js | 14 +++++++++----- src/lib/sleep.js | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/lib/sleep.js diff --git a/src/emulator/commands/ps.js b/src/emulator/commands/ps.js index ad1947b..b2e2a49 100644 --- a/src/emulator/commands/ps.js +++ b/src/emulator/commands/ps.js @@ -1,20 +1,24 @@ const { Terminal } = require("xterm"); +const sleep = require('../../lib/sleep'); /** * * @param {string[]} argv * @param {Terminal} terminal */ -module.exports = (argv, terminal) => { +module.exports = async (argv, terminal) => { if (argv.indexOf('--help') != -1) { terminal.write( `Usage: ${argv[0]} [OPTIONS] Show current process list`); return; } - terminal.write( -`\tPID\tTTY\tTIME\tCMD - 42\tpts/0\t00:00:00\tzsh - 43\tpts/0\t00:00:00\tps + terminal.write('PID\tTTY\tTIME\t\tCMD'); + + await sleep(5); + + terminal.write(` +1\tpts/0\t00:00:00\tzsh +2\tpts/0\t00:00:00\tps `); } \ No newline at end of file diff --git a/src/lib/sleep.js b/src/lib/sleep.js new file mode 100644 index 0000000..8d255e6 --- /dev/null +++ b/src/lib/sleep.js @@ -0,0 +1 @@ +module.exports = (timeout) => new Promise(r => setTimeout(r, timeout)); \ No newline at end of file