From 92ff00b6cc044b7a143fcddfbffe3470073fe02e Mon Sep 17 00:00:00 2001 From: vasilito Date: Sat, 20 Jun 2026 10:26:45 +0300 Subject: [PATCH] tlc: CLI +N argument for tlcedit/tlcview (MC parity) Both binaries support MC-style +N positional: 'tlcedit +42 file.txt' opens at line 42. tlcview gains line support for the first time. main.rs updated for new open_file(file, start_line) signature. --- .../recipes/tui/tlc/source/src/bin/tlcedit.rs | 41 +++++++++++++------ .../recipes/tui/tlc/source/src/bin/tlcview.rs | 33 +++++++++++---- local/recipes/tui/tlc/source/src/main.rs | 2 +- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/local/recipes/tui/tlc/source/src/bin/tlcedit.rs b/local/recipes/tui/tlc/source/src/bin/tlcedit.rs index 813c6d9a44..8426898397 100644 --- a/local/recipes/tui/tlc/source/src/bin/tlcedit.rs +++ b/local/recipes/tui/tlc/source/src/bin/tlcedit.rs @@ -1,24 +1,30 @@ //! tlcedit — standalone editor entry point. //! //! Opens a file in the TLC built-in editor, same as `tlc edit `. +//! Supports MC-style `+N` to open at a specific line: `tlcedit +42 file.txt`. use std::process::ExitCode; - -#[derive(Debug, clap::Parser)] -#[command(name = "tlcedit", version, about = "Twilight Commander — built-in editor")] -struct Cli { - /// File to edit. - file: String, - - /// Line number to jump to on open. - #[arg(long, value_name = "N")] - line: Option, -} +use clap::Parser; fn main() -> ExitCode { - let cli = ::parse(); + let mut raw: Vec = std::env::args().skip(1).collect(); + let mut start_line: Option = None; + raw.retain(|a| { + if let Some(n) = a.strip_prefix('+') { + if let Ok(line) = n.parse::() { + start_line = Some(line); + return false; + } + } + true + }); - match tlc::editor::open_file(&cli.file, cli.line) { + let mut full: Vec = vec!["tlcedit".to_string()]; + full.extend(raw); + let cli = Cli::parse_from(full); + let line = cli.line.or(start_line); + + match tlc::editor::open_file(&cli.file, line) { Ok(()) => ExitCode::SUCCESS, Err(e) => { eprintln!("tlcedit: cannot open {file}: {e}", file = cli.file); @@ -26,3 +32,12 @@ fn main() -> ExitCode { } } } + +#[derive(Debug, clap::Parser)] +#[command(name = "tlcedit", version, about = "Twilight Commander — built-in editor")] +struct Cli { + file: String, + + #[arg(long, value_name = "N")] + line: Option, +} diff --git a/local/recipes/tui/tlc/source/src/bin/tlcview.rs b/local/recipes/tui/tlc/source/src/bin/tlcview.rs index 511001c0e3..2e217b4902 100644 --- a/local/recipes/tui/tlc/source/src/bin/tlcview.rs +++ b/local/recipes/tui/tlc/source/src/bin/tlcview.rs @@ -1,20 +1,29 @@ //! tlcview — standalone viewer entry point. //! //! Opens a file in the TLC built-in viewer, same as `tlc view `. +//! Supports MC-style `+N` to open at a specific line: `tlcview +42 file.txt`. use std::process::ExitCode; - -#[derive(Debug, clap::Parser)] -#[command(name = "tlcview", version, about = "Twilight Commander — built-in viewer")] -struct Cli { - /// File to view. - file: String, -} +use clap::Parser; fn main() -> ExitCode { - let cli = ::parse(); + let mut raw: Vec = std::env::args().skip(1).collect(); + let mut start_line: Option = None; + raw.retain(|a| { + if let Some(n) = a.strip_prefix('+') { + if let Ok(line) = n.parse::() { + start_line = Some(line); + return false; + } + } + true + }); - match tlc::viewer::open_file(&cli.file) { + let mut full: Vec = vec!["tlcview".to_string()]; + full.extend(raw); + let cli = Cli::parse_from(full); + + match tlc::viewer::open_file(&cli.file, start_line) { Ok(()) => ExitCode::SUCCESS, Err(e) => { eprintln!("tlcview: cannot view {file}: {e}", file = cli.file); @@ -22,3 +31,9 @@ fn main() -> ExitCode { } } } + +#[derive(Debug, clap::Parser)] +#[command(name = "tlcview", version, about = "Twilight Commander — built-in viewer")] +struct Cli { + file: String, +} diff --git a/local/recipes/tui/tlc/source/src/main.rs b/local/recipes/tui/tlc/source/src/main.rs index 7249b24c9f..2ef6472542 100644 --- a/local/recipes/tui/tlc/source/src/main.rs +++ b/local/recipes/tui/tlc/source/src/main.rs @@ -128,7 +128,7 @@ fn run_editor(file: &str, line: Option) -> ExitCode { fn run_viewer(file: &str) -> ExitCode { log::info!("opening viewer for {file}"); - match tlc::viewer::open_file(file) { + match tlc::viewer::open_file(file, None) { Ok(()) => ExitCode::SUCCESS, Err(e) => { eprintln!("tlc: cannot view {file}: {e}");