Soft wrap text with fold and tput cols#3
Merged
Conversation
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. |
Contributor
Author
|
I've already added tput cols to get curent terminal size though |
Owner
|
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 also note the -9 in the arg this is coz of the line numbering in bat that has a with of 9. |
Owner
|
looks good 🙏 thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Upgrade from #2)
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