faketerminal icon indicating copy to clipboard operation
faketerminal copied to clipboard

how we can use `requestPassword`?

Open A1Gard opened this issue 4 years ago • 4 comments

My sample:


window.FakeTerminal.command.ops = function (instance) {

        //  Extend the base command
        window.FakeTerminal.command.apply(this, arguments);

        var base = this;

        base.info = function () {
            return {
                private: false,
                description: 'This command doesn\'t do anything terribly exciting'
            };
        };


        base.execute = function (foo, bar) {
            instance.output.write('The value of foo is: ' + foo);
            instance.output.write('The value of bar is: ' + bar);
            base.deferred.resolve();
            var xx = '';
            var ss = instance.input.requestPassword(xx);
            return base.deferred.promise();
        };

        return base;
    };

What's the problem?

A1Gard avatar Oct 16 '20 03:10 A1Gard

@A1Gard have you figured this out yet? @hellopablo how do we check the value of the password?

oxmc avatar Dec 16 '21 10:12 oxmc

@A1Gard i found the solution:

window.FakeTerminal.command.shutdown = function (instance) {
  window.FakeTerminal.command.apply(this, arguments);
  var base = this;
  base.info = function () {
    return {
      private: false,
      description: 'This command shuts the os down.'
    };
  };
  base.execute = function () {
    instance.output.write(`<question>Please enter your password:</question>`);
    instance.input.request("password").done(function(value) {
      if (value == "AtyysCyBDnESysTmsT1000") {
        instance.output.write(`<info>Initiating shutdown sequence...</info>`);
        base.deferred.resolve();
      } else {
        instance.output.write(`<error>ERROR: Aborting shutdown sequence.</error>`);
        instance.output.write(`<error>ERROR: Incorrect password.</error>`);
        base.deferred.resolve();
      };
    }).fail(function() {
      instance.output.write("ERROR FATAL");
      base.deferred.resolve();
    });
    return base.deferred.promise();
  };
  return base;
};

oxmc avatar Dec 16 '21 11:12 oxmc

Thanks @oxmc - sorry @A1Gard I've not had/made time to look at this repository in years (literally).

I do want to revisit this project and bring it to the modern world... one day 😅

hellopablo avatar Dec 16 '21 11:12 hellopablo

@hellopablo if you do look into the repo, please create a docs site, like xterm.js

So users can refer to it.

oxmc avatar Dec 16 '21 11:12 oxmc