-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_state.zig
More file actions
173 lines (162 loc) · 6.53 KB
/
help_state.zig
File metadata and controls
173 lines (162 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const std = @import("std");
const mem = std.mem;
const Allocator = std.mem.Allocator;
pub const HelpState = struct {
allocator: Allocator,
scroll_offset: usize,
content_lines: std.ArrayListUnmanaged([]const u8),
total_lines: usize,
pub fn init(allocator: Allocator) !HelpState {
var content_lines = std.ArrayListUnmanaged([]const u8){};
// Build help content
const help_lines = [_][]const u8{
"",
"SLASH COMMANDS",
"",
" /help",
" Show this help screen with all available commands and shortcuts.",
"",
" /config",
" Open configuration editor to modify LLM provider settings,",
" API keys, model parameters, and other application preferences.",
"",
" /profiles",
" Open the interactive profile manager to create, switch, and manage",
" configuration profiles. Profiles let you save and switch between",
" different settings (API keys, models, preferences, etc.).",
"",
" /profile list",
" List all available profiles with active profile indicator.",
"",
" /profile switch <name>",
" Switch to a different profile and reinitialize settings.",
"",
" /profile save <name>",
" Save current configuration as a new profile.",
"",
" /profile delete <name>",
" Delete a profile (cannot delete active or last remaining profile).",
"",
" /agents",
" Launch the agent builder to create custom AI agents with specific",
" system prompts, tools, and configurations.",
"",
" /context",
" Generate a comprehensive context summary of your project structure",
" and send it to the LLM for better code understanding.",
"",
" /toggle-toolcall-json",
" Toggle the display of raw JSON data for LLM tool calls. Useful",
" for debugging or understanding how the AI is using tools.",
"",
" /quit",
" Exit the application gracefully. Same as pressing Ctrl+D.",
"",
"",
"KEYBOARD SHORTCUTS",
"",
" Enter",
" Send your message to the AI or submit the current input.",
"",
" Ctrl+C",
" Cancel the current AI response generation. The partial response",
" will be discarded and you can start a new message.",
"",
" Ctrl+D",
" Exit the application (same as /quit command).",
"",
" Ctrl+O",
" Toggle the expansion state of the thinking block at your cursor",
" position. Thinking blocks show the AI's reasoning process.",
"",
" Escape",
" Clear the input buffer without sending a message.",
"",
" ↑ / ↓ (Arrow Keys)",
" Scroll the message view up or down by 3 lines.",
"",
" Page Up / Page Down",
" Scroll the message view up or down more quickly.",
"",
" Mouse Wheel",
" Scroll through messages naturally using your mouse wheel.",
"",
" Home / End (in help viewer)",
" Jump to the top or bottom of the help content.",
"",
"",
"BASIC USAGE",
"",
" Starting a conversation:",
" Simply type your message and press Enter. The AI will respond",
" with assistance, code suggestions, or answers to your questions.",
"",
" Using tools:",
" The AI can automatically use various tools like file operations,",
" bash commands, web searches, and more. Tool calls are displayed",
" inline with the conversation.",
"",
" Thinking blocks:",
" When enabled, thinking blocks show the AI's internal reasoning.",
" Click or use Ctrl+O to expand/collapse them.",
"",
" Configuration:",
" Use /config to adjust settings like LLM provider (Anthropic,",
" OpenAI, LM Studio), model selection, context size, and API keys.",
"",
" Custom agents:",
" Use /agents to create specialized AI agents with custom system",
" prompts and tool access. Agents are saved and can be reused.",
"",
"",
"DOCUMENTATION",
"",
" For more detailed documentation, see:",
" • docs/user-guide/commands.md - Complete command reference",
" • docs/user-guide/features.md - Feature descriptions",
" • docs/user-guide/configuration.md - Configuration options",
" • docs/QUICK_START.md - Getting started guide",
"",
};
for (help_lines) |line| {
const duped = try allocator.dupe(u8, line);
try content_lines.append(allocator, duped);
}
return HelpState{
.allocator = allocator,
.scroll_offset = 0,
.content_lines = content_lines,
.total_lines = content_lines.items.len,
};
}
pub fn deinit(self: *HelpState) void {
for (self.content_lines.items) |line| {
self.allocator.free(line);
}
self.content_lines.deinit(self.allocator);
}
pub fn scrollUp(self: *HelpState, lines: usize) void {
if (self.scroll_offset >= lines) {
self.scroll_offset -= lines;
} else {
self.scroll_offset = 0;
}
}
pub fn scrollDown(self: *HelpState, lines: usize, visible_lines: usize) void {
const max_scroll = if (self.total_lines > visible_lines)
self.total_lines - visible_lines
else
0;
self.scroll_offset = @min(self.scroll_offset + lines, max_scroll);
}
pub fn scrollToTop(self: *HelpState) void {
self.scroll_offset = 0;
}
pub fn scrollToBottom(self: *HelpState, visible_lines: usize) void {
if (self.total_lines > visible_lines) {
self.scroll_offset = self.total_lines - visible_lines;
} else {
self.scroll_offset = 0;
}
}
};