mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-09 12:11:20 -03:00
Clean up fish-printf in preparation for publishing
Make fish-printf no longer depend on the widestring crate, as other clients won't use it; instead this is an optional feature. Make format strings a generic type, so that both narrow and wide strings can serve. This removes a lot of the complexity around converting from narrow to wide. Add a README.md to this crate.
This commit is contained in:
43
printf/README.md
Normal file
43
printf/README.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# fish-printf
|
||||
|
||||
The printf implementation used in [fish-shell](https://fishshell.com), based on musl printf.
|
||||
|
||||
[](https://crates.io/crates/fish-printf)
|
||||
|
||||
Licensed under the MIT license.
|
||||
|
||||
### Usage
|
||||
|
||||
Run `cargo add fish-printf` to add this crate to your `Cargo.toml` file.
|
||||
|
||||
Also run `cargo add widestring` to add the widestring crate.
|
||||
|
||||
### Notes
|
||||
|
||||
fish-printf attempts to match the C standard for printf. It supports the following features:
|
||||
|
||||
- Locale-specific formatting (decimal point, thousands separator, etc.)
|
||||
- Honors the current rounding mode.
|
||||
- Supports the `%n` modifier for counting characters written.
|
||||
|
||||
fish-printf does not support positional arguments, such as `printf("%2$d", 1, 2)`.
|
||||
|
||||
Prefixes like `l` or `ll` are recognized, but only used for validating the format string.
|
||||
The size of integer values is taken from the argument type.
|
||||
|
||||
fish-printf can output to an `std::fmt::Write` object, or return a string.
|
||||
|
||||
For reasons related to fish-shell, fish-printf has a feature "widestring" which uses the [widestring](https://crates.io/crates/widestring) crate. This is off by default.
|
||||
|
||||
### Examples
|
||||
|
||||
```rust
|
||||
use fish_printf::sprintf;
|
||||
|
||||
// Create a `String` from a format string.
|
||||
let s = sprintf!("%0.5g", 123456.0) // 1.2346e+05
|
||||
|
||||
// Append to an existing string.
|
||||
let s = String::new();
|
||||
sprintf!(=> &mut s, "%0.5g", 123456.0) // 1.2346e+05
|
||||
```
|
||||
Reference in New Issue
Block a user