@samitouri / QOSami-HFS / commits / fdc63ad0

simplified console handling

Massimo Melina committed Feb 28, 2026 at 16:02 UTC fdc63ad04cdfcfea02942f411b5f5856e53fd3ed
1 file changed +10 -24
src/commands.ts
+10 -24
@@ -15,8 +15,6 @@ import { downloadPlugin } from './github'
15 import { Dict, formatBytes, formatSpeed, formatTimestamp, makeMatcher } from './cross'
16 import apiMonitor from './api.monitor'
17 import { argv } from './argv'
18 -import { consoleHint } from './consoleLog'
19 -import { debounceAsync } from './debounceAsync'
18
19 if (!argv.updating && !showHelp) {
20 try {
@@ -27,42 +25,30 @@ if (!argv.updating && !showHelp) {
25 .on('SIGINT', () => process.emit('SIGINT')) // readline swallows the first ctrl+c unless we forward it to process-level handlers
26
27 let isClean = true
30 - let cleaning: undefined | Promise<void>
31 - const showPrompt = tty && debounceAsync(async () => {
32 - await cleaning
28 + const showPrompt = tty && _.debounce(() => {
29 if (quitting || !tty) return
30 prompter.prompt(true)
31 isClean = false
36 - }, { wait: 100 })
32 + }, 100)
33 function clean() {
34 if (isClean) return
39 - return cleaning ||= new Promise(resolve => {
40 - cursorTo(process.stdout, 0, undefined, () => { // we don't need to clean as long as the prompt is never longer than the printed line
41 - resolve()
42 - cleaning = undefined
43 - isClean = true
44 - })
45 - })
35 + // keep console methods synchronous: reposition the cursor immediately and let stream ordering preserve output sequence
36 + cursorTo(process.stdout, 0) // we don't need to clean as long as the prompt is never longer than the printed line
37 + isClean = true
38 }
39
40 showPrompt?.()
49 - // print this hint when we have not been printing anything else for a while, to not get mixed too much
50 - let printHintOnce = tty && _.debounce(() => {
51 - consoleHint("this is an interactive console, you can enter commands")
52 - printHintOnce = undefined as any // never more
53 - }, 2000)
54 - setTimeout(() => _.each(console, (v: any, k) => {
55 - if (!_.isFunction(v)) return
56 - ;(console as any)[k] = async (...args: any[]) => {
41 + for (const k of ['log', 'warn', 'error', 'debug'] as const) {
42 + const v = console[k]
43 + ;(console as any)[k] = (...args: any[]) => {
44 if (!quitting && tty)
58 - await clean()
45 + clean()
46 try { v(...args) }
47 finally {
48 showPrompt?.()
62 - printHintOnce?.()
49 }
50 }
65 - }), 1000) // avoid messing in making console methods async too soon and so preventing fatal errors to be printed before process.exit – TODO investigate how to avoid this async thing at all
51 + }
52
53 }
54 catch {