mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
(feat) MD syntax for bat|non fixed width for fold
This commit is contained in:
@@ -2,8 +2,16 @@ use std::io::Result;
|
|||||||
use std::process::{Command, ExitStatus, Stdio};
|
use std::process::{Command, ExitStatus, Stdio};
|
||||||
|
|
||||||
pub fn open_bat() -> Result<ExitStatus> {
|
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")
|
let soft_wrap = match Command::new("fold")
|
||||||
.arg("-s")
|
.arg("-s")
|
||||||
|
.arg("-w")
|
||||||
|
.arg(terminal_cols)
|
||||||
.arg("/tmp/log_e")
|
.arg("/tmp/log_e")
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
@@ -11,9 +19,12 @@ pub fn open_bat() -> Result<ExitStatus> {
|
|||||||
Err(why) => panic!("couldn't spawn wc: {}", why),
|
Err(why) => panic!("couldn't spawn wc: {}", why),
|
||||||
Ok(soft_wrap) => soft_wrap,
|
Ok(soft_wrap) => soft_wrap,
|
||||||
};
|
};
|
||||||
|
|
||||||
Command::new("bat")
|
Command::new("bat")
|
||||||
.arg("--paging")
|
.arg("--paging")
|
||||||
.arg("always")
|
.arg("always")
|
||||||
|
.arg("-l")
|
||||||
|
.arg("markdown")
|
||||||
.stdin(soft_wrap.stdout.unwrap())
|
.stdin(soft_wrap.stdout.unwrap())
|
||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()
|
.wait()
|
||||||
|
|||||||
Reference in New Issue
Block a user