vtcode_tui/core_tui/session/
impl_input.rs1use super::*;
2
3impl Session {
4 pub fn cursor(&self) -> usize {
5 self.input_manager.cursor()
6 }
7
8 pub fn set_input(&mut self, text: impl Into<String>) {
9 self.input_manager.set_content(text.into());
10 self.input_compact_mode = self.input_compact_placeholder().is_some();
11 self.mark_dirty();
12 }
13
14 pub fn set_cursor(&mut self, pos: usize) {
15 self.input_manager.set_cursor(pos);
16 self.mark_dirty();
17 }
18
19 pub fn process_key(&mut self, key: KeyEvent) -> Option<InlineEvent> {
20 events::process_key(self, key)
21 }
22
23 pub fn handle_command(&mut self, command: InlineCommand) {
24 match command {
25 InlineCommand::AppendLine { kind, segments } => {
26 self.clear_thinking_spinner_if_active(kind);
27 self.push_line(kind, segments);
28 self.transcript_content_changed = true;
29 }
30 InlineCommand::AppendPastedMessage {
31 kind,
32 text,
33 line_count,
34 } => {
35 self.clear_thinking_spinner_if_active(kind);
36 self.append_pasted_message(kind, text, line_count);
37 self.transcript_content_changed = true;
38 }
39 InlineCommand::Inline { kind, segment } => {
40 self.clear_thinking_spinner_if_active(kind);
41 self.append_inline(kind, segment);
42 self.transcript_content_changed = true;
43 }
44 InlineCommand::ReplaceLast { count, kind, lines } => {
45 self.clear_thinking_spinner_if_active(kind);
46 self.replace_last(count, kind, lines);
47 self.transcript_content_changed = true;
48 }
49 InlineCommand::SetPrompt { prefix, style } => {
50 self.prompt_prefix = prefix;
51 self.prompt_style = style;
52 self.ensure_prompt_style_color();
53 }
54 InlineCommand::SetPlaceholder { hint, style } => {
55 self.placeholder = hint;
56 self.placeholder_style = style;
57 }
58 InlineCommand::SetMessageLabels { agent, user } => {
59 self.labels.agent = agent.filter(|label| !label.is_empty());
60 self.labels.user = user.filter(|label| !label.is_empty());
61 self.invalidate_scroll_metrics();
62 }
63 InlineCommand::SetHeaderContext { context } => {
64 self.header_context = context;
65 self.needs_redraw = true;
66 }
67 InlineCommand::SetInputStatus { left, right } => {
68 self.input_status_left = left;
69 self.input_status_right = right;
70 if self.thinking_spinner.is_active {
71 self.thinking_spinner.stop();
72 }
73 self.needs_redraw = true;
74 }
75 InlineCommand::SetTheme { theme } => {
76 self.theme = theme.clone();
77 self.styles.set_theme(theme);
78 self.ensure_prompt_style_color();
79 self.invalidate_transcript_cache();
80 }
81 InlineCommand::SetAppearance { appearance } => {
82 self.appearance = appearance;
83 self.invalidate_transcript_cache();
84 self.invalidate_scroll_metrics();
85 }
86 InlineCommand::SetQueuedInputs { entries } => {
87 self.set_queued_inputs_entries(entries);
88 self.mark_dirty();
89 }
90 InlineCommand::SetCursorVisible(value) => {
91 self.cursor_visible = value;
92 }
93 InlineCommand::SetInputEnabled(value) => {
94 self.input_enabled = value;
95 slash::update_slash_suggestions(self);
96 }
97 InlineCommand::SetInput(content) => {
98 if Self::is_error_content(&content) {
101 crate::utils::transcript::display_error(&content);
103 } else {
104 self.input_manager.set_content(content);
105 self.input_compact_mode = self.input_compact_placeholder().is_some();
106 self.scroll_manager.set_offset(0);
107 slash::update_slash_suggestions(self);
108 }
109 }
110 InlineCommand::ClearInput => {
111 command::clear_input(self);
112 }
113 InlineCommand::ForceRedraw => {
114 self.mark_dirty();
115 }
116 InlineCommand::ShowModal {
117 title,
118 lines,
119 secure_prompt,
120 } => {
121 self.show_modal(title, lines, secure_prompt);
122 }
123 InlineCommand::ShowListModal {
124 title,
125 lines,
126 items,
127 selected,
128 search,
129 } => {
130 self.show_list_modal(title, lines, items, selected, search);
131 }
132 InlineCommand::ShowWizardModal {
133 title,
134 steps,
135 current_step,
136 search,
137 mode,
138 } => {
139 self.show_wizard_modal(title, steps, current_step, search, mode);
140 }
141 InlineCommand::CloseModal => {
142 self.close_modal();
143 }
144 InlineCommand::LoadFilePalette { files, workspace } => {
145 self.load_file_palette(files, workspace);
146 }
147 InlineCommand::ClearScreen => {
148 self.clear_screen();
149 }
150 InlineCommand::SuspendEventLoop
151 | InlineCommand::ResumeEventLoop
152 | InlineCommand::ClearInputQueue => {
153 }
155 InlineCommand::SetEditingMode(mode) => {
156 self.header_context.editing_mode = mode;
157 self.needs_redraw = true;
158 }
159 InlineCommand::SetAutonomousMode(enabled) => {
160 self.header_context.autonomous_mode = enabled;
161 self.needs_redraw = true;
162 }
163 InlineCommand::ShowPlanConfirmation { plan } => {
164 command::show_plan_confirmation_modal(self, *plan);
165 }
166 InlineCommand::ShowDiffPreview {
167 file_path,
168 before,
169 after,
170 hunks,
171 current_hunk,
172 } => {
173 command::show_diff_preview(self, file_path, before, after, hunks, current_hunk);
174 }
175 InlineCommand::SetSkipConfirmations(skip) => {
176 self.skip_confirmations = skip;
177 if skip {
178 self.close_modal();
179 }
180 }
181 InlineCommand::Shutdown => {
182 self.request_exit();
183 }
184 InlineCommand::SetReasoningStage(stage) => {
185 self.header_context.reasoning_stage = stage;
186 self.invalidate_header_cache();
187 }
188 }
189 self.needs_redraw = true;
190 }
191}