diff --git a/.vscode/settings.json b/.vscode/settings.json index ae1e84e..7fca93f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,7 @@ "Nonblank", "nonprinting", "pico", + "Roff", "struct", "uutils", "xflags" diff --git a/complete/Cargo.toml b/complete/Cargo.toml index 54abe1a..16c73d0 100644 --- a/complete/Cargo.toml +++ b/complete/Cargo.toml @@ -8,3 +8,4 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +roff = "0.2.1" \ No newline at end of file diff --git a/complete/src/lib.rs b/complete/src/lib.rs index 4504797..b703d64 100644 --- a/complete/src/lib.rs +++ b/complete/src/lib.rs @@ -2,6 +2,7 @@ // file that was distributed with this source code. mod fish; +mod man; mod md; mod zsh; @@ -39,7 +40,7 @@ pub fn render(c: &Command, shell: &str) -> String { "md" => md::render(c), "fish" => fish::render(c), "zsh" => zsh::render(c), - "man" => panic!("manpages are not implemented yet"), + "man" => man::render(c), "sh" | "bash" | "csh" | "elvish" | "powershell" => panic!("shell '{shell}' completion is not implemented yet!"), _ => panic!("unknown option '{shell}'! Expected one of: \"md\", \"fish\", \"zsh\", \"man\", \"sh\", \"bash\", \"csh\", \"elvish\", \"powershell\""), } diff --git a/complete/src/man.rs b/complete/src/man.rs new file mode 100644 index 0000000..44500a6 --- /dev/null +++ b/complete/src/man.rs @@ -0,0 +1,33 @@ +use crate::Command; +use roff::{bold, roman, Roff}; + +pub fn render(c: &Command) -> String { + let mut page = Roff::new(); + page.control("TH", [&c.name.to_uppercase(), "1"]); + page.control("SH", ["NAME"]); + page.text([roman(&c.name)]); + page.control("SH", ["DESCRIPTION"]); + page.text([roman(&c.summary)]); + page.control("SH", ["OPTIONS"]); + + for arg in &c.args { + page.control("TP", []); + + let mut flags = Vec::new(); + for l in &arg.long { + if !flags.is_empty() { + flags.push(roman(", ")); + } + flags.push(bold(format!("--{l}"))); + } + for s in &arg.short { + if !flags.is_empty() { + flags.push(roman(", ")); + } + flags.push(bold(format!("-{s}"))); + } + page.text(flags); + page.text([roman(&arg.help)]); + } + page.render() +}