Code Monkey home page Code Monkey logo

Comments (5)

cronvel avatar cronvel commented on August 20, 2024

Hi,

I'm aware of this issue, but there isn't much to do. The lib is not to blame for this, that's the way Node.js deals with stdin that cause this. You should explicitly close the app at the end of the terminate() function.

You can replace your terminate() function by:

function terminate() {
  term.processExit() ;
}

This will turn grabInput off, perform some cleanup and exit.
term.processExit() accepts an exit code as argument.

from terminal-kit.

freeall avatar freeall commented on August 20, 2024

Hi,

Thanks for your answer. You are right that I could do process.exit(), but that doesn't seem like the best solution.

I'm not sure you're right about the stdin. but I don't think that's entirely correct. If you look at this readline example:

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('Press enter', (answer) => {
  rl.close();
});

It terminates after you press enter. I'm guessing it could be fixed in terminal-kit by closing the input stream when the user does grabInput(false), or am I wrong?

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

Yes, closing the input stream would terminate the process.

When grab-input is turned off, it only removes the input stream listener. It is possible to turn grab-input on later, so it doesn't make sense to close the stream.

from terminal-kit.

freeall avatar freeall commented on August 20, 2024

To me it should be possible to do it the same way that readline does. It feels a little off that after I am done reading input I now have to use process.exit when I want to, at some point, close the program.

Imagine I'm making a program where I ask the user for something, and at some point my program starts to download a file. Now it becomes scary if I closed the program before the download stream was done.

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

Well, you should know when your app should be closed or not ;)

Seriously, if at some point this is a problem for you, you may consider using async-kit's async.exit(). That will help you to cleanly exit your app.

Whenever I get some time, I will explore the readline() code source to see if there is some tricks to achieve that cleanly. Closing stdin is not an option.

from terminal-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.