diff --git a/cmd/ingest_tap/model.go b/cmd/ingest_tap/model.go index 93e79376..b2900e14 100644 --- a/cmd/ingest_tap/model.go +++ b/cmd/ingest_tap/model.go @@ -1,6 +1,7 @@ package main import ( + "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/table" "github.com/charmbracelet/bubbles/viewport" "github.com/charmbracelet/lipgloss" @@ -36,6 +37,8 @@ type ( focusIcaoList []string + help help.Model + statsTable table.Model selectedTable table.Model planesTable table.Model @@ -81,6 +84,7 @@ func initialModel(natsURL, wsURL string) (*model, error) { logger: logger.With().Str("app", "model").Logger(), startTime: time.Now(), tapper: NewPlaneWatchTapper(WithLogger(logger)), + help: help.New(), tickDuration: time.Millisecond * 16, focusIcaoList: make([]string, 0), source: planesSourceWSLow, diff --git a/cmd/ingest_tap/tui.go b/cmd/ingest_tap/tui.go index 8c172d97..5e7e74a7 100644 --- a/cmd/ingest_tap/tui.go +++ b/cmd/ingest_tap/tui.go @@ -1,6 +1,7 @@ package main import ( + "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/table" "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" @@ -22,6 +23,22 @@ const ( planesSourceWSHigh ) +type keyMap map[string]key.Binding + +var keyBindings = keyMap{ + "Up": key.NewBinding(key.WithKeys("up"), key.WithHelp("↑", "Move up in the aircraft list")), + "Down": key.NewBinding(key.WithKeys("up"), key.WithHelp("↓", "Move up in the aircraft list")), + "PageUp": key.NewBinding(key.WithKeys("up"), key.WithHelp("PgUp", "Move a page up in the aircraft list")), + "PageDown": key.NewBinding(key.WithKeys("up"), key.WithHelp("PgDn", "Move a page down in the aircraft list")), + + "Source": key.NewBinding(key.WithKeys("s"), key.WithHelp("s", "Switch Plane List Data Source")), + "Select": key.NewBinding(key.WithKeys(tea.KeyEnter.String()), key.WithHelp(tea.KeyEnter.String(), "Select a plane")), + + "Quit": key.NewBinding(key.WithKeys("q", "ctrl+c"), key.WithHelp("q/ctrl+c", "Exit")), + + "Help": key.NewBinding(key.WithKeys("h", "?"), key.WithHelp("h/?", "Show Help")), +} + func runTui(c *cli.Context) error { m, err := initialModel(c.String(natsURL), c.String(websocketURL)) if err != nil { @@ -67,18 +84,24 @@ func (m *model) Init() tea.Cmd { func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch tMsg := msg.(type) { case tea.KeyMsg: - switch tMsg.String() { - case "ctrl+c", "q": + switch { + case key.Matches(tMsg, keyBindings["Quit"]): return m, tea.Quit - case "s": + case key.Matches(tMsg, keyBindings["Source"]): if m.source == planesSourceWSHigh { m.source = planesSourceIngest } else { m.source++ } - case tea.KeyEnter.String(): + case key.Matches(tMsg, keyBindings["Select"]): m.selectedIcao = m.planesTable.SelectedRow()[0] m.selectedCallSign = m.planesTable.SelectedRow()[2] + m.logger.Info(). + Str("icao", m.selectedIcao). + Str("callsign", m.selectedCallSign). + Msg("Selecting Aircraft") + case key.Matches(tMsg, keyBindings["Help"]): + m.help.ShowAll = !m.help.ShowAll } case tea.WindowSizeMsg: m.width = tMsg.Width @@ -106,6 +129,7 @@ func (m *model) handleWindowSizing() { m.statsTable.SetWidth(m.width) m.selectedTable.SetWidth(m.width) m.planesTable.SetWidth(m.width) + m.help.Width = m.width headingHeight := lipgloss.Height(m.heading.Render("test")) statsTableHeight := 3 @@ -208,6 +232,7 @@ func (m *model) selectedTableRow(source planesSource, data *sourceInfo) table.Ro loc.LonStr(), loc.AltitudeStr(), loc.VerticalRateStr(), + loc.HeadingStr(), } } @@ -276,6 +301,8 @@ func (m *model) View() string { view += m.heading.Render("Logs") + "\n" view += m.logView.View() + "\n" } + + view += m.help.View(keyBindings) return view } @@ -284,3 +311,15 @@ func (m *model) tickCmd() tea.Cmd { return timerTick(t) }) } + +func (k keyMap) ShortHelp() []key.Binding { + return []key.Binding{k["Help"], k["Quit"]} +} + +func (k keyMap) FullHelp() [][]key.Binding { + return [][]key.Binding{ + {k["Up"], k["Down"], k["PgUp"], k["PgDn"]}, + {k["Source"], k["Select"]}, + {k["Help"], k["Quit"]}, + } +} diff --git a/lib/export/types.go b/lib/export/types.go index 304a69d2..fe990eed 100644 --- a/lib/export/types.go +++ b/lib/export/types.go @@ -378,6 +378,9 @@ func (pl *PlaneLocation) SquawkStr() string { if nil == pl { return "" } + if pl.Squawk == "0" { + return "" + } return pl.Squawk }