mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-19 14:00:29 +00:00
Improve list-actions command documentation formatting
This commit fixes two issues with the `list-actions` command: 1. Ensures all actions are listed, including those without individual documentation but sharing docs with related actions 2. Improves documentation formatting with proper indentation and grouping
This commit is contained in:
@@ -3,6 +3,7 @@ const args = @import("args.zig");
|
||||
const Action = @import("action.zig").Action;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const help_strings = @import("help_strings");
|
||||
const KeybindAction = @import("../input/Binding.zig").Action;
|
||||
|
||||
pub const Options = struct {
|
||||
/// If `true`, print out documentation about the action associated with the
|
||||
@@ -36,18 +37,45 @@ pub fn run(alloc: Allocator) !u8 {
|
||||
}
|
||||
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
const info = @typeInfo(help_strings.KeybindAction);
|
||||
inline for (info.Struct.decls) |field| {
|
||||
try stdout.print("{s}", .{field.name});
|
||||
if (opts.docs) {
|
||||
try stdout.print(":\n", .{});
|
||||
var iter = std.mem.splitScalar(u8, std.mem.trimRight(u8, @field(help_strings.KeybindAction, field.name), &std.ascii.whitespace), '\n');
|
||||
while (iter.next()) |line| {
|
||||
try stdout.print(" {s}\n", .{line});
|
||||
}
|
||||
} else {
|
||||
try stdout.print("\n", .{});
|
||||
|
||||
var buffer = std.ArrayList(u8).init(std.heap.page_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
const fields = @typeInfo(KeybindAction).Union.fields;
|
||||
inline for (fields) |field| {
|
||||
if (field.name[0] == '_') continue;
|
||||
|
||||
// Write previously stored doc comment below all related actions
|
||||
if (@hasDecl(help_strings.KeybindAction, field.name)) {
|
||||
try stdout.writeAll(buffer.items);
|
||||
try stdout.writeAll("\n");
|
||||
|
||||
buffer.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
// Write the field name.
|
||||
try stdout.writeAll(field.name);
|
||||
try stdout.writeAll(":\n");
|
||||
|
||||
if (@hasDecl(help_strings.KeybindAction, field.name)) {
|
||||
var iter = std.mem.splitScalar(
|
||||
u8,
|
||||
@field(help_strings.KeybindAction, field.name),
|
||||
'\n',
|
||||
);
|
||||
while (iter.next()) |s| {
|
||||
// If it is the last line and empty, then skip it.
|
||||
if (iter.peek() == null and s.len == 0) continue;
|
||||
try buffer.appendSlice(" ");
|
||||
try buffer.appendSlice(s);
|
||||
try buffer.appendSlice("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write any remaining buffered documentation
|
||||
if (buffer.items.len > 0) {
|
||||
try stdout.writeAll(buffer.items);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user