add update rssi to items

This commit is contained in:
sq 2021-05-26 12:46:29 -04:00
parent 324bfff597
commit c3f2942b85
No known key found for this signature in database
GPG Key ID: 7AF3499CBA8E6251
6 changed files with 23 additions and 12 deletions

35
tui.go

@ -129,9 +129,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case projVars.DiscoveredDevice:
for _, v := range m.choices {
for k, v := range m.choices {
if strings.HasPrefix(v, fmt.Sprintf("address: %s", msg.ScanResult.Address.String())) {
// TODO update RSSI
m.choices[k] = fmt.Sprintf("address: %s rssi: %d",
msg.ScanResult.Address.String(),
msg.ScanResult.RSSI)
return m, listenForScanResults
}
}
@ -146,7 +149,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
fmt.Sprintf("address: %s rssi: %d", msg.ScanResult.Address.String(), msg.ScanResult.RSSI)) */
m.choices = append(m.choices,
fmt.Sprintf("address: %s rssi: %d", msg.ScanResult.Address.String(), msg.ScanResult.RSSI))
fmt.Sprintf("address: %s rssi: %d",
msg.ScanResult.Address.String(),
msg.ScanResult.RSSI))
return m, listenForScanResults
@ -199,13 +204,13 @@ func (m model) View() string {
s := m.spinner.View(
) + lipgloss.NewStyle(
).Bold(true,
).Foreground(lipgloss.Color("#FAFAFA"),
).Background(lipgloss.Color("#7D56F4"),
).PaddingTop(0,
).PaddingLeft(0,
).Width(80,
).Render("Scanning for devices",
) + "\n\n"
).Foreground(lipgloss.Color("#FAFAFA"),
).Background(lipgloss.Color("#7D56F4"),
).PaddingTop(0,
).PaddingLeft(0,
).Width(80,
).Render("Scanning for devices",
) + "\n\n"
// Iterate over our choices
for i, choice := range m.choices {
@ -213,13 +218,19 @@ func (m model) View() string {
// Is the cursor pointing at this choice?
cursor := " " // no cursor
if m.cursor == i {
cursor = ">" // cursor!
//cursor = ">" // cursor!
cursor = lipgloss.NewStyle(
).Blink(true,
).Render(">")
}
// Is this choice selected?
checked := " " // not selected
if _, ok := m.selected[i]; ok {
checked = "x" // selected!
//checked = "x" // selected!
checked = lipgloss.NewStyle(
).Bold(true,
).Render("x")
}
// Render the row