mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 06:27:45 +00:00
dd: use num_format::Float directly instead of printf
This commit is contained in:
parent
39c6758475
commit
ee0e2c042b
1 changed files with 11 additions and 4 deletions
|
@ -13,8 +13,10 @@ use std::io::Write;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use uucore::format::sprintf;
|
use uucore::{
|
||||||
use uucore::{error::UResult, format::FormatArgument};
|
error::UResult,
|
||||||
|
format::num_format::{FloatVariant, Formatter},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::numbers::{to_magnitude_and_suffix, SuffixType};
|
use crate::numbers::{to_magnitude_and_suffix, SuffixType};
|
||||||
|
|
||||||
|
@ -152,8 +154,13 @@ impl ProgUpdate {
|
||||||
let (carriage_return, newline) = if rewrite { ("\r", "") } else { ("", "\n") };
|
let (carriage_return, newline) = if rewrite { ("\r", "") } else { ("", "\n") };
|
||||||
|
|
||||||
// The duration should be formatted as in `printf %g`.
|
// The duration should be formatted as in `printf %g`.
|
||||||
// TODO: remove unwrap and make FormatError implement UError
|
let mut duration_str = Vec::new();
|
||||||
let duration_str = sprintf("%g", &[FormatArgument::Float(duration)])?;
|
uucore::format::num_format::Float {
|
||||||
|
variant: FloatVariant::Shortest,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.fmt(&mut duration_str, duration)?;
|
||||||
|
// We assume that printf will output valid UTF-8
|
||||||
let duration_str = std::str::from_utf8(&duration_str).unwrap();
|
let duration_str = std::str::from_utf8(&duration_str).unwrap();
|
||||||
|
|
||||||
// If the number of bytes written is sufficiently large, then
|
// If the number of bytes written is sufficiently large, then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue