返回 CodeWhale
external_editor.rs
根目录 / crates / tui / src / tui / external_editor.rs
1 //! External editor support for the composer.
2 //!
3 //! Spawns `$VISUAL`/`$EDITOR` (fallback `vi`) on a temp file pre-populated with
4 //! the composer's current contents. The TUI is suspended for the duration of
5 //! the edit and re-entered on return. The temp file is cleaned up in all paths
6 //! (success, editor failure, IO error) via [`tempfile::NamedTempFile`].
7 //!
8 //! Reference: codex-rs's `tui/src/external_editor.rs` — the design here mirrors
9 //! that approach but is synchronous (called inline from the TUI event loop) and
10 //! handles its own raw-mode toggling rather than relying on the caller.
11
12 use std::env;
13 use std::fs;
14 use std::io::{self, Stdout, Write};
15 use std::process::Command;
16
17 use crossterm::{
18 event::DisableFocusChange,
19 execute,
20 terminal::{disable_raw_mode, enable_raw_mode},
21 };
22 use ratatui::Terminal;
23 use tempfile::Builder;
24
25 use super::color_compat::ColorCompatBackend;
26
27 /// Outcome of a single external-editor invocation.
28 #[derive(Debug, PartialEq, Eq)]
29 pub enum EditorOutcome {
30 /// Editor exited cleanly and the file contents differ from the seed.
31 Edited(String),
32 /// Editor exited cleanly but the contents are unchanged (or empty after
33 /// trimming). The composer should be left as-is.
34 Unchanged,
35 /// Editor exited non-zero or could not be spawned. The composer should be
36 /// left as-is and a status toast shown.
37 Cancelled,
38 }
39
40 /// Resolve the editor command, preferring `$VISUAL` over `$EDITOR`, falling
41 /// back to `vi`. Returns the raw string for the test path; `spawn_editor`
42 /// splits it via `shlex` (Unix) so users can set `EDITOR="code --wait"`.
43 fn resolve_editor() -> String {
44 env::var("VISUAL")
45 .ok()
46 .filter(|s| !s.trim().is_empty())
47 .or_else(|| env::var("EDITOR").ok().filter(|s| !s.trim().is_empty()))
48 .unwrap_or_else(|| "vi".to_string())
49 }
50
51 #[cfg(unix)]
52 fn split_command(raw: &str) -> Option<Vec<String>> {
53 shlex::split(raw)
54 }
55
56 #[cfg(not(unix))]
57 fn split_command(raw: &str) -> Option<Vec<String>> {
58 // On Windows we do not support shell-quoted editor commands; treat the
59 // full string as the program name.
60 if raw.trim().is_empty() {
61 None
62 } else {
63 Some(vec![raw.to_string()])
64 }
65 }
66
67 /// Run the external editor without touching terminal state. Exposed for tests.
68 ///
69 /// Returns:
70 /// - `Ok(EditorOutcome::Edited(new))` if the editor exited cleanly and the
71 /// contents differ from `seed`.
72 /// - `Ok(EditorOutcome::Unchanged)` if the editor exited cleanly but the
73 /// contents match `seed`.
74 /// - `Ok(EditorOutcome::Cancelled)` if the editor exited non-zero or could not
75 /// be spawned.
76 ///
77 /// The temp file is removed on every path because [`tempfile::NamedTempFile`]
78 /// is dropped at the end of the function.
79 pub fn run_editor_raw(seed: &str) -> io::Result<EditorOutcome> {
80 let mut tmp = Builder::new()
81 .prefix("deepseek-edit-")
82 .suffix(".md")
83 .tempfile()?;
84 tmp.write_all(seed.as_bytes())?;
85 tmp.flush()?;
86 let path = tmp.path().to_path_buf();
87
88 let raw = resolve_editor();
89 let parts = match split_command(&raw) {
90 Some(p) if !p.is_empty() => p,
91 _ => return Ok(EditorOutcome::Cancelled),
92 };
93
94 let mut cmd = Command::new(&parts[0]);
95 if parts.len() > 1 {
96 cmd.args(&parts[1..]);
97 }
98 cmd.arg(&path);
99
100 let status = match cmd.status() {
101 Ok(s) => s,
102 Err(_) => return Ok(EditorOutcome::Cancelled),
103 };
104 if !status.success() {
105 return Ok(EditorOutcome::Cancelled);
106 }
107
108 let new = fs::read_to_string(&path)?;
109 // tmp goes out of scope here — file is unlinked.
110 if new == seed {
111 Ok(EditorOutcome::Unchanged)
112 } else {
113 Ok(EditorOutcome::Edited(new))
114 }
115 }
116
117 /// Append the file (and optional line) arguments in the spelling `program`
118 /// understands.
119 ///
120 /// Every caller that opens a real file goes through here so the three paths
121 /// cannot drift on how a line number is spelled. Without a line this is exactly
122 /// `cmd.arg(path)`, which is what it has always been.
123 ///
124 /// `file_stem` rather than the whole program name, so an absolute path and a
125 /// Windows `.exe` suffix both still match. An editor we do not recognize gets
126 /// the bare path: opening the right file at the wrong line beats a spurious
127 /// argument the editor treats as a second file to open.
128 fn push_target_args(cmd: &mut Command, program: &str, path: &std::path::Path, line: Option<u32>) {
129 let Some(line) = line else {
130 cmd.arg(path);
131 return;
132 };
133 let stem = std::path::Path::new(program)
134 .file_stem()
135 .and_then(|s| s.to_str())
136 .unwrap_or(program)
137 .to_ascii_lowercase();
138
139 match stem.as_str() {
140 // The vi family and the editors that copied its `+N` convention.
141 "vi" | "vim" | "nvim" | "view" | "gvim" | "nano" | "pico" | "emacs" | "emacsclient"
142 | "kak" | "micro" | "joe" => {
143 cmd.arg(format!("+{line}"));
144 cmd.arg(path);
145 }
146 // VS Code and its forks need an explicit flag before `file:line`.
147 "code" | "code-insiders" | "codium" | "vscodium" | "cursor" | "windsurf" => {
148 cmd.arg("--goto");
149 cmd.arg(format!("{}:{line}", path.display()));
150 }
151 // Sublime, Zed and JetBrains launchers all take `file:line` directly.
152 "subl" | "sublime_text" | "zed" | "idea" | "pycharm" | "goland" | "clion" | "rustrover"
153 | "webstorm" => {
154 cmd.arg(format!("{}:{line}", path.display()));
155 }
156 _ => {
157 cmd.arg(path);
158 }
159 }
160 }
161
162 /// Run the external editor on a real file, in place.
163 ///
164 /// Unlike [`run_editor_raw`] there is no temp file and no seed: the file on
165 /// disk *is* the document, so a `hooks.toml` the user edits stays edited even
166 /// if the editor exits non-zero. The outcome only reports whether the bytes
167 /// moved, which is what the caller needs in order to decide whether to reload.
168 pub fn run_editor_on_path(path: &std::path::Path, line: Option<u32>) -> io::Result<EditorOutcome> {
169 let before = fs::read_to_string(path).unwrap_or_default();
170
171 let raw = resolve_editor();
172 let parts = match split_command(&raw) {
173 Some(p) if !p.is_empty() => p,
174 _ => return Ok(EditorOutcome::Cancelled),
175 };
176 let mut cmd = Command::new(&parts[0]);
177 if parts.len() > 1 {
178 cmd.args(&parts[1..]);
179 }
180 push_target_args(&mut cmd, &parts[0], path, line);
181 let status = match cmd.status() {
182 Ok(status) => status,
183 Err(_) => return Ok(EditorOutcome::Cancelled),
184 };
185
186 let after = fs::read_to_string(path).unwrap_or_default();
187 if after == before {
188 // A non-zero exit with no change is the editor being quit; a
189 // non-zero exit that *did* change the file still changed the file.
190 return Ok(if status.success() {
191 EditorOutcome::Unchanged
192 } else {
193 EditorOutcome::Cancelled
194 });
195 }
196 Ok(EditorOutcome::Edited(after))
197 }
198
199 /// Suspend the TUI, run the external editor on `path`, then re-enter it.
200 ///
201 /// The suspend/resume dance is [`spawn_editor_for_input`]'s, factored so the
202 /// composer and a file editor cannot drift on terminal-mode restoration.
203 pub(crate) fn spawn_editor_for_path(
204 terminal: &mut Terminal<ColorCompatBackend<Stdout>>,
205 use_mouse_capture: bool,
206 use_bracketed_paste: bool,
207 path: &std::path::Path,
208 line: Option<u32>,
209 ) -> io::Result<EditorOutcome> {
210 with_suspended_tui(terminal, use_mouse_capture, use_bracketed_paste, || {
211 run_editor_on_path(path, line)
212 })
213 }
214
215 /// Suspend the TUI, run the external editor on `current`, then re-enter the
216 /// TUI. Returns the new composer text iff the user saved changes.
217 ///
218 /// On any error (raw-mode toggle, IO, editor spawn failure), the function
219 /// still attempts to fully restore the terminal before returning.
220 pub(crate) fn spawn_editor_for_input(
221 terminal: &mut Terminal<ColorCompatBackend<Stdout>>,
222 use_mouse_capture: bool,
223 use_bracketed_paste: bool,
224 current: &str,
225 ) -> io::Result<EditorOutcome> {
226 with_suspended_tui(terminal, use_mouse_capture, use_bracketed_paste, || {
227 run_editor_raw(current)
228 })
229 }
230
231 /// Hand the terminal to a child, run `body`, and restore the TUI.
232 ///
233 /// Restoration is best-effort and runs on every path, including a `body` that
234 /// failed: leaving raw mode or the alt screen wrong is worse than the error
235 /// being reported.
236 fn with_suspended_tui(
237 terminal: &mut Terminal<ColorCompatBackend<Stdout>>,
238 use_mouse_capture: bool,
239 use_bracketed_paste: bool,
240 body: impl FnOnce() -> io::Result<EditorOutcome>,
241 ) -> io::Result<EditorOutcome> {
242 // 0. Stop reading the tty.
243 // #6165: suspending crossterm state is not enough. The input pump runs on
244 // its own thread and keeps calling `event::read()` whatever mode the
245 // terminal is in, so a child launched without this pause competes with
246 // Codewhale for every keystroke — the editor cannot be quit and the
247 // fragments land in the composer. Pausing here, rather than at each call
248 // site, is what makes `/hooks edit` and the composer editor correct by
249 // the same construction. Fail closed: a pump that will not stop means the
250 // handoff would reproduce the defect, so the editor does not run.
251 let input_pause = crate::tui::ui::pause_terminal_input_for_child()?;
252
253 // 1. Suspend.
254 // Focus reporting is about to be disabled. Fail closed to the quiet state
255 // so a stale FocusLost cannot authorize a surprise notification while an
256 // external editor owns the terminal.
257 crate::tui::notifications::set_terminal_focused(true);
258 // #443: pop keyboard enhancement flags first so the editor
259 // process doesn't inherit a half-configured input mode. Best-
260 // effort — matches the shutdown / panic paths in main.rs.
261 // Use the Windows-aware helper: the raw crossterm execute!() is a
262 // no-op on Windows and would leave the editor process in Kitty mode.
263 suspend_tui_child_modes(
264 terminal.backend_mut(),
265 use_mouse_capture,
266 use_bracketed_paste,
267 );
268 let _ = disable_raw_mode();
269 let _ = super::ui::leave_alt_screen(terminal.backend_mut());
270
271 // 2. Run the child (synchronous; inherits stdio).
272 let result = body();
273
274 // 3. Resume — best-effort restoration regardless of `result`.
275 let _ = enable_raw_mode();
276 let _ = super::ui::enter_alt_screen(terminal.backend_mut());
277 super::ui::recover_terminal_modes(
278 terminal.backend_mut(),
279 use_mouse_capture,
280 use_bracketed_paste,
281 );
282 // Reporting was unavailable during the handoff. Resume focused and wait
283 // for a fresh FocusLost before background-only delivery is eligible.
284 crate::tui::notifications::set_terminal_focused(true);
285 // Force a full repaint so a SIGWINCH during the edit doesn't leave the
286 // viewport stale.
287 let _ = terminal.clear();
288
289 // 4. Take the tty back, after the modes it reads under are restored.
290 drop(input_pause);
291
292 result
293 }
294
295 fn suspend_tui_child_modes<W: Write>(
296 writer: &mut W,
297 use_mouse_capture: bool,
298 use_bracketed_paste: bool,
299 ) {
300 super::ui::pop_keyboard_enhancement_flags(writer);
301 super::ui::disable_alternate_scroll_mode(writer);
302 let _ = execute!(writer, DisableFocusChange);
303 if use_mouse_capture {
304 disable_mouse_capture_for_child(writer);
305 }
306 if use_bracketed_paste {
307 super::ui::disable_bracketed_paste_mode(writer);
308 }
309 let _ = writer.flush();
310 }
311
312 fn disable_mouse_capture_for_child<W: Write>(writer: &mut W) {
313 // Crossterm's mouse-capture command takes a WinAPI path on Windows and
314 // does not emit bytes into PTY-style terminals such as mintty. Release
315 // the WinAPI state before resetting the inherited PTY state so resume
316 // can re-enable capture through a real console-mode transition.
317 #[cfg(windows)]
318 let _ = execute!(writer, crossterm::event::DisableMouseCapture);
319 const DISABLE_MOUSE_CAPTURE: &[u8] = b"\x1b[?1006l\x1b[?1015l\x1b[?1003l\x1b[?1002l\x1b[?1000l";
320 if let Err(err) = writer.write_all(DISABLE_MOUSE_CAPTURE) {
321 tracing::debug!(?err, "DisableMouseCapture direct reset ignored");
322 }
323 }
324
325 #[cfg(test)]
326 mod tests {
327 use super::*;
328 use crate::test_support::{EnvVarGuard, lock_test_env};
329
330 /// The file on disk is the document: a `hooks.toml` the user edits stays
331 /// edited, and the outcome only reports whether the bytes moved.
332 #[test]
333 #[cfg(unix)]
334 fn editing_a_path_in_place_reports_only_whether_the_bytes_moved() {
335 let _lock = lock_test_env();
336 let dir = tempfile::tempdir().unwrap();
337 let path = dir.path().join("hooks.toml");
338 fs::write(&path, "# seed\n").unwrap();
339
340 // An editor that saves nothing.
341 let _visual = EnvVarGuard::set("VISUAL", "true");
342 let _editor = EnvVarGuard::remove("EDITOR");
343 assert_eq!(
344 run_editor_on_path(&path, None).unwrap(),
345 EditorOutcome::Unchanged,
346 "an editor that changes nothing must not trigger a reload"
347 );
348
349 // An editor that appends a line.
350 let script = dir.path().join("append.sh");
351 fs::write(&script, "#!/bin/sh\nprintf 'x\\n' >> \"$1\"\n").unwrap();
352 use std::os::unix::fs::PermissionsExt as _;
353 fs::set_permissions(&script, fs::Permissions::from_mode(0o755)).unwrap();
354 // Shadow rather than reassign: both guards live, and drop order
355 // restores the original value last.
356 let _visual_script = EnvVarGuard::set("VISUAL", &script);
357 match run_editor_on_path(&path, None).unwrap() {
358 EditorOutcome::Edited(text) => assert!(text.contains("# seed") && text.contains('x')),
359 other => panic!("expected Edited, got {other:?}"),
360 }
361 assert!(
362 fs::read_to_string(&path).unwrap().contains('x'),
363 "the edit belongs to the real file, not a temp copy"
364 );
365 }
366
367 /// The line argument is spelled per editor family, and an unknown editor
368 /// gets the bare path rather than an argument it would treat as a file.
369 #[test]
370 fn push_target_args_spells_the_line_per_editor_family() {
371 use std::ffi::OsStr;
372
373 let path = std::path::Path::new("/w/src/main.rs");
374 let args_for = |program: &str, line: Option<u32>| -> Vec<String> {
375 let mut cmd = Command::new(program);
376 push_target_args(&mut cmd, program, path, line);
377 cmd.get_args()
378 .map(OsStr::to_string_lossy)
379 .map(|s| s.into_owned())
380 .collect()
381 };
382
383 // No line: byte-identical to the historical `cmd.arg(path)`.
384 assert_eq!(args_for("vim", None), vec!["/w/src/main.rs"]);
385 assert_eq!(args_for("code", None), vec!["/w/src/main.rs"]);
386
387 // vi family, including an absolute path and a .exe suffix.
388 assert_eq!(args_for("vim", Some(12)), vec!["+12", "/w/src/main.rs"]);
389 assert_eq!(args_for("nano", Some(3)), vec!["+3", "/w/src/main.rs"]);
390 assert_eq!(
391 args_for("/usr/bin/nvim", Some(9)),
392 vec!["+9", "/w/src/main.rs"]
393 );
394 // `.exe` is stripped by `file_stem` on every platform. A backslashed
395 // Windows *path* only splits on Windows, so it is not asserted here.
396 assert_eq!(args_for("vim.exe", Some(5)), vec!["+5", "/w/src/main.rs"]);
397
398 // VS Code and forks need the flag; Zed/Sublime/JetBrains take file:line.
399 assert_eq!(
400 args_for("code", Some(42)),
401 vec!["--goto", "/w/src/main.rs:42"]
402 );
403 assert_eq!(args_for("zed", Some(42)), vec!["/w/src/main.rs:42"]);
404
405 // Unknown editor: open the right file, never an invented argument.
406 assert_eq!(args_for("my-editor", Some(42)), vec!["/w/src/main.rs"]);
407 }
408
409 #[test]
410 fn resolve_editor_prefers_visual_over_editor() {
411 let _lock = lock_test_env();
412 let _visual = EnvVarGuard::set("VISUAL", "vis-cmd");
413 let _editor = EnvVarGuard::set("EDITOR", "ed-cmd");
414 assert_eq!(resolve_editor(), "vis-cmd");
415 }
416
417 #[test]
418 fn resolve_editor_falls_back_to_vi() {
419 let _lock = lock_test_env();
420 let _visual = EnvVarGuard::remove("VISUAL");
421 let _editor = EnvVarGuard::remove("EDITOR");
422 assert_eq!(resolve_editor(), "vi");
423 }
424
425 /// Editor that immediately exits 0 without touching the file ⇒ Unchanged.
426 #[test]
427 #[cfg(unix)]
428 fn run_editor_unchanged_when_editor_is_noop() {
429 let _lock = lock_test_env();
430 let _visual = EnvVarGuard::remove("VISUAL");
431 let _editor = EnvVarGuard::set("EDITOR", "true");
432 let out = run_editor_raw("seed text").expect("editor ok");
433 assert_eq!(out, EditorOutcome::Unchanged);
434 }
435
436 /// Editor that exits non-zero ⇒ Cancelled.
437 #[test]
438 #[cfg(unix)]
439 fn run_editor_cancelled_on_nonzero_exit() {
440 let _lock = lock_test_env();
441 let _visual = EnvVarGuard::remove("VISUAL");
442 let _editor = EnvVarGuard::set("EDITOR", "false");
443 let out = run_editor_raw("seed").expect("call ok");
444 assert_eq!(out, EditorOutcome::Cancelled);
445 }
446
447 /// Spawning an editor binary that doesn't exist ⇒ Cancelled (graceful).
448 #[test]
449 #[cfg(unix)]
450 fn run_editor_cancelled_when_editor_missing() {
451 let _lock = lock_test_env();
452 let _visual = EnvVarGuard::remove("VISUAL");
453 let _editor = EnvVarGuard::set("EDITOR", "/nonexistent/codewhale-test-editor");
454 let out = run_editor_raw("seed").expect("call ok");
455 assert_eq!(out, EditorOutcome::Cancelled);
456 }
457
458 /// Editor that rewrites the file ⇒ Edited(new).
459 #[test]
460 #[cfg(unix)]
461 fn run_editor_returns_edited_contents() {
462 use std::os::unix::fs::PermissionsExt;
463
464 let _lock = lock_test_env();
465 let dir = tempfile::tempdir().unwrap();
466 let script = dir.path().join("ed.sh");
467 fs::write(&script, "#!/bin/sh\nprintf 'edited body' > \"$1\"\n").unwrap();
468 let mut perms = fs::metadata(&script).unwrap().permissions();
469 perms.set_mode(0o755);
470 fs::set_permissions(&script, perms).unwrap();
471
472 let _visual = EnvVarGuard::remove("VISUAL");
473 let _editor = EnvVarGuard::set("EDITOR", &script);
474 let out = run_editor_raw("seed body").expect("editor ok");
475 assert_eq!(out, EditorOutcome::Edited("edited body".to_string()));
476 }
477
478 /// Verify that the temp file is unlinked after `run_editor_raw` returns,
479 /// regardless of outcome. We test the success path with a script that
480 /// echoes the file path to a side channel before exiting.
481 #[test]
482 #[cfg(unix)]
483 fn run_editor_cleans_up_temp_file() {
484 use std::os::unix::fs::PermissionsExt;
485
486 let _lock = lock_test_env();
487 let dir = tempfile::tempdir().unwrap();
488 let path_capture = dir.path().join("capture.txt");
489 let script = dir.path().join("ed.sh");
490 fs::write(
491 &script,
492 format!(
493 "#!/bin/sh\nprintf '%s' \"$1\" > \"{}\"\nprintf 'x' > \"$1\"\n",
494 path_capture.display()
495 ),
496 )
497 .unwrap();
498 let mut perms = fs::metadata(&script).unwrap().permissions();
499 perms.set_mode(0o755);
500 fs::set_permissions(&script, perms).unwrap();
501
502 let _visual = EnvVarGuard::remove("VISUAL");
503 let _editor = EnvVarGuard::set("EDITOR", &script);
504 let _ = run_editor_raw("seed").expect("editor ok");
505
506 let captured = fs::read_to_string(&path_capture).expect("captured path");
507 assert!(!captured.is_empty(), "editor should have received a path");
508 assert!(
509 !std::path::Path::new(&captured).exists(),
510 "temp file {captured:?} should be cleaned up after run_editor_raw returns"
511 );
512 }
513
514 #[test]
515 fn suspend_tui_child_modes_disables_every_inherited_mode() {
516 let mut out = Vec::new();
517
518 suspend_tui_child_modes(&mut out, true, true);
519
520 let seq = String::from_utf8_lossy(&out);
521 assert!(
522 seq.contains("\x1b[?1007l"),
523 "external editor suspend must disable alternate-scroll mode: {seq:?}"
524 );
525 assert!(
526 seq.contains("\x1b[?1004l"),
527 "external editor suspend must disable focus events: {seq:?}"
528 );
529 assert!(
530 seq.contains("\x1b[?2004l"),
531 "external editor suspend must disable bracketed paste: {seq:?}"
532 );
533 assert!(
534 seq.contains("\x1b[?1000l"),
535 "external editor suspend must disable mouse capture when active: {seq:?}"
536 );
537 }
538
539 #[test]
540 fn suspend_tui_child_modes_leaves_mouse_capture_alone_when_inactive() {
541 let mut out = Vec::new();
542
543 suspend_tui_child_modes(&mut out, false, true);
544
545 let seq = String::from_utf8_lossy(&out);
546 assert!(
547 !seq.contains("\x1b[?1000l"),
548 "external editor suspend must not emit mouse-capture reset when inactive: {seq:?}"
549 );
550 }
551
552 #[test]
553 fn resume_tui_child_modes_reenables_shared_terminal_modes() {
554 let mut out = Vec::new();
555
556 crate::tui::ui::recover_terminal_modes(&mut out, true, true);
557
558 let seq = String::from_utf8_lossy(&out);
559 assert!(
560 !seq.contains("\x1b[?1007h"),
561 "must not enable alternate-scroll"
562 );
563 assert!(seq.contains("\x1b[?1007l"), "must reset alternate-scroll");
564 assert!(
565 seq.contains("\x1b[?1004h"),
566 "external editor resume must restore focus events: {seq:?}"
567 );
568 assert!(
569 seq.contains("\x1b[?2004h"),
570 "external editor resume must restore bracketed paste: {seq:?}"
571 );
572 }
573
574 #[test]
575 fn resume_tui_child_modes_leaves_alternate_scroll_off_when_mouse_capture_inactive() {
576 let mut out = Vec::new();
577
578 crate::tui::ui::recover_terminal_modes(&mut out, false, true);
579
580 let seq = String::from_utf8_lossy(&out);
581 assert!(
582 !seq.contains("\x1b[?1007h"),
583 "external editor resume must not enable alternate-scroll without mouse capture: {seq:?}"
584 );
585 assert!(
586 seq.contains("\x1b[?1007l"),
587 "external editor resume must reset alternate-scroll without mouse capture: {seq:?}"
588 );
589 assert!(
590 seq.contains("\x1b[?1004h"),
591 "external editor resume must still restore focus events: {seq:?}"
592 );
593 assert!(
594 seq.contains("\x1b[?2004h"),
595 "external editor resume must still restore bracketed paste: {seq:?}"
596 );
597 }
598 }
599
599 lines RUST