The Line Gauge Widget
The line_gauge widget displays a horizontal progress indicator using line-drawing characters. It’s more compact than gauge and ideal for dashboards where vertical space is limited.
Interface
use super::{Line, Style, Tui};
type LineGauge = {
filled_style: &[Style, null],
filled_symbol: &[string, null],
label: &[Line, null],
ratio: &f64,
style: &[Style, null],
unfilled_style: &[Style, null],
unfilled_symbol: &[string, null],
};
val line_gauge: fn(
?#filled_style: &[Style, null],
?#filled_symbol: &[string, null],
?#label: &[Line, null],
?#style: &[Style, null],
?#unfilled_style: &[Style, null],
?#unfilled_symbol: &[string, null],
ratio: &f64
) -> Tui;
Parameters
- filled_style - Style for the filled portion
- filled_symbol - Character used to draw the filled portion
- unfilled_style - Style for the unfilled portion
- unfilled_symbol - Character used to draw the unfilled portion
- label - A
Linedisplayed within the gauge - style - Base style for the widget
- ratio (positional) - The filled fraction, from 0.0 to 1.0; a value outside that range is clamped, with a logged warning
Examples
Basic Usage
use tui::{style, line_gauge::line_gauge};
// 75%
let progress = 0.75;
line_gauge(
#filled_style: &style(#fg: `Green),
&progress
)

Color-coded Status
use tui::{line, style, block::block, line_gauge::line_gauge};
let percentage = min(100, count(sys::time::timer(0.5, true)));
let power = cast<f64>(percentage)$ / 100.0;
let color = select power {
x if x < 0.10 => `Red,
x if x < 0.25 => `Yellow,
x => `Green
};
block(
#border: &`All,
#title: &line("Power"),
&line_gauge(
#filled_style: &style(#fg: color),
#label: &line("[percentage]%"),
&power
)
)

Compact Multi-metric Display
use tui::{line, style, layout::{child, layout}, line_gauge::line_gauge};
layout(
#direction: &`Vertical,
&[
child(#constraint: `Percentage(5), line_gauge(
#filled_style: &style(#fg: `Red),
#label: &line("CPU 45%"),
&0.45
)),
child(#constraint: `Percentage(5), line_gauge(
#filled_style: &style(#fg: `Yellow),
#label: &line("MEM 67%"),
&0.67
)),
child(#constraint: `Percentage(5), line_gauge(
#filled_style: &style(#fg: `Green),
#label: &line("DSK 23%"),
&0.23
))
]
)

Use Cases
- System resource monitors (CPU, RAM, disk, network)
- Download/upload progress indicators
- Compact status dashboards
- Progress tracking in limited space
Comparison with gauge
Use line_gauge when:
- You need compact, single-line displays
- Vertical space is limited
- You want a more technical/modern look
Use gauge when:
- You have more vertical space available
- You want larger, more prominent indicators