Center alignment for fmt
Use '^' to specify center alignment in format strings. fmt!( "[{:^5s}]", "Hi" ) -> "[ Hi ]" fmt!( "[{:^5s}]", "H" ) -> "[ H ]" fmt!( "[{:^5d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^5d}]", -1i ) -> "[ -1 ]" fmt!( "[{:^6d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^6d}]", -1i ) -> "[ -1 ]" If the padding is odd then the padding on the right will be one character longer than the padding on the left. Tuples squashed
This commit is contained in:
parent
6d8b5c9f7d
commit
2bc4a5e92a
6 changed files with 33 additions and 9 deletions
|
@ -81,6 +81,8 @@ pub enum Alignment {
|
|||
AlignLeft,
|
||||
/// The value will be aligned to the right.
|
||||
AlignRight,
|
||||
/// The value will be aligned in the center.
|
||||
AlignCenter,
|
||||
/// The value will take on a default alignment.
|
||||
AlignUnknown,
|
||||
}
|
||||
|
@ -279,7 +281,7 @@ impl<'a> Parser<'a> {
|
|||
match self.cur.clone().next() {
|
||||
Some((_, c)) => {
|
||||
match self.cur.clone().skip(1).next() {
|
||||
Some((_, '>')) | Some((_, '<')) => {
|
||||
Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
|
||||
spec.fill = Some(c);
|
||||
self.cur.next();
|
||||
}
|
||||
|
@ -293,6 +295,8 @@ impl<'a> Parser<'a> {
|
|||
spec.align = AlignLeft;
|
||||
} else if self.consume('>') {
|
||||
spec.align = AlignRight;
|
||||
} else if self.consume('^') {
|
||||
spec.align = AlignCenter;
|
||||
}
|
||||
// Sign flags
|
||||
if self.consume('+') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue