Просмотр исходного кода

Implemented title color change on unstable connection

arianagiroux 3 недель назад
Родитель
Сommit
9f003da86c
4 измененных файлов с 59 добавлено и 9 удалено
  1. 9 2
      Readme.md
  2. 14 5
      internal/tui/tui.go
  3. 36 0
      internal/tui/types.go
  4. 0 2
      main.go

+ 9 - 2
Readme.md

@@ -10,7 +10,6 @@ additionally, see `bin/` for additional pre-compiled binaries
 
 
 - main.go:// TODO(main): determine chart heights dynamically by number of addresses
 - main.go:// TODO(main): determine chart heights dynamically by number of addresses
 - main.go:// TODO(performance): implement ping message channel buffering
 - main.go:// TODO(performance): implement ping message channel buffering
-- main.go:// TODO(tui): notify user when an address is not resolving
 
 
 > NOTE: generate this list via `git grep '// TODO' -- ':(exclude)Readme.md'`
 > NOTE: generate this list via `git grep '// TODO' -- ':(exclude)Readme.md'`
 
 
@@ -20,9 +19,11 @@ additionally, see `bin/` for additional pre-compiled binaries
  - [x] Implements viewport logic via bubbles
  - [x] Implements viewport logic via bubbles
  - [x] Implements ntcharts framework for tables
  - [x] Implements ntcharts framework for tables
 
 
-### Extras
+## Extras
  - [ ] Implement ssh TUI client (via wish)
  - [ ] Implement ssh TUI client (via wish)
 
 
+## resources
+
 | resource        | use                                |
 | resource        | use                                |
 |-----------------|------------------------------------|
 |-----------------|------------------------------------|
 | Core frameworks |                                    |
 | Core frameworks |                                    |
@@ -37,6 +38,12 @@ additionally, see `bin/` for additional pre-compiled binaries
 | [wish][wish]    | ssh tui client                     |
 | [wish][wish]    | ssh tui client                     |
 |-----------------|------------------------------------|
 |-----------------|------------------------------------|
 
 
+### color palette
+
+| base      | lower     | middle    | secondary | primary   |
+|-----------|-----------|-----------|-----------|-----------|
+| `#19535f` | `#0b7a75` | `#d7c9aa` | `#7b2d26` | `#f0f3f5` |
+
 [bt]: https://github.com/charmbracelet/bubbletea
 [bt]: https://github.com/charmbracelet/bubbletea
 [lg]: https://github.com/charmbracelet/lipgloss
 [lg]: https://github.com/charmbracelet/lipgloss
 [bbl]: https://github.com/charmbracelet/bubbles
 [bbl]: https://github.com/charmbracelet/bubbles

+ 14 - 5
internal/tui/tui.go

@@ -4,6 +4,7 @@ package tui
 
 
 import (
 import (
 	"fmt"
 	"fmt"
+	"slices"
 	"time"
 	"time"
 
 
 	"github.com/NimbleMarkets/ntcharts/linechart/streamlinechart"
 	"github.com/NimbleMarkets/ntcharts/linechart/streamlinechart"
@@ -48,10 +49,6 @@ func (m Model) Tick() tea.Cmd {
 }
 }
 
 
 func (m Model) content() string {
 func (m Model) content() string {
-	var headerStyle = lipgloss.NewStyle().
-		Bold(true).
-		Italic(true)
-
 	var blockStyle = lipgloss.NewStyle().
 	var blockStyle = lipgloss.NewStyle().
 		Width(m.width).
 		Width(m.width).
 		Align(lipgloss.Center)
 		Align(lipgloss.Center)
@@ -61,7 +58,18 @@ func (m Model) content() string {
 		if len(address.results) == 0 {
 		if len(address.results) == 0 {
 			output = output + fmt.Sprintf("\n%s\tloading...", headerStyle.Render(address.Address))
 			output = output + fmt.Sprintf("\n%s\tloading...", headerStyle.Render(address.Address))
 		} else if m.viewport.Width != 0 && m.viewport.Height != 0 {
 		} else if m.viewport.Width != 0 && m.viewport.Height != 0 {
-			output = output + fmt.Sprintf("\n%s", blockStyle.Render(headerStyle.Render(address.Address)))
+			if slices.Contains(address.results, -1) {
+				output = output + fmt.Sprintf("\n%s",
+					blockStyle.Render(headerStyle.Render(
+						fmt.Sprintf("%s\t%s",
+							secondaryColor.Render(address.Address),
+							infoStyle.Render("(connection unstable)"),
+						),
+					)))
+			} else {
+				output = output + fmt.Sprintf("\n%s",
+					blockStyle.Render(headerStyle.Render(address.Address)))
+			}
 
 
 			// Linechart // TODO(complexity): too many if branches
 			// Linechart // TODO(complexity): too many if branches
 			var slc streamlinechart.Model
 			var slc streamlinechart.Model
@@ -85,6 +93,7 @@ func (m Model) content() string {
 
 
 	return output
 	return output
 }
 }
+
 func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	var cmd tea.Cmd
 	var cmd tea.Cmd
 	var cmds []tea.Cmd
 	var cmds []tea.Cmd

+ 36 - 0
internal/tui/types.go

@@ -3,6 +3,8 @@ package tui
 import (
 import (
 	"pingo/internal/ping"
 	"pingo/internal/ping"
 	"time"
 	"time"
+
+	"github.com/charmbracelet/lipgloss"
 )
 )
 
 
 type Address struct {
 type Address struct {
@@ -47,6 +49,8 @@ func (a *Address) Last() (delay float64) {
 	}
 	}
 }
 }
 
 
+// [tea.Msg] signatures
+
 type tickMsg time.Time
 type tickMsg time.Time
 
 
 // A simple boolean flag sent when the program is ready to poll addresses
 // A simple boolean flag sent when the program is ready to poll addresses
@@ -56,3 +60,35 @@ type pollMsg bool
 type errMsg struct{ err error }
 type errMsg struct{ err error }
 
 
 func (e errMsg) Error() string { return e.err.Error() }
 func (e errMsg) Error() string { return e.err.Error() }
+
+// Style Defintions
+
+// A style for chart headers
+var headerStyle = lipgloss.NewStyle().
+	Bold(true).
+	Italic(true)
+
+// A style for info text
+var infoStyle = lipgloss.NewStyle().
+	Italic(true).
+	Faint(true)
+
+// A style for the base colour
+// var baseColor = lipgloss.NewStyle().
+// 	Foreground(lipgloss.Color("#19535f"))
+
+// A style for the lower colour
+// var lowerColor = lipgloss.NewStyle().
+// 	Foreground(lipgloss.Color("#0b7a75"))
+
+// A style for the middle colour
+// var middleColor = lipgloss.NewStyle().
+// 	Foreground(lipgloss.Color("#d7c9aa"))
+
+// A style for the secondary colour
+var secondaryColor = lipgloss.NewStyle().
+	Foreground(lipgloss.Color("#7b2d26"))
+
+	// A style for the primary colour
+	// var primaryColor = lipgloss.NewStyle().
+	// 	Foreground(lipgloss.Color("#f0f3f5"))

+ 0 - 2
main.go

@@ -4,8 +4,6 @@
 //
 //
 // TODO(performance): implement ping message channel buffering
 // TODO(performance): implement ping message channel buffering
 //
 //
-// TODO(tui): notify user when an address is not resolving
-//
 //	i.e, change the address title to red so long as there is a single -1 in
 //	i.e, change the address title to red so long as there is a single -1 in
 //	the display buffer, and a toast notification (???) if a display buffer is
 //	the display buffer, and a toast notification (???) if a display buffer is
 //	entirely composed of -1
 //	entirely composed of -1