Documentation
¶
Overview ¶
Package spectrum implements an audio-style spectrum analyzer widget.
Index ¶
- type AlertControl
- func (ac *AlertControl) AlertMessage() string
- func (ac *AlertControl) Draw(t terminalapi.Terminal, graphArea image.Rectangle, primaryLabel string) error
- func (ac *AlertControl) DrawAlert(t terminalapi.Terminal, pane image.Rectangle, focused bool) error
- func (ac *AlertControl) Enabled() bool
- func (ac *AlertControl) HandleMouse(pos image.Point, graphArea image.Rectangle, primaryLabel string) bool
- func (ac *AlertControl) SetEnabled(enabled bool)
- func (ac *AlertControl) SetThreshold(value int)
- func (ac *AlertControl) Threshold() int
- func (ac *AlertControl) UpdateSamples(values []int)
- type Mode
- type Option
- func AlertColor(c cell.Color) Option
- func AxisCellOpts(cOpts ...cell.Option) Option
- func ChannelLabels(primary, secondary string) Option
- func Gradient(colors ...cell.Color) Option
- func HalfDuplex() Option
- func HalfDuplexRune(r rune) Option
- func Height(h int) Option
- func Horizontal() Option
- func HorizontalRunes(runes ...rune) Option
- func LabelCellOpts(cOpts ...cell.Option) Option
- func MaxValue(v int) Option
- func PeakRunes(primary, secondary rune) Option
- func PrimaryRunes(runes ...rune) Option
- func SecondaryRunes(runes ...rune) Option
- func Stereo() Option
- func Threshold(v int) Option
- func ThresholdLineColor(c cell.Color) Option
- func Vertical() Option
- type Orientation
- type Sample
- type Spectrum
- func (s *Spectrum) Configure(opts ...Option) error
- func (s *Spectrum) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error
- func (*Spectrum) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error
- func (*Spectrum) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error
- func (s *Spectrum) Options() widgetapi.Options
- func (s *Spectrum) SetHalfDuplex(primary []int) error
- func (s *Spectrum) SetStereo(primary, secondary []int) error
- func (s *Spectrum) Update(primary, secondary []int) error
- func (s *Spectrum) ValueAt(size, pos image.Point) (Sample, bool)
- func (s *Spectrum) ValueCapacity() int
- type Synth
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertControl ¶
type AlertControl struct {
// contains filtered or unexported fields
}
AlertControl manages a threshold dropdown, an alarm checkbox, and an optional warning banner for a spectrum visualization.
The control is intended for overlay-style demos or dashboards that want a ready-made alarm UI without reimplementing layout, state, and mouse wiring. NewAlertControl remains the single constructor entry point; additional methods extend behavior without introducing alternate setup paths.
func NewAlertControl ¶
func NewAlertControl(min, max, step, selected int, onChange func(int) error) (*AlertControl, error)
NewAlertControl returns a new threshold and alarm control.
The generated thresholds cover the inclusive range `[min, max]` in `step` increments. The selected threshold snaps to the nearest generated value. The onChange callback is the low-level threshold hook and runs after user-driven threshold changes.
func (*AlertControl) AlertMessage ¶
func (ac *AlertControl) AlertMessage() string
AlertMessage returns the current warning banner message.
func (*AlertControl) Draw ¶
func (ac *AlertControl) Draw(t terminalapi.Terminal, graphArea image.Rectangle, primaryLabel string) error
Draw renders the alarm checkbox and threshold dropdown within graphArea.
The primary label is used only for horizontal alignment so the control can appear just to the right of a graph's leading title.
func (*AlertControl) DrawAlert ¶
func (ac *AlertControl) DrawAlert(t terminalapi.Terminal, pane image.Rectangle, focused bool) error
DrawAlert renders the warning banner centered inside pane when focused.
func (*AlertControl) Enabled ¶
func (ac *AlertControl) Enabled() bool
Enabled reports whether the alarm checkbox is currently checked.
func (*AlertControl) HandleMouse ¶
func (ac *AlertControl) HandleMouse(pos image.Point, graphArea image.Rectangle, primaryLabel string) bool
HandleMouse routes an absolute mouse click into the alert control.
func (*AlertControl) SetEnabled ¶
func (ac *AlertControl) SetEnabled(enabled bool)
SetEnabled replaces the checkbox state programmatically.
func (*AlertControl) SetThreshold ¶
func (ac *AlertControl) SetThreshold(value int)
SetThreshold snaps value to the nearest configured threshold and updates the dropdown selection to match.
func (*AlertControl) Threshold ¶
func (ac *AlertControl) Threshold() int
Threshold returns the currently selected threshold value.
func (*AlertControl) UpdateSamples ¶
func (ac *AlertControl) UpdateSamples(values []int)
UpdateSamples refreshes the alarm state against the latest values.
type Mode ¶
type Mode int
Mode controls whether the widget draws two mirrored channels or a single half-duplex channel.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options.
func AlertColor ¶
AlertColor sets the color used for rendered values that meet or exceed the configured threshold.
func AxisCellOpts ¶
AxisCellOpts sets the cell options used for the axis line.
func ChannelLabels ¶
ChannelLabels sets the labels shown around the axis for the primary and secondary channels.
func HalfDuplex ¶
func HalfDuplex() Option
HalfDuplex configures the widget to draw only the primary channel.
func HalfDuplexRune ¶
HalfDuplexRune sets the rune used to draw the single-channel half-duplex columns or rows.
func Height ¶
Height sets a fixed height for the Spectrum. If not set or set to zero, the widget uses all available vertical space.
func Horizontal ¶
func Horizontal() Option
Horizontal configures the widget to draw mirrored horizontal rows.
func HorizontalRunes ¶
HorizontalRunes sets the runes used to fill horizontally oriented channels. The runes are ordered from low amplitude to high amplitude.
func LabelCellOpts ¶
LabelCellOpts sets the cell options used for the axis labels.
func PrimaryRunes ¶
PrimaryRunes sets the runes used to fill the primary channel body. The runes are ordered from low amplitude to high amplitude.
func SecondaryRunes ¶
SecondaryRunes sets the runes used to fill the secondary channel body. The runes are ordered from low amplitude to high amplitude.
func Stereo ¶
func Stereo() Option
Stereo configures the widget to draw both channels around the axis.
func Threshold ¶
Threshold sets the alarm threshold value.
Values at or above the threshold are highlighted with AlertColor, and a threshold indicator line is drawn with ThresholdLineColor. Zero disables the threshold overlay.
func ThresholdLineColor ¶
ThresholdLineColor sets the color used to draw the threshold indicator line.
type Orientation ¶
type Orientation int
Orientation controls whether the spectrum draws as vertical columns or horizontal rows.
const ( // OrientationVertical draws mirrored columns around a horizontal axis. OrientationVertical Orientation = iota // OrientationHorizontal draws mirrored rows around a vertical axis. OrientationHorizontal )
type Sample ¶
type Sample struct {
// X is the one-based visible sample index.
X int
// Y is the sample value at X.
Y int
}
Sample identifies a visible data point under a rendered spectrum cell.
type Spectrum ¶
type Spectrum struct {
// contains filtered or unexported fields
}
Spectrum draws mirrored or half-duplex activity bars for fast-moving audio or telemetry signals.
Implements widgetapi.Widget. This object is thread-safe.
func (*Spectrum) Configure ¶
Configure updates rendering options while preserving the current samples.
func (*Spectrum) Draw ¶
Draw draws the Spectrum widget onto the canvas. Implements widgetapi.Widget.Draw.
func (*Spectrum) SetHalfDuplex ¶
SetHalfDuplex replaces the primary channel and switches the widget to half-duplex mode.
func (*Spectrum) Update ¶
Update replaces channel samples using automatic mode selection. Passing a nil secondary slice selects half-duplex mode.
func (*Spectrum) ValueAt ¶
ValueAt returns the visible sample under pos for a canvas of size.
The provided position must be relative to the widget canvas, not the terminal. The returned X value is one-based and follows the samples currently visible after fitting to the rendered span.
func (*Spectrum) ValueCapacity ¶
ValueCapacity returns the number of visible values the widget could display along its active sampling axis on the last draw.
type Synth ¶
type Synth struct {
// contains filtered or unexported fields
}
Synth generates smoothed synthetic activity suitable for driving spectrum widgets in demos and quick prototypes.
The output slices are reused between calls to Step. Treat them as read-only and copy if they need to be retained.
Directories
¶
| Path | Synopsis |
|---|---|
|
Binary spectrumdemo shows the functionality of a spectrum widget.
|
Binary spectrumdemo shows the functionality of a spectrum widget. |