(feat) MD syntax for bat|non fixed width for fold

This commit is contained in:
newbee1905
2022-07-12 13:54:25 +07:00
parent 62288ea334
commit 8e0edf66fe

View File

@@ -2,8 +2,16 @@ use std::io::Result;
use std::process::{Command, ExitStatus, Stdio};
pub fn open_bat() -> Result<ExitStatus> {
let terminal_cols_cmd = Command::new("tput").arg("cols").output()?.stdout;
let terminal_cols: String = match std::str::from_utf8(&terminal_cols_cmd) {
Err(_e) => "80".to_string(),
Ok(v) => (v.trim().parse::<i32>().unwrap() - 10).to_string(),
};
let soft_wrap = match Command::new("fold")
.arg("-s")
.arg("-w")
.arg(terminal_cols)
.arg("/tmp/log_e")
.stdout(Stdio::piped())
.spawn()
@@ -11,9 +19,12 @@ pub fn open_bat() -> Result<ExitStatus> {
Err(why) => panic!("couldn't spawn wc: {}", why),
Ok(soft_wrap) => soft_wrap,
};
Command::new("bat")
.arg("--paging")
.arg("always")
.arg("-l")
.arg("markdown")
.stdin(soft_wrap.stdout.unwrap())
.spawn()?
.wait()