Comments (9)
@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.
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.
@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.
Made a PR #106
from deno-cliffy.
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.
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.
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.
I have opend an deno issue denoland/deno#8299. Let's see what they will say.
from deno-cliffy.
Cool, that would be even better! thanks @marcushultman
from deno-cliffy.
Related Issues (20)
- Navigating back on the outer most prompt level can select a disabled item HOT 1
- Feature: Ability to parse arguments without execution HOT 3
- Standalone options does not trigger command action HOT 3
- `command.default(name)` doesn't seem to work as expected
- ANSI codes overflow multi-line table cells
- Feedback on grouped select prompt HOT 1
- Allow for dynamic Select options
- Empty strings are parsed as arguments regardless of context HOT 1
- feature request: return output from action handler
- Can I read option as argument? HOT 1
- generated zsh completions doesn't seem to be able to tab-complete files. HOT 4
- Warnings about Deno.stdin in v1.40.1 HOT 7
- Prefill and edit prompt? HOT 1
- Is the project alive ? HOT 2
- Docs: JSDoc example for `Command#arguments` method shows wrong syntax in intellisense
- Not available on jsr.io HOT 7
- TypeError: Cannot read properties of undefined (reading 'icon') HOT 2
- `files` option fails if user inputs `~/`
- Disable colors if the standard output is not a TTY
- Support automatic zsh completions with fpath
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno-cliffy.