Documentation
¶
Overview ¶
Package radar is a widget that renders an animated radar sweep display.
The widget draws a rotating beam over a circular grid of range rings and crosshairs, reproducing the classic phosphor-persistence look of a monochrome PPI radar scope. The sweep trail fades from the beam's leading edge back through a configurable angular width.
Contact points are placed on the scope by the caller. Each contact dims gradually as the beam sweeps away and brightens again on the next pass, matching real radar refresh behaviour.
The sweep speed, beam width, direction (CW / CCW), total arc, and colours are all configurable through Option values.
Index ¶
- Constants
- type Contact
- type Direction
- type Option
- func BeamColor(r, g, b int) Option
- func BeamWidth(degrees float64) Option
- func Border(ls linestyle.LineStyle, cOpts ...cell.Option) Option
- func BorderTitle(title string) Option
- func ContactChar(ch rune) Option
- func ContactColor(r, g, b int) Option
- func HideTooltip() Option
- func RangeRings(n int) Option
- func ShowTooltip() Option
- func StartAngle(degrees float64) Option
- func SweepDirection(d Direction) Option
- func SweepSpan(degrees float64) Option
- func SweepSpeed(degreesPerSecond float64) Option
- type Radar
- func (r *Radar) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error
- func (r *Radar) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error
- func (r *Radar) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error
- func (r *Radar) Options() widgetapi.Options
- func (r *Radar) SetContacts(contacts []*Contact, opts ...Option) error
Constants ¶
const DefaultBeamWidth = 35.0
DefaultBeamWidth is the default angular width of the sweep trail in degrees.
const DefaultContactChar = '◆'
DefaultContactChar is the default rune used to mark contact positions.
const DefaultRangeRings = 3
DefaultRangeRings is the default number of concentric range rings.
const DefaultSweepSpan = 360.0
DefaultSweepSpan is the default total sweep arc in degrees (full rotation).
const DefaultSweepSpeed = 60.0
DefaultSweepSpeed is the default sweep speed in degrees per second.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Contact ¶
type Contact struct {
// Angle is the bearing in degrees, measured clockwise from North
// (0 = North, 90 = East, 180 = South, 270 = West).
Angle float64
// Distance is the range expressed as a fraction of the display radius
// (0.0 = at the origin, 1.0 = at the outer ring edge).
Distance float64
// Elevation is the contact's altitude in feet above sea level.
Elevation float64
// Label is a short human-readable identifier shown in the contact log
// and in the hover tooltip.
Label string
// Info is an optional extra line of free-form text appended to the
// hover tooltip (e.g. "AIR · 350 kt"). Leave empty to omit.
Info string
// contains filtered or unexported fields
}
Contact represents a single radar return (blip) displayed on the scope.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options to Radar.
func BeamColor ¶
BeamColor sets the primary color of the radar beam and its phosphor trail. r, g, b are RGB24 components in the range [0, 255]. Defaults to neon green (0, 255, 70).
func BeamWidth ¶
BeamWidth sets the angular width of the visible sweep trail (the phosphor fade). The value is in degrees. Larger values create a wider, more gradual fade. Defaults to 35.
func Border ¶
Border configures the Radar to have a border of the specified style. Optionally accepts cell options to style the border (e.g. color).
func BorderTitle ¶
BorderTitle sets a text title displayed within the border. Has no effect if no border style is configured.
func ContactChar ¶
ContactChar sets the Unicode rune drawn at each contact point on the display. Defaults to '◆'.
func ContactColor ¶
ContactColor sets the color used to render contact blip runes. r, g, b are RGB24 components in the range [0, 255]. Defaults to red (255, 50, 50).
func RangeRings ¶
RangeRings sets the number of concentric distance markers drawn on the display. Must be between 1 and 10. Defaults to 3.
func ShowTooltip ¶
func ShowTooltip() Option
ShowTooltip enables the mouse-hover tooltip popup. This is the default.
func StartAngle ¶
StartAngle sets the initial beam angle in degrees measured clockwise from North (top of the display). Defaults to 0.
func SweepDirection ¶
SweepDirection sets whether the beam sweeps clockwise or counter-clockwise. Defaults to DirectionClockwise.
func SweepSpan ¶
SweepSpan sets the total arc swept in one pass. Use 360 for a full rotation. Values less than 360 cause the beam to oscillate between 0 and SweepSpan rather than continuously rotating. Defaults to 360.
func SweepSpeed ¶
SweepSpeed sets the angular velocity of the radar sweep beam. The value is in degrees per second; e.g. 60 = one full rotation every 6 s. Defaults to 60.
type Radar ¶
type Radar struct {
// contains filtered or unexported fields
}
Radar renders an animated radar sweep display on the terminal.
Implements widgetapi.Widget. This object is thread-safe.
func New ¶
New returns a new Radar widget configured with the provided options. The widget is ready to draw immediately; call SetContacts to populate it.
func (*Radar) Draw ¶
Draw renders the radar scope onto the canvas. It advances the sweep beam according to the time elapsed since the previous frame and recomputes contact intensities before rendering.
Draw implements widgetapi.Widget.Draw.
func (*Radar) Keyboard ¶
Keyboard implements widgetapi.Widget.Keyboard. The Radar widget does not process keyboard events.
func (*Radar) Mouse ¶
Mouse implements widgetapi.Widget.Mouse. The widget records the cursor position on every event so that Draw can render a contact tooltip when the cursor is over a blip.