feat: add option to use glow instead of bat

This commit is contained in:
newbee1905
2023-02-01 22:42:51 +07:00
parent 652548057b
commit 330eb6239a
3 changed files with 70 additions and 21 deletions

View File

@@ -3,16 +3,15 @@ use std::process::{Command, ExitStatus, Stdio};
#[allow(unused_assignments)]
pub fn open_bat() -> Result<ExitStatus> {
let termsize::Size {rows: _, cols} = termsize::get().unwrap();
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
let mut path = String::new();
if cfg!(target_os = "windows"){
if cfg!(target_os = "windows") {
use dirs::home_dir;
let mut home = format!("{:?}",home_dir()).replace("\\\\","/");
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
home.drain(0..6);
home.drain(home.len()-2..home.len());
path = format!("{}/AppData/Roaming/log_e",home).to_string();
}
else{
home.drain(home.len() - 2..home.len());
path = format!("{}/AppData/Roaming/log_e", home).to_string();
} else {
path = "/tmp/log_e".to_string();
}
@@ -37,3 +36,36 @@ pub fn open_bat() -> Result<ExitStatus> {
.spawn()?
.wait()
}
#[allow(unused_assignments)]
pub fn open_glow() -> Result<ExitStatus> {
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
let mut path = String::new();
if cfg!(target_os = "windows") {
use dirs::home_dir;
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
home.drain(0..6);
home.drain(home.len() - 2..home.len());
path = format!("{}/AppData/Roaming/log_e", home).to_string();
} else {
path = "/tmp/log_e".to_string();
}
let soft_wrap = match Command::new("fold")
.arg("-s")
.arg("-w")
.arg((cols - 9).to_string())
.arg(path)
.stdout(Stdio::piped())
.spawn()
{
Err(why) => panic!("couldn't spawn wc: {}", why),
Ok(soft_wrap) => soft_wrap,
};
Command::new("glow")
.arg("-p")
.stdin(soft_wrap.stdout.unwrap())
.spawn()?
.wait()
}