Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/uu/fold/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
fold-about = Writes each file (or standard input if no files are given)
to standard output whilst breaking long lines
fold-usage = fold [OPTION]... [FILE]...
fold-bytes-help = count using bytes rather than columns (meaning control characters such as newline are not treated specially)
fold-spaces-help = break lines at word boundaries rather than a hard cut-off
fold-width-help = set WIDTH as the maximum line width rather than 80
fold-error-illegal-width = illegal width value
fold-error-readline = failed to read line
7 changes: 7 additions & 0 deletions src/uu/fold/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fold-about = Écrit chaque fichier (ou l'entrée standard si aucun fichier n'est donné) sur la sortie standard en coupant les lignes trop longues
fold-usage = fold [OPTION]... [FICHIER]...
fold-bytes-help = compter en octets plutôt qu'en colonnes (les caractères de contrôle comme retour chariot ne sont pas traités spécialement)
fold-spaces-help = couper les lignes aux limites de mots plutôt qu'à une largeur fixe
fold-width-help = définir WIDTH comme largeur de ligne maximale au lieu de 80
fold-error-illegal-width = valeur de largeur illégale
fold-error-readline = échec de lecture de la ligne
26 changes: 15 additions & 11 deletions src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
// spell-checker:ignore (ToDOs) ncount routput

use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, Read, stdin};
use std::path::Path;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

const TAB_WIDTH: usize = 8;

Expand Down Expand Up @@ -41,7 +42,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Some(inp_width) => inp_width.parse::<usize>().map_err(|e| {
USimpleError::new(
1,
format!("illegal width value ({}): {e}", inp_width.quote()),
get_message_with_args(
"fold-error-illegal-width",
HashMap::from([
("width".to_string(), inp_width.quote().to_string()),
("error".to_string(), e.to_string()),
]),
),
)
})?,
None => 80,
Expand All @@ -65,24 +72,21 @@ pub fn uu_app() -> Command {
Arg::new(options::BYTES)
.long(options::BYTES)
.short('b')
.help(
"count using bytes rather than columns (meaning control characters \
such as newline are not treated specially)",
)
.help(get_message("fold-bytes-help"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::SPACES)
.long(options::SPACES)
.short('s')
.help("break lines at word boundaries rather than a hard cut-off")
.help(get_message("fold-spaces-help"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::WIDTH)
.long(options::WIDTH)
.short('w')
.help("set WIDTH as the maximum line width rather than 80")
.help(get_message("fold-width-help"))
.value_name("WIDTH")
.allow_hyphen_values(true),
)
Expand Down Expand Up @@ -142,7 +146,7 @@ fn fold_file_bytewise<T: Read>(mut file: BufReader<T>, spaces: bool, width: usiz
loop {
if file
.read_line(&mut line)
.map_err_context(|| "failed to read line".to_string())?
.map_err_context(|| get_message("fold-error-readline"))?
== 0
{
break;
Expand Down Expand Up @@ -236,7 +240,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, spaces: bool, width: usize) -> URe
loop {
if file
.read_line(&mut line)
.map_err_context(|| "failed to read line".to_string())?
.map_err_context(|| get_message("fold-error-readline"))?
== 0
{
break;
Expand Down Expand Up @@ -275,7 +279,7 @@ fn fold_file<T: Read>(mut file: BufReader<T>, spaces: bool, width: usize) -> URe
col_count += 1;
}
_ => col_count += 1,
};
}

output.push(ch);
}
Expand Down
Loading