Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4ed2d63
std.Progress: display nodes in a tree form
DISTREAT Nov 26, 2023
1ec1bf3
std.Progress: truncate content to terminal width
DISTREAT Nov 26, 2023
ae732ba
std.Progress: make the output_buffer end index a field
DISTREAT Nov 26, 2023
215c40d
frontend: migrate to the new API of std.Progress
DISTREAT Nov 26, 2023
d421c78
std.Progress: always write the output_buffer
DISTREAT Nov 26, 2023
64138fb
docgen: add support for more ansi escape sequences
DISTREAT Nov 26, 2023
4d0574b
std.Progress: use fill option to replace indentation_buffer
DISTREAT Nov 26, 2023
9f9c17b
std.Progress: remove confusing comment
DISTREAT Nov 26, 2023
10f04b6
std.Progress: remove confusing comment
DISTREAT Nov 26, 2023
b8bbf9b
std.Progress: fix trailing bracket
DISTREAT Nov 26, 2023
1ba94ea
std.Progress: redundant mutability
DISTREAT Nov 26, 2023
72cc178
std.Progress: add truncation support for macos
DISTREAT Nov 26, 2023
49a521d
Merge zig master and resolve conflicts
DISTREAT Apr 21, 2024
20cb751
std.Progress: update casing of AtomicOrder field identifiers
DISTREAT Apr 22, 2024
e5209b9
std.Progress: do not copy ellipse if not memory-safe
DISTREAT Apr 22, 2024
aaa13b0
std.Progress: continously update max_columns
DISTREAT Apr 22, 2024
4a743c6
Merge zig master and resolve docgen conflicts
DISTREAT Apr 28, 2024
aa1c0cc
std.Progress: `output_buffer` as two-dimensional
DISTREAT Apr 29, 2024
623b068
std.Progress: add method for deactivating node
DISTREAT Apr 29, 2024
7fcfe79
std.Progress: prevent unnecessary iterations
DISTREAT Apr 29, 2024
0cbc601
doctest: add support for more ansi escape sequences
DISTREAT Apr 30, 2024
acb5067
std.Progress: missing check for `max_columns` is 0
DISTREAT Apr 30, 2024
f4258a2
std.Progress: double `output_buffer` row limit
DISTREAT Apr 30, 2024
d29ca27
frontend: migrate to new backend of std.Progress
DISTREAT Apr 30, 2024
b5510ce
std.Progress: skip newline on node without info
DISTREAT Apr 30, 2024
7bc2e15
std.Progress: option to emulate old progress bar
DISTREAT Apr 30, 2024
433968f
Merge remote-tracking branch 'upstream/master'
DISTREAT Apr 30, 2024
6b037fc
std.Progress: ansi buffer write to end
DISTREAT Apr 30, 2024
59e3c2d
frontend: enable one-line progress bar everywhere
DISTREAT Apr 30, 2024
13c3f69
std.Progress: ignore newline if buffer is full
DISTREAT Apr 30, 2024
41f3adc
std.Progress: option to disregard terminal width
DISTREAT May 1, 2024
3cb4e80
std.Progress: do not assume windows is always tty
DISTREAT May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/compiler/test_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn mainTerminal() void {
var fail_count: usize = 0;
var progress = std.Progress{
.dont_print_on_dumb = true,
.emulate_one_line_bar = true,
};
const root_node = progress.start("Test", test_fn_list.len);
const have_tty = progress.terminal != null and
Expand Down
429 changes: 275 additions & 154 deletions lib/std/Progress.zig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/std/zig/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn receiveBody_u32(s: *Server) !u32 {
return bswap(result);
}

pub fn serveStringMessage(s: *Server, tag: OutMessage.Tag, msg: []const u8) !void {
pub fn serveStringMessage(s: *const Server, tag: OutMessage.Tag, msg: []const u8) !void {
return s.serveMessage(.{
.tag = tag,
.bytes_len = @as(u32, @intCast(msg.len)),
Expand Down
67 changes: 17 additions & 50 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4031,10 +4031,9 @@ fn serve(
.unprotected_estimated_total_items = 0,
.unprotected_completed_items = 0,
},
.columns_written = 0,
.prev_refresh_timestamp = 0,
.timer = null,
.done = false,
.emulate_one_line_bar = true,
};
const main_progress_node = &progress.root;
main_progress_node.context = &progress;
Expand All @@ -4045,7 +4044,7 @@ fn serve(
switch (hdr.tag) {
.exit => return cleanExit(),
.update => {
assert(main_progress_node.recently_updated_child == null);
for (main_progress_node.children) |child| assert(child == null);
tracy.frameMark();

if (arg_mode == .translate_c) {
Expand Down Expand Up @@ -4110,7 +4109,7 @@ fn serve(
},
.hot_update => {
tracy.frameMark();
assert(main_progress_node.recently_updated_child == null);
for (main_progress_node.children) |child| assert(child == null);
if (child_pid) |pid| {
try comp.hotCodeSwap(main_progress_node, pid);
try serveUpdateResults(&server, comp);
Expand Down Expand Up @@ -4149,51 +4148,19 @@ fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Th
error.Timeout => {},
}

var buf: std.BoundedArray(u8, 160) = .{};
progress.refresh();

{
progress.update_mutex.lock();
defer progress.update_mutex.unlock();

var need_ellipse = false;
var maybe_node: ?*std.Progress.Node = &progress.root;
while (maybe_node) |node| {
if (need_ellipse) {
buf.appendSlice("... ") catch {};
}
need_ellipse = false;
const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .monotonic);
const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .monotonic);
const current_item = completed_items + 1;
if (node.name.len != 0 or eti > 0) {
if (node.name.len != 0) {
buf.appendSlice(node.name) catch {};
need_ellipse = true;
}
if (eti > 0) {
if (need_ellipse) buf.appendSlice(" ") catch {};
buf.writer().print("[{d}/{d}] ", .{ current_item, eti }) catch {};
need_ellipse = false;
} else if (completed_items != 0) {
if (need_ellipse) buf.appendSlice(" ") catch {};
buf.writer().print("[{d}] ", .{current_item}) catch {};
need_ellipse = false;
}
}
maybe_node = @atomicLoad(?*std.Progress.Node, &node.recently_updated_child, .acquire);
// TODO: Provisional. This should be better integrated.
for (progress.output_buffer[0 .. progress.rows_written + 1], 0..) |output_row, row_index| {
if (row_index != 0) {
server.serveStringMessage(.progress, "\n") catch |err| {
fatal("unable to write to client: {s}", .{@errorName(err)});
};
}
server.serveStringMessage(.progress, output_row[0..progress.columns_written[row_index]]) catch |err| {
fatal("unable to write to client: {s}", .{@errorName(err)});
};
}

const progress_string = buf.slice();

server.serveMessage(.{
.tag = .progress,
.bytes_len = @as(u32, @intCast(progress_string.len)),
}, &.{
progress_string,
}) catch |err| {
fatal("unable to write to client: {s}", .{@errorName(err)});
};
}
}

Expand Down Expand Up @@ -4466,7 +4433,7 @@ fn runOrTestHotSwap(
fn updateModule(comp: *Compilation, color: Color) !void {
{
// If the terminal is dumb, we dont want to show the user all the output.
var progress: std.Progress = .{ .dont_print_on_dumb = true };
var progress: std.Progress = .{ .dont_print_on_dumb = true, .emulate_one_line_bar = true };
const main_progress_node = progress.start("", 0);
defer main_progress_node.end();
switch (color) {
Expand Down Expand Up @@ -4730,7 +4697,7 @@ const usage_build =
;

fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
var progress: std.Progress = .{ .dont_print_on_dumb = true };
var progress: std.Progress = .{ .dont_print_on_dumb = true, .emulate_one_line_bar = true };

var build_file: ?[]const u8 = null;
var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
Expand Down Expand Up @@ -5475,10 +5442,10 @@ fn jitCmd(
.unprotected_estimated_total_items = 0,
.unprotected_completed_items = 0,
},
.columns_written = 0,
.prev_refresh_timestamp = 0,
.timer = null,
.done = false,
.emulate_one_line_bar = true,
};
const main_progress_node = &progress.root;
main_progress_node.context = &progress;
Expand Down Expand Up @@ -6812,7 +6779,7 @@ fn cmdFetch(

try http_client.initDefaultProxies(arena);

var progress: std.Progress = .{ .dont_print_on_dumb = true };
var progress: std.Progress = .{ .dont_print_on_dumb = true, .emulate_one_line_bar = true };
const root_prog_node = progress.start("Fetch", 0);
defer root_prog_node.end();

Expand Down
2 changes: 1 addition & 1 deletion test/src/Cases.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ fn resolveTargetQuery(query: std.Target.Query) std.Build.ResolvedTarget {
fn runCases(self: *Cases, zig_exe_path: []const u8) !void {
const host = try std.zig.system.resolveTargetQuery(.{});

var progress = std.Progress{};
var progress = std.Progress{ .emulate_one_line_bar = true };
const root_node = progress.start("compiler", self.cases.items.len);
progress.terminal = null;
defer root_node.end();
Expand Down
6 changes: 5 additions & 1 deletion tools/doctest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,11 @@ fn termColor(allocator: Allocator, input: []const u8) ![]u8 {
},
.after_number => switch (c) {
';' => state = .arg,
'D' => state = .start,
'A'...'G' => state = .start,
'J' => {
buf.items.len = last_new_line;
state = .start;
},
'K' => {
buf.items.len = last_new_line;
state = .start;
Expand Down
2 changes: 1 addition & 1 deletion tools/update_cpu_features.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ pub fn main() anyerror!void {
var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
defer zig_src_dir.close();

var progress = std.Progress{};
var progress = std.Progress{ .emulate_one_line_bar = true };
const root_progress = progress.start("", llvm_targets.len);
defer root_progress.end();

Expand Down