Skip to content

Soft wrap text with fold and tput cols#3

Merged
mrfluffy-dev merged 3 commits into
mrfluffy-dev:mainfrom
newbee1905:main
Jul 13, 2022
Merged

Soft wrap text with fold and tput cols#3
mrfluffy-dev merged 3 commits into
mrfluffy-dev:mainfrom
newbee1905:main

Conversation

@newbee1905
Copy link
Copy Markdown
Contributor

@newbee1905 newbee1905 commented Jul 12, 2022

(Upgrade from #2)

  • (feat) Soft wrap text with fold
  • (feat) MD syntax for bat|non fixed width for fold

Fold is a gnu utils
Tested with docker image for freebsd test
tput is from ncurses -> probably already existed
Minus the real terminal's width by 10 because of space of the number row

Improve reading experience with softwrap

@mrfluffy-dev
Copy link
Copy Markdown
Owner

although the word wrapping is cool the problem I have is the wrapping doesn't take in to account the size of the terminal so going full screen won't have the desired effect.

@newbee1905
Copy link
Copy Markdown
Contributor Author

newbee1905 commented Jul 13, 2022

I've already added tput cols to get curent terminal size though

@mrfluffy-dev
Copy link
Copy Markdown
Owner

mrfluffy-dev commented Jul 13, 2022

could you change the open_text.rs to something like this.

use std::io::Result;
use std::process::{Command, ExitStatus, Stdio};
extern crate termsize;
pub fn open_bat() -> Result<ExitStatus> {
    let termsize::Size {rows: _, cols} = termsize::get().unwrap();
    let soft_wrap = match Command::new("fold")
        .arg("-s")
        .arg("-w")
        .arg((cols-9).to_string())
        .arg("/tmp/log_e")
        .stdout(Stdio::piped())
        .spawn()
    {
        Err(why) => panic!("couldn't spawn wc: {}", why),
        Ok(soft_wrap) => soft_wrap,
    };

    Command::new("bat")
        .arg("--paging")
        .arg("always")
        .stdin(soft_wrap.stdout.unwrap())
        .spawn()?
        .wait()
}

note I am using the crate termsize = "0.1.6"

also note the -9 in the arg this is coz of the line numbering in bat that has a with of 9.

@mrfluffy-dev
Copy link
Copy Markdown
Owner

looks good 🙏 thanks.

@mrfluffy-dev mrfluffy-dev merged commit 3132f3b into mrfluffy-dev:main Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants