src/commands/logs.js
/**
   * Wait for a key pressed by the user. The promise will error if an exit command in triggered by the user
   *
   * @param {string|function} matcher The key to match or a function that matches a given "key" object and returns a boolean
   * @return {Promise<true>} Returns a promise that resolves when the given key is pressed
   */
Wait for a key pressed by the user. The promise will error if an exit command in triggered by the user
@param {string|function} matcher The key to match or a function that matches a given "key" object and returns a boolean
@return {Promise} Returns a promise that resolves when the given key is pressed
Wait for a key pressed by the user . The promise will error if an exit command in triggered by the user @param { string|function } matcher The key to match or a function that matches a given " key " object and returns a boolean @return { Promise } Returns a promise that resolves when the given key is pressed
async waitForKeyPress(matcher) {
    return once(readline.createInterface({
      terminal: true,
      input: process.stdin,
      output: process.stdout,
    }).input, 'keypress').then(([_, key]) => {
      if (key.ctrl && ['z', 'c'].includes(key.name)) {
        throw new Error('exit')
      }
      process.stdout.clearLine()
      process.stdout.cursorTo(0)
      if ((typeof matcher === 'function' && matcher(key)) || matcher === key.name) {
        return true
      }
      return this.waitForKeyPress(matcher)
    })
  }
async waitForKeyPress ( matcher ) { return once ( readline . createInterface ( { terminal : true , input : process . stdin , output : process . stdout , } ) . input , 'keypress' ) . then ( ( [ _ , key ] ) => { if ( key . ctrl && [ 'z' , 'c' ] . includes ( key . name ) ) { throw new Error ( 'exit' ) } process . stdout . clearLine ( ) process . stdout . cursorTo ( 0 ) if ( ( typeof matcher === 'function' && matcher ( key ) ) || matcher === key . name ) { return true } return this . waitForKeyPress ( matcher ) } ) }
Wait for a key pressed by the user.
Wait for a key pressed by the user .
// Register a one-time event handler for a "keypress input" // Handle an exit sequence and throw an error to fail the promise // Clear the line to prevent input from showing // Check if the key matches // Queue the same event handler if the key didn't match