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.
This commit is contained in:
2026-06-20 10:26:45 +03:00
parent 4e4863e122
commit 92ff00b6cc
3 changed files with 53 additions and 23 deletions
+28 -13
View File
@@ -1,24 +1,30 @@
//! tlcedit — standalone editor entry point.
//!
//! Opens a file in the TLC built-in editor, same as `tlc edit <file>`.
//! 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<u64>,
}
use clap::Parser;
fn main() -> ExitCode {
let cli = <Cli as clap::Parser>::parse();
let mut raw: Vec<String> = std::env::args().skip(1).collect();
let mut start_line: Option<u64> = None;
raw.retain(|a| {
if let Some(n) = a.strip_prefix('+') {
if let Ok(line) = n.parse::<u64>() {
start_line = Some(line);
return false;
}
}
true
});
match tlc::editor::open_file(&cli.file, cli.line) {
let mut full: Vec<String> = 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<u64>,
}
@@ -1,20 +1,29 @@
//! tlcview — standalone viewer entry point.
//!
//! Opens a file in the TLC built-in viewer, same as `tlc view <file>`.
//! 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 = <Cli as clap::Parser>::parse();
let mut raw: Vec<String> = std::env::args().skip(1).collect();
let mut start_line: Option<u64> = None;
raw.retain(|a| {
if let Some(n) = a.strip_prefix('+') {
if let Ok(line) = n.parse::<u64>() {
start_line = Some(line);
return false;
}
}
true
});
match tlc::viewer::open_file(&cli.file) {
let mut full: Vec<String> = 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,
}
+1 -1
View File
@@ -128,7 +128,7 @@ fn run_editor(file: &str, line: Option<u64>) -> 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}");