Implement edit and exit
This commit is contained in:
@@ -1,11 +1,22 @@
|
||||
import * as readline from 'node:readline'
|
||||
import {BehaviorSubject} from "../util/subject.js";
|
||||
import {Lifecycle, LifecycleAware} from "../util/lifecycle.js";
|
||||
import {StreamLogger} from "../util/log.js";
|
||||
import {log} from "../log.js";
|
||||
|
||||
export class Input extends BehaviorSubject<string> implements LifecycleAware {
|
||||
private rl?: readline.Interface
|
||||
private log: StreamLogger = log.getStreamLogger('input')
|
||||
|
||||
public hasPrompt(): boolean {
|
||||
return !!this.rl
|
||||
}
|
||||
|
||||
public setupPrompt(): void {
|
||||
this.log.verbose({
|
||||
setupPrompt: { hasExistingPrompt: !!this.rl },
|
||||
})
|
||||
|
||||
if ( this.rl ) {
|
||||
this.closePrompt()
|
||||
}
|
||||
@@ -25,6 +36,10 @@ export class Input extends BehaviorSubject<string> implements LifecycleAware {
|
||||
}
|
||||
|
||||
public closePrompt(): void {
|
||||
this.log.verbose({
|
||||
closePrompt: { hasExistingPrompt: !!this.rl },
|
||||
})
|
||||
|
||||
this.rl?.close()
|
||||
this.rl = undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user