mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
1.8 KiB
1.8 KiB
Title: Rule Order: 30 RedirectFrom: rule Description: "The Rule class is used to render a horizontal rule (line) to the terminal." Highlights: - Custom colors for line and title. - Specify left, center or right aligned title. Reference: T:Spectre.Console.Rule
The Rule
class is used to render a horizontal rule (line) to the terminal.
Usage
To render a rule without a title:
var rule = new Rule();
AnsiConsole.Write(rule);
Title
You can set the rule title markup text.
var rule = new Rule("[red]Hello[/]");
AnsiConsole.Write(rule);
───────────────────────────────── Hello ─────────────────────────────────
Title alignment
You can set the rule's title alignment.
var rule = new Rule("[red]Hello[/]");
rule.Alignment = Justify.Left;
AnsiConsole.Write(rule);
── Hello ────────────────────────────────────────────────────────────────
You can also specify it via an extension method:
var rule = new Rule("[red]Hello[/]");
rule.LeftJustified();
AnsiConsole.Write(rule);
── Hello ────────────────────────────────────────────────────────────────
Styling
var rule = new Rule("[red]Hello[/]");
rule.Style = Style.Parse("red dim");
AnsiConsole.Write(rule);
You can also specify it via an extension method
var rule = new Rule("[red]Hello[/]");
rule.RuleStyle("red dim");
AnsiConsole.Write(rule);