Skip to content

Add std.io.tty.setInterruptSignalHandler and use it in std.Progress - #20644

Closed
ghost wants to merge 1 commit into
masterfrom
unknown repository
Closed

Add std.io.tty.setInterruptSignalHandler and use it in std.Progress#20644
ghost wants to merge 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jul 16, 2024

Copy link
Copy Markdown

Closes #20266
Closes #13045

When doing things that involve printing something to the terminal and then clearing it or having any kind of state in form of content printed to the terminal, it's very useful if you can handle the case of interruption. Even the standard library finds a use case for this: std.Progress.

Before:

~/zig@abort$ zig-out/bin/zig test ../x.zig --zig-lib-dir lib
^C05] AST Lowering
~/zig@abort$ zig-out/bin/zig test ../x.zig --zig-lib-dir lib
^C36] AST Lowering
~/zig@abort$ tificate/Bundle.zig
├─ math/cbrt.zig
├─ tar/output.zig
├─ io.zig
├─ tar/test.zig
├─ math.zig
├─ crypto/Certificate/Bundle/macos.zig
└─ std.zig

After:

~/zig@abort$ zig-out/bin/zig test ../x.zig --zig-lib-dir lib
^C~/zig@abort$ zig-out/bin/zig test ../x.zig --zig-lib-dir lib
^C~/zig@abort$

Ctrl+C is the most common way to abort the compiler while it is running.
Aborting it because of not needing it to run anymore is common, so why not handle this case if we can and keep output clean?

Comment thread lib/std/Progress.zig Outdated
Comment thread lib/std/Progress.zig Outdated
Comment thread lib/std/io/tty.zig Outdated
@andrewrk

Copy link
Copy Markdown
Member

Thank you but I don't want to catch SIGINT. I think it is annoying as a user when processes do this.

@andrewrk andrewrk closed this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

std.Progress: Output not cleared on SIGINT Proposal: std.debug.setAbortSignalHandler

3 participants