How can I use keypress and prompt libraries same time?

Ionică Bizău

I want to catch all key presses, but also, use prompt library.

var Prompt = require("prompt")
  , Keypress = require("keypress")
  ;

Prompt.start();
var schema = {
    properties: {
        name: {
            required: true
          , description: "What's your name?"
        }
    }
};

Prompt.get(schema, function (err, result) {
    console.log(err || result);
});

process.stdin.on("keypress", function (ch, key) {
    console.log(key);
    if (key && key.name === "c" && key.ctrl) {
        process.exit();
    }
});

The issue is that after prompt callback is called, keypress events are not triggered anymore.

Is there a solution/work around for this?

Ionică Bizău

I found the following workaround:

// Override get method
var oldGet = Prompt.get;
Prompt.get = function (schema, callback) {
    oldGet.call(this, schema, function () {
        process.stdin.setRawMode(true);
        process.stdin.resume();
        callback.apply(this, arguments);
    });
};

I used this in the cli-github project.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I conditionally include two differently named libraries of the same version for a cross-compile project in Eclipse?

분류에서Dev

How can I ping multiple IP addresses at the same time?

분류에서Dev

How can I broadcast and pick up a keypress event in AngularJS?

분류에서Dev

How can I force git to prompt me for the email address to use, if not set in the repo config?

분류에서Dev

How can I change the prompt of the terminal permanently

분류에서Dev

How can I automate inputting text into a prompt?

분류에서Dev

How can I use the same ViewController from a storyboard with different sizes?

분류에서Dev

How can I use date and time selectors in OneNote 2010?

분류에서Dev

How can I implement a Zoom Panel with Java Swing libraries

분류에서Dev

How can I change my number validation from a form to a prompt?

분류에서Dev

How can I shorten my command line (bash) prompt?

분류에서Dev

How can I use function arguments where variables exist with the same name?

분류에서Dev

iOS versions: if I have an app with specific "minor" device required, how can I use benefits of newer devices in the same app?

분류에서Dev

How i can use a criteria in cicle for i

분류에서Dev

How can I program two simultaneous key press events in tkinter to move a canvas item diagonally using a dictionary of keypress events?

분류에서Dev

Can I get the same object with its vales and use it in a different method?

분류에서Dev

How can I use const fields of a child class in inherited methods where the parent class has the same const fields?

분류에서Dev

How can I convert date time from time zone A to time zone B in Joda time?

분류에서Dev

How can I use the selected category in a databaseQueryProcessor?

분류에서Dev

How can I use onItemSelected in Android?

분류에서Dev

How can I use relative path in CodeIgniter?

분류에서Dev

How can I use CUDA without the monitor?

분류에서Dev

How can I use sharedPreferences in baseAdapter?

분류에서Dev

How can I use typescript in Aptana Studio?

분류에서Dev

How can I use progressbar in Android

분류에서Dev

How long can i use WSAPI 1.42

분류에서Dev

How can i use data in an array in a query

분류에서Dev

How can i use $_POST if the name is a variable?

분류에서Dev

How can I use another drive with Owncloud?

Related 관련 기사

  1. 1

    How can I conditionally include two differently named libraries of the same version for a cross-compile project in Eclipse?

  2. 2

    How can I ping multiple IP addresses at the same time?

  3. 3

    How can I broadcast and pick up a keypress event in AngularJS?

  4. 4

    How can I force git to prompt me for the email address to use, if not set in the repo config?

  5. 5

    How can I change the prompt of the terminal permanently

  6. 6

    How can I automate inputting text into a prompt?

  7. 7

    How can I use the same ViewController from a storyboard with different sizes?

  8. 8

    How can I use date and time selectors in OneNote 2010?

  9. 9

    How can I implement a Zoom Panel with Java Swing libraries

  10. 10

    How can I change my number validation from a form to a prompt?

  11. 11

    How can I shorten my command line (bash) prompt?

  12. 12

    How can I use function arguments where variables exist with the same name?

  13. 13

    iOS versions: if I have an app with specific "minor" device required, how can I use benefits of newer devices in the same app?

  14. 14

    How i can use a criteria in cicle for i

  15. 15

    How can I program two simultaneous key press events in tkinter to move a canvas item diagonally using a dictionary of keypress events?

  16. 16

    Can I get the same object with its vales and use it in a different method?

  17. 17

    How can I use const fields of a child class in inherited methods where the parent class has the same const fields?

  18. 18

    How can I convert date time from time zone A to time zone B in Joda time?

  19. 19

    How can I use the selected category in a databaseQueryProcessor?

  20. 20

    How can I use onItemSelected in Android?

  21. 21

    How can I use relative path in CodeIgniter?

  22. 22

    How can I use CUDA without the monitor?

  23. 23

    How can I use sharedPreferences in baseAdapter?

  24. 24

    How can I use typescript in Aptana Studio?

  25. 25

    How can I use progressbar in Android

  26. 26

    How long can i use WSAPI 1.42

  27. 27

    How can i use data in an array in a query

  28. 28

    How can i use $_POST if the name is a variable?

  29. 29

    How can I use another drive with Owncloud?

뜨겁다태그

보관