aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/input/helpgen_actions.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/input/helpgen_actions.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/input/helpgen_actions.zig')
-rw-r--r--vendor/libghostty-vt/src/input/helpgen_actions.zig112
1 files changed, 112 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/input/helpgen_actions.zig b/vendor/libghostty-vt/src/input/helpgen_actions.zig
new file mode 100644
index 00000000..4210f1f9
--- /dev/null
+++ b/vendor/libghostty-vt/src/input/helpgen_actions.zig
@@ -0,0 +1,112 @@
+//! This module is a help generator for keybind actions documentation.
+//! It can generate documentation in different formats (plaintext for CLI,
+//! markdown for website) while maintaining consistent content.
+
+const std = @import("std");
+const KeybindAction = @import("Binding.zig").Action;
+const help_strings = @import("help_strings");
+
+/// Format options for generating keybind actions documentation
+pub const Format = enum {
+ /// Plain text output with indentation
+ plaintext,
+ /// Markdown formatted output
+ markdown,
+
+ fn formatFieldName(self: Format, writer: *std.Io.Writer, field_name: []const u8) !void {
+ switch (self) {
+ .plaintext => {
+ try writer.writeAll(field_name);
+ try writer.writeAll(":\n");
+ },
+ .markdown => {
+ try writer.writeAll("## `");
+ try writer.writeAll(field_name);
+ try writer.writeAll("`\n");
+ },
+ }
+ }
+
+ fn formatDocLine(self: Format, writer: *std.Io.Writer, line: []const u8) !void {
+ switch (self) {
+ .plaintext => {
+ try writer.writeAll(" ");
+ try writer.writeAll(line);
+ try writer.writeAll("\n");
+ },
+ .markdown => {
+ try writer.writeAll(line);
+ try writer.writeAll("\n");
+ },
+ }
+ }
+
+ fn header(self: Format) ?[]const u8 {
+ return switch (self) {
+ .plaintext => null,
+ .markdown =>
+ \\---
+ \\title: Keybinding Action Reference
+ \\description: Reference of all Ghostty keybinding actions.
+ \\editOnGithubLink: https://github.com/ghostty-org/ghostty/edit/main/src/input/Binding.zig
+ \\---
+ \\
+ \\This is a reference of all Ghostty keybinding actions.
+ \\
+ \\
+ ,
+ };
+ }
+};
+
+/// Generate keybind actions documentation with the specified format
+pub fn generate(
+ writer: *std.Io.Writer,
+ format: Format,
+ show_docs: bool,
+ page_allocator: std.mem.Allocator,
+) !void {
+ if (format.header()) |header| {
+ try writer.writeAll(header);
+ }
+
+ var stream: std.Io.Writer.Allocating = .init(page_allocator);
+ defer stream.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 (show_docs and @hasDecl(help_strings.KeybindAction, field.name)) {
+ try writer.writeAll(stream.written());
+ try writer.writeAll("\n");
+ stream.clearRetainingCapacity();
+ }
+
+ if (show_docs) {
+ try format.formatFieldName(writer, field.name);
+ } else {
+ try writer.writeAll(field.name);
+ try writer.writeAll("\n");
+ }
+
+ if (show_docs and @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 format.formatDocLine(&stream.writer, s);
+ }
+ }
+ }
+
+ // Write any remaining buffered documentation
+ if (stream.written().len > 0) {
+ try writer.writeAll(stream.written());
+ }
+}