rssi color, added columns cleaned up header bar started adding padding for elements
This commit is contained in:
parent
878def56ec
commit
c84a110f6e
BIN
.eros-data/devices/000000001.data
Normal file
BIN
.eros-data/devices/000000001.data
Normal file
Binary file not shown.
BIN
.eros-data/devices/index
Normal file
BIN
.eros-data/devices/index
Normal file
Binary file not shown.
0
.logs/2021-05-26T13:19:45-04:00.log
Normal file
0
.logs/2021-05-26T13:19:45-04:00.log
Normal file
0
.logs/2021-05-26T13:36:48-04:00.log
Normal file
0
.logs/2021-05-26T13:36:48-04:00.log
Normal file
0
.logs/2021-05-26T13:39:34-04:00.log
Normal file
0
.logs/2021-05-26T13:39:34-04:00.log
Normal file
0
.logs/2021-05-26T13:40:38-04:00.log
Normal file
0
.logs/2021-05-26T13:40:38-04:00.log
Normal file
0
.logs/2021-05-26T13:41:55-04:00.log
Normal file
0
.logs/2021-05-26T13:41:55-04:00.log
Normal file
0
.logs/2021-05-26T13:42:45-04:00.log
Normal file
0
.logs/2021-05-26T13:42:45-04:00.log
Normal file
0
.logs/2021-05-26T14:14:36-04:00.log
Normal file
0
.logs/2021-05-26T14:14:36-04:00.log
Normal file
0
.logs/2021-05-26T14:15:07-04:00.log
Normal file
0
.logs/2021-05-26T14:15:07-04:00.log
Normal file
0
.logs/2021-05-26T14:31:04-04:00.log
Normal file
0
.logs/2021-05-26T14:31:04-04:00.log
Normal file
0
.logs/2021-05-26T14:31:27-04:00.log
Normal file
0
.logs/2021-05-26T14:31:27-04:00.log
Normal file
0
.logs/2021-05-26T14:32:15-04:00.log
Normal file
0
.logs/2021-05-26T14:32:15-04:00.log
Normal file
0
.logs/2021-05-26T14:32:55-04:00.log
Normal file
0
.logs/2021-05-26T14:32:55-04:00.log
Normal file
0
.logs/2021-05-26T14:34:13-04:00.log
Normal file
0
.logs/2021-05-26T14:34:13-04:00.log
Normal file
0
.logs/2021-05-26T14:45:10-04:00.log
Normal file
0
.logs/2021-05-26T14:45:10-04:00.log
Normal file
0
.logs/2021-05-26T14:46:15-04:00.log
Normal file
0
.logs/2021-05-26T14:46:15-04:00.log
Normal file
0
.logs/2021-05-26T14:49:47-04:00.log
Normal file
0
.logs/2021-05-26T14:49:47-04:00.log
Normal file
0
.logs/2021-05-26T14:52:27-04:00.log
Normal file
0
.logs/2021-05-26T14:52:27-04:00.log
Normal file
0
.logs/2021-05-26T14:53:47-04:00.log
Normal file
0
.logs/2021-05-26T14:53:47-04:00.log
Normal file
0
.logs/2021-05-26T14:54:01-04:00.log
Normal file
0
.logs/2021-05-26T14:54:01-04:00.log
Normal file
0
.logs/2021-05-26T14:56:25-04:00.log
Normal file
0
.logs/2021-05-26T14:56:25-04:00.log
Normal file
0
.logs/2021-05-26T14:56:51-04:00.log
Normal file
0
.logs/2021-05-26T14:56:51-04:00.log
Normal file
0
.logs/2021-05-26T14:56:58-04:00.log
Normal file
0
.logs/2021-05-26T14:56:58-04:00.log
Normal file
0
.logs/2021-05-26T15:01:06-04:00.log
Normal file
0
.logs/2021-05-26T15:01:06-04:00.log
Normal file
0
.logs/2021-05-26T15:01:25-04:00.log
Normal file
0
.logs/2021-05-26T15:01:25-04:00.log
Normal file
0
.logs/2021-05-26T15:01:46-04:00.log
Normal file
0
.logs/2021-05-26T15:01:46-04:00.log
Normal file
0
.logs/2021-05-26T15:04:41-04:00.log
Normal file
0
.logs/2021-05-26T15:04:41-04:00.log
Normal file
0
.logs/2021-05-26T15:06:32-04:00.log
Normal file
0
.logs/2021-05-26T15:06:32-04:00.log
Normal file
0
.logs/2021-05-26T15:07:09-04:00.log
Normal file
0
.logs/2021-05-26T15:07:09-04:00.log
Normal file
0
.logs/2021-05-26T15:08:08-04:00.log
Normal file
0
.logs/2021-05-26T15:08:08-04:00.log
Normal file
0
.logs/2021-05-26T15:08:17-04:00.log
Normal file
0
.logs/2021-05-26T15:08:17-04:00.log
Normal file
0
.logs/2021-05-26T15:08:30-04:00.log
Normal file
0
.logs/2021-05-26T15:08:30-04:00.log
Normal file
0
.logs/2021-05-26T15:18:05-04:00.log
Normal file
0
.logs/2021-05-26T15:18:05-04:00.log
Normal file
0
.logs/2021-05-26T15:18:42-04:00.log
Normal file
0
.logs/2021-05-26T15:18:42-04:00.log
Normal file
0
.logs/2021-05-26T15:19:59-04:00.log
Normal file
0
.logs/2021-05-26T15:19:59-04:00.log
Normal file
0
.logs/2021-05-26T15:20:19-04:00.log
Normal file
0
.logs/2021-05-26T15:20:19-04:00.log
Normal file
0
.logs/2021-05-26T15:20:37-04:00.log
Normal file
0
.logs/2021-05-26T15:20:37-04:00.log
Normal file
0
.logs/2021-05-26T15:36:54-04:00.log
Normal file
0
.logs/2021-05-26T15:36:54-04:00.log
Normal file
0
.logs/2021-05-26T17:40:58Z.log
Normal file
0
.logs/2021-05-26T17:40:58Z.log
Normal file
0
.logs/2021-05-26T17:41:22Z.log
Normal file
0
.logs/2021-05-26T17:41:22Z.log
Normal file
0
.logs/2021-05-26T18:32:04Z.log
Normal file
0
.logs/2021-05-26T18:32:04Z.log
Normal file
70
tui.go
70
tui.go
@ -30,18 +30,20 @@ type model struct {
|
||||
func getSpinner() spinner.Model {
|
||||
s := spinner.NewModel()
|
||||
s.Spinner = spinner.Dot
|
||||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
||||
s.Style = lipgloss.NewStyle(
|
||||
).Foreground(lipgloss.Color("205"))
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
var initialModel = model {
|
||||
choices: []string{},
|
||||
choices: []string{ strings.Repeat(" ", 6 ) + "Address" + strings.Repeat(" ", 17) + "RSSI" },
|
||||
// A map which indicates which choices are selected. We're using
|
||||
// the map like a mathematical set. The keys refer to the indexes
|
||||
// of the `choices` slice, above.
|
||||
selected: make(map[int]struct{}),
|
||||
spinner: getSpinner(),
|
||||
cursor: 1,
|
||||
}
|
||||
|
||||
func initializeRadios() {
|
||||
@ -125,15 +127,35 @@ func (m model) Init() tea.Cmd {
|
||||
)
|
||||
}
|
||||
|
||||
func getFormattedRow(dev projVars.DiscoveredDevice) string {
|
||||
return fmt.Sprintf("%s%s%s",
|
||||
dev.ScanResult.Address.String(),
|
||||
strings.Repeat(" ", 7),
|
||||
func(rssi int16) string {
|
||||
if rssi < -80 {
|
||||
return lipgloss.NewStyle(
|
||||
).Foreground(lipgloss.Color("#FF0000"),
|
||||
).Render(fmt.Sprintf("%d", rssi))
|
||||
}
|
||||
if rssi < -50 {
|
||||
return lipgloss.NewStyle(
|
||||
).Foreground(lipgloss.Color("#FFFF00"),
|
||||
).Render(fmt.Sprintf("%d", rssi))
|
||||
} else {
|
||||
return lipgloss.NewStyle(
|
||||
).Foreground(lipgloss.Color("#008000"),
|
||||
).Render(fmt.Sprintf("%d", rssi))
|
||||
}
|
||||
}(dev.ScanResult.RSSI))
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case projVars.DiscoveredDevice:
|
||||
for k, v := range m.choices {
|
||||
if strings.HasPrefix(v, fmt.Sprintf("address: %s", msg.ScanResult.Address.String())) {
|
||||
m.choices[k] = fmt.Sprintf("address: %s rssi: %d",
|
||||
msg.ScanResult.Address.String(),
|
||||
msg.ScanResult.RSSI)
|
||||
if strings.HasPrefix(v, msg.ScanResult.Address.String()) {
|
||||
m.choices[k] = getFormattedRow(msg)
|
||||
|
||||
return m, listenForScanResults
|
||||
}
|
||||
@ -148,10 +170,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}(len(m.choices)):],
|
||||
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))
|
||||
m.choices = append(m.choices, getFormattedRow(msg))
|
||||
|
||||
return m, listenForScanResults
|
||||
|
||||
@ -172,7 +191,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
// The "up" and "k" keys move the cursor up
|
||||
case "up", "k":
|
||||
if m.cursor > 0 {
|
||||
if m.cursor > 1 {
|
||||
m.cursor--
|
||||
}
|
||||
|
||||
@ -201,16 +220,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
func (m model) View() string {
|
||||
// The header
|
||||
s := m.spinner.View(
|
||||
) + lipgloss.NewStyle(
|
||||
s := 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(78,
|
||||
).Render("protomolecule" + strings.Repeat(" ", 78 - 24) + "[q] - exit",
|
||||
) + "\n\n"
|
||||
|
||||
|
||||
/* Iterate over our choices
|
||||
@ -223,6 +241,10 @@ func (m model) View() string {
|
||||
https://stackoverflow.com/questions/24562942/golang-how-do-i-determine-the-number-of-lines-in-a-file-efficiently/24563853
|
||||
*/
|
||||
for i, choice := range m.choices {
|
||||
if strings.HasPrefix(choice, " ") {
|
||||
s += fmt.Sprintf("%s\n", choice)
|
||||
continue
|
||||
}
|
||||
|
||||
// Is the cursor pointing at this choice?
|
||||
cursor := " " // no cursor
|
||||
@ -230,7 +252,7 @@ func (m model) View() string {
|
||||
//cursor = ">" // cursor!
|
||||
cursor = lipgloss.NewStyle(
|
||||
).Blink(true,
|
||||
).Render(">")
|
||||
).Render(">")
|
||||
}
|
||||
|
||||
// Is this choice selected?
|
||||
@ -239,7 +261,7 @@ func (m model) View() string {
|
||||
//checked = "x" // selected!
|
||||
checked = lipgloss.NewStyle(
|
||||
).Bold(true,
|
||||
).Render("x")
|
||||
).Render("x")
|
||||
}
|
||||
|
||||
// Render the row
|
||||
@ -247,7 +269,7 @@ func (m model) View() string {
|
||||
}
|
||||
|
||||
// The footer
|
||||
s += "\nPress q to quit.\n"
|
||||
s += m.spinner.View()
|
||||
|
||||
// Send the UI for rendering
|
||||
return s
|
||||
@ -261,7 +283,7 @@ func listenForScanResults() tea.Msg {
|
||||
//time.Sleep( 1 * time.Second)
|
||||
return dev
|
||||
} else {
|
||||
time.Sleep( 1 * time.Second)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user