Files
BitLogger/docs/api/text-style.md
T
Nanaloveyuki 25a6a973d2 πŸ“ Update More API Document
2026-05-20 11:37:49 +08:00

2.2 KiB

name, group, category, update-time, description, key-word
name group category update-time description key-word
text-style api formatter 20260520 Create a reusable text style used by style tags and formatter config helpers.
style
formatter
color
public

Text-style

Create a TextStyle describing foreground color, background color, and emphasis flags such as bold or underline. This helper is the basic style value used by formatter style tags and config-driven formatter settings.

Interface

pub fn text_style(
  fg~ : String? = None,
  bg~ : String? = None,
  bold~ : Bool = false,
  dim~ : Bool = false,
  italic~ : Bool = false,
  underline~ : Bool = false,
) -> TextStyle {

input

  • fg : String? - Optional foreground color, usually a named color or hex string.
  • bg : String? - Optional background color.
  • bold : Bool - Whether bold emphasis is enabled.
  • dim : Bool - Whether dim emphasis is enabled.
  • italic : Bool - Whether italic emphasis is enabled.
  • underline : Bool - Whether underline emphasis is enabled.

output

  • TextStyle - Reusable style value.

Explanation

Detailed rules explaining key parameters and behaviors

  • This helper creates a plain style value; it does not register tags by itself.
  • The returned style is commonly used in style_tag_registry() and TextFormatterConfig::new(style_tags=...).
  • Color interpretation still depends on formatter color settings and runtime support.

How to Use

Here are some specific examples provided.

When Need A Reusable Custom Tag Style

When a formatter should define a named style tag:

let accent = text_style(fg=Some("#4cc9f0"), bold=true)

In this example, accent becomes a reusable style value that can be attached to a style tag registry or config map.

Error Case

e.g.:

  • If a style uses colors but the formatter disables markup or color output, visible rendering may not reflect the full style.

  • This helper does not validate higher-level tag naming because it only creates the style value itself.

Notes

  1. This is the basic building block for style-tag customization.

  2. Use style_tag_registry() when you need named tags rather than a raw style value.