Giter Club home page Giter Club logo

Comments (9)

marcushultman avatar marcushultman commented on July 22, 2024 1

@c4spar I've opened another issue denoland/deno#8343 that would help solve this. If we could use another TTY mode that forwards keystrokes, but handles interrupts/suspend, the whole problem disappears.

from deno-cliffy.

c4spar avatar c4spar commented on July 22, 2024

Hi @marcushultman,

Yes, we should definitely improve that! And if you want to make a PR this would be great 👍 But i'm not shure if we should use a callback method.

I think the best would be if it were possible to emit a SIGINT signal on ctrl+c. Then you can simply register a handler with Deno.signal() or Deno.signals.interrupt(). But I haven't found a way to emit a signal yet.

If we use a callback method, than you have to register two SIGINT handler. One with the prompt method and one with Deno.singal() in case the prompt isn't running actually.

from deno-cliffy.

marcushultman avatar marcushultman commented on July 22, 2024

@c4spar Deno.kill(Deno.pid, Deno.Signal.SIGINT); would work (it's even used in std/signal tests). I'll experiment some more on my own fork by raising a signal (the callback solution I sketched up works, but indeed requires two handlers just as you say.

from deno-cliffy.

marcushultman avatar marcushultman commented on July 22, 2024

Made a PR #106

from deno-cliffy.

c4spar avatar c4spar commented on July 22, 2024

Awesome! thanks for this PR @marcushultman.

This works great but i'm also not so happy with the --allow-run flag. Because this forces the user to disable the sandbox mode of deno and indicates that we want to run a child process but we only want to kill our own process.
Deno should provide a way to allow a script to kill itself with a SIGINT without the need of the --allow-run flag.

We could ask the user for the run permissions berfor calling Deno.kill() but than it would be possible the user disagrees and the sigint event doesn't fires and there will be also no sandboxing mode.

I found also an issue with the SIGINT handler. The default SIGINT actions wan't be restored after calling sig.dispose() atm.
For example, if you exit following script with ctrl+c, ctrl+c is no longer working for the shell prompt and other programms like tail -f <file-name>.

import { Input } from "https://raw.githubusercontent.com/marcushultman/deno-cliffy/raise-signal/prompt/input.ts";

const sigint = Deno.signals.interrupt();

(async () => {
  for await (const _ of sigint) {
    sigint.dispose();
    Deno.exit(0);
  }
})();

const name: string = await Input.prompt("What's your github user name?");
console.log({ name });
sigint.dispose();

There is already a deno issue for this: denoland/deno#7164

Maybe we should first implement the callback solution and as soon as the above bug is fixed and there is a way to trigger the SIGINT event without the need of the --allow-run flag, we can implement the new version. We can do this without a breaking change. If a callback is passed to the prompt, the callback will be executed, otherwise the kill api is used.

What do you think?

from deno-cliffy.

c4spar avatar c4spar commented on July 22, 2024

Another issue is, Deno.kill() doesn't work on windows as mentioned in the documentation: This functionality currently only works on Linux and Mac OS.
https://doc.deno.land/builtin/unstable#Deno.kill

from deno-cliffy.

marcushultman avatar marcushultman commented on July 22, 2024

I think it's not unreasonable to want a way to raise a signal from within Deno itself, and I know the Deno core team are susceptible for ideas that improve stuff like this.

Another issue I found is also that cliffy prevents other tasks such as suspending the process (ctrl+z). Not sure what options there are.

from deno-cliffy.

c4spar avatar c4spar commented on July 22, 2024

I have opend an deno issue denoland/deno#8299. Let's see what they will say.

from deno-cliffy.

c4spar avatar c4spar commented on July 22, 2024

Cool, that would be even better! thanks @marcushultman

from deno-cliffy.

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.