pub struct BarSpectrum { /* private fields */ }Expand description
Levels as columns rising from the bottom, as cava and a graphic
equaliser show a spectrum: each band (from
dsp::bands, lowest first, falling under
dsp::Falloff for cava’s look) a bar
bar_width cells wide, gap cells
apart, its top in eighths of a cell.
mirrordraws the bands twice, the low ones in the middle and the high ones at both edges (cava’s mirrored layout);stereoputs one channel on each side, the left reversed.- Levels are scaled from 0 to the loudest band (or
range); a level outside is drawn at the end it passes, a NaN as 0. - The bars are centred in the width they are given. When they do not fit, the gaps go first, then the bars narrow to a cell, then neighbouring bands share a column (the louder shown).
- It fills the height it is given (a
Layoutregion, an intuiTUIve node) unlessheightis set; given none, it is 8 rows. In ASCII, each bar is#s to the nearest whole cell.
use rich::Console;
use rich_ext::chart::BarSpectrum;
let console = Console::builder().width(7).color_system(None).build();
let bars = BarSpectrum::new([1.0, 0.5, 0.25]).range(1.0).height(2);
assert_eq!(console.render_export(&bars), " █ \n █ █ ▄ \n");
// Mirrored: the low bands in the middle.
let console = Console::builder().width(11).color_system(None).build();
let mirrored = bars.mirror(true);
assert_eq!(console.render_export(&mirrored), " █ █ \n▄ █ █ █ █ ▄\n");Implementations§
Source§impl BarSpectrum
impl BarSpectrum
Sourcepub fn new(bands: impl IntoIterator<Item = f64>) -> Self
pub fn new(bands: impl IntoIterator<Item = f64>) -> Self
A bar per band of bands, lowest frequency first.
Sourcepub fn stereo(
left: impl IntoIterator<Item = f64>,
right: impl IntoIterator<Item = f64>,
) -> Self
pub fn stereo( left: impl IntoIterator<Item = f64>, right: impl IntoIterator<Item = f64>, ) -> Self
Two channels, mirrored: left’s bands from the middle out to the
left edge, right’s from the middle to the right edge.
Sourcepub fn mirror(self, mirror: bool) -> Self
pub fn mirror(self, mirror: bool) -> Self
Draw the bands twice, the low ones in the middle (default false).
A stereo spectrum is always mirrored.
Sourcepub fn range(self, max: f64) -> Self
pub fn range(self, max: f64) -> Self
The level of a full bar (default: the loudest band). Bars start at 0.
Sourcepub fn style(self, style: impl Into<String>) -> Self
pub fn style(self, style: impl Into<String>) -> Self
The bars’ style: a theme key or a definition (default
chart.bar).
Sourcepub fn charset(self, charset: Charset) -> Self
pub fn charset(self, charset: Charset) -> Self
Which glyphs to draw with (default Charset::Auto: blocks, or
ASCII on an ASCII-only console).
Trait Implementations§
Source§impl AccessibleText for BarSpectrum
Bar spectrum, 16 bands, mirrored, levels from 0 to 0.8, then the
loudest band (Loudest: band 3 of 16, 0.8); a stereo one says each
channel’s.
impl AccessibleText for BarSpectrum
Bar spectrum, 16 bands, mirrored, levels from 0 to 0.8, then the
loudest band (Loudest: band 3 of 16, 0.8); a stereo one says each
channel’s.
Source§fn accessible_text(&self, _width: usize) -> String
fn accessible_text(&self, _width: usize) -> String
width where layout matters.Source§impl Clone for BarSpectrum
impl Clone for BarSpectrum
Source§impl Debug for BarSpectrum
impl Debug for BarSpectrum
Source§impl Draw for BarSpectrum
impl Draw for BarSpectrum
Source§impl PartialEq for BarSpectrum
impl PartialEq for BarSpectrum
Source§impl Renderable for BarSpectrum
impl Renderable for BarSpectrum
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
(minimum, maximum) cell width this renderable wants. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.