Skip to content

Commit

Permalink
Implement flag for skipping wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Aug 31, 2024
1 parent 285d8cc commit 8191024
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn format_file(
let temp_state: State;
(line, temp_state) =
apply_indent(&line, linum_old, &state, logs, file, args);
if needs_wrap(&line, &temp_state) {
if needs_wrap(&line, &temp_state, args) {
let wrapped_lines =
apply_wrap(&line, &temp_state, file, args, logs);
if wrapped_lines.is_some() {
Expand Down
3 changes: 3 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct Cli {
pub check: bool,
#[arg(long, short, help = "Print to STDOUT, do not modify files")]
pub print: bool,
#[arg(long, short, help = "Keep lines, do not wrap")]
pub keep: bool,
#[arg(long, short, help = "Show info log messages")]
pub verbose: bool,
#[arg(long, short, help = "Show trace log messages")]
Expand All @@ -29,6 +31,7 @@ impl Cli {
Cli {
check: false,
print: false,
keep: false,
verbose: false,
trace: false,
files: Vec::<String>::new(),
Expand Down
5 changes: 3 additions & 2 deletions src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use log::Level::{Trace, Warn};
const WRAP_MIN: usize = 70;
const WRAP_MAX: usize = 80;

pub fn needs_wrap(line: &str, state: &State) -> bool {
(line.chars().count() > WRAP_MAX)
pub fn needs_wrap(line: &str, state: &State, args: &Cli) -> bool {
!args.keep
&& !state.leave.visual
&& !state.ignore.visual
&& (line.chars().count() > WRAP_MAX)
}

fn find_wrap_point(line: &str) -> Option<usize> {
Expand Down

0 comments on commit 8191024

Please sign in to comment.