1
1
import fs from 'fs-extra' ;
2
2
import path from 'node:path' ;
3
+ import readline from 'node:readline' ;
3
4
import { tools } from '@iobroker/js-controller-common' ;
4
5
import { isLocalObjectsDbServer , isLocalStatesDbServer } from '@iobroker/js-controller-common' ;
5
6
import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis' ;
6
7
import { MHClient , type BrowseResultEntry } from './multihostClient.js' ;
7
- import readline from 'node: readline' ;
8
+ import readlineSync from 'readline-sync ' ;
8
9
import prompt from 'prompt' ;
9
10
10
11
interface MHParams {
@@ -30,7 +31,7 @@ export class Multihost {
30
31
}
31
32
32
33
/**
33
- * Retrive config (iobroker.json content)
34
+ * Retrieve config (iobroker.json content)
34
35
*/
35
36
getConfig ( ) : ioBroker . IoBrokerJson {
36
37
let config ;
@@ -257,38 +258,9 @@ export class Multihost {
257
258
258
259
/**
259
260
* Read password from cli
260
- *
261
- * @param callback
262
261
*/
263
- readPassword ( callback : ( password : string ) => void ) : void {
264
- const rl = readline . createInterface ( {
265
- input : process . stdin ,
266
- output : process . stdout ,
267
- } ) ;
268
-
269
- function hidden ( query : string , callback : ( pw : string ) => void ) : void {
270
- const stdin = process . openStdin ( ) ;
271
- process . stdin . on ( 'data' , _char => {
272
- const char = _char . toString ( ) ;
273
- switch ( char ) {
274
- case '\n' :
275
- case '\r' :
276
- case '\u0004' :
277
- stdin . pause ( ) ;
278
- break ;
279
-
280
- default :
281
- process . stdout . write ( `\x1B[2K\x1B[200D${ query } ${ new Array ( rl . line . length + 1 ) . join ( '*' ) } ` ) ;
282
- break ;
283
- }
284
- } ) ;
285
-
286
- rl . question ( query , value => {
287
- callback ( value ) ;
288
- } ) ;
289
- }
290
-
291
- hidden ( 'Enter secret phrase for connection: ' , password => callback ( password ) ) ;
262
+ readPassword ( ) : string {
263
+ return readlineSync . question ( 'Enter secret phrase for connection: ' , { hideEchoBack : true } ) ;
292
264
}
293
265
294
266
/**
@@ -400,13 +372,12 @@ export class Multihost {
400
372
callback ( new Error ( `Invalid index: ${ answer } ` ) ) ;
401
373
} else {
402
374
if ( listEntry . auth ) {
403
- this . readPassword ( password => {
404
- if ( password ) {
405
- this . connectHelper ( mhClient , listEntry . ip ! , password , callback ) ;
406
- } else {
407
- callback ( new Error ( 'No password entered!' ) ) ;
408
- }
409
- } ) ;
375
+ const password = this . readPassword ( ) ;
376
+ if ( password ) {
377
+ this . connectHelper ( mhClient , listEntry . ip ! , password , callback ) ;
378
+ } else {
379
+ callback ( new Error ( 'No password entered!' ) ) ;
380
+ }
410
381
} else {
411
382
this . connectHelper ( mhClient , listEntry . ip ! , '' , callback ) ;
412
383
}
0 commit comments