Skip to main content

pad_left

Function pad_left 

Source
pub fn pad_left(s: &str, width: usize) -> String
Expand description

Pads a string on the left (right-aligns) to reach the target width.

ANSI escape codes are preserved and don’t count toward width calculations.

Warning: This does not strip BBCode tags—they will be counted toward the display width. For tagged content, compute padding manually using visible_width and " ".repeat(padding).

§Example

use standout_render::tabular::pad_left;

assert_eq!(pad_left("42", 5), "   42");
assert_eq!(pad_left("hello", 3), "hello");  // No truncation