Skip to content

build_runner: add option to clear console when watching #24122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

romeobalta
Copy link

As described in #23472.

Running zig build with -fincremental and --watch it's a bit hard to identify what's the up-to-date error state.

This PR allows you to opt-in having the screen cleared on debounce timeout.

@@ -266,6 +267,8 @@ pub fn main() !void {
prominent_compile_errors = true;
} else if (mem.eql(u8, arg, "--watch")) {
watch = true;
} else if (mem.eql(u8, arg, "--with-clear")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally prefer something like --watch-clear. The with doesn't really add any clarity, but watch clarifies that it affects --watch.

It also needs to be added to the help text in usage().

Copy link
Member

@mlugg mlugg Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that --watch=clear might be even better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me too. Though I don't know if we expect to add other options that affect --watch in the future?

Copy link
Member

@mlugg mlugg Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's YAGNI this for the minute: --watch=clear feels to me like the simplest approach for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seen this after pushing update to --watch-clear, will update to --watch=clear.

@@ -484,6 +487,10 @@ pub fn main() !void {
var debounce_timeout: Watch.Timeout = .none;
while (true) switch (try w.wait(gpa, debounce_timeout)) {
.timeout => {
if (watch_clear) {
try std.io.getStdOut().writeAll("\x1B[2J\x1B[H");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, "\x1B[2J\x1B[H" should be moved into std.io.tty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that std.Progress already has code like this so that could be refactored.

@andrewrk andrewrk self-requested a review June 9, 2025 07:25
@andrewrk
Copy link
Member

andrewrk commented Jun 9, 2025

clearing is pretty aggressive, have you considered simply adding a newline instead?

@mlugg
Copy link
Member

mlugg commented Jun 9, 2025

clearing is pretty aggressive, have you considered simply adding a newline instead?

FWIW, I absolutely want the "clear" option, and have done for a while. With the reference trace and command also in the output, just blank lines don't separate things enough. I would really like my --watch terminal window to purely be current compile errors.

Ideally we could replace just the previous zig build output, but terminals don't have the necessary capabilities to rewrite scrollback.

@romeobalta
Copy link
Author

I agree with @mlugg on this one. I usually just want to expend as little as possible of my attention trying to locate the error in the log and just go back to fixing the code.

I was wondering if it would be better to also allow people to specify their own separator either as a flag or as an option in build.zig. This would enable other edge cases as well. (Eg. I'm running zig build --watch as a job in my editor and surface the errors in a QuickFix list automatically, I can use the separator to clear the QF list between builds).

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.

6 participants