repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
d0dbcaf
parent
0598279
author
Eric Bower
date
2024-05-16 13:34:36 +0000 UTC
styles: cleanup tui colors
3 files changed,  +83, -98
M tui/cms.go
+2, -8
 1@@ -73,13 +73,6 @@ var menuChoices = map[menuChoice]string{
 2 	exitChoice:          "Exit",
 3 }
 4 
 5-func NewSpinner(styles common.Styles) spinner.Model {
 6-	s := spinner.New()
 7-	s.Spinner = spinner.Dot
 8-	s.Style = styles.Spinner
 9-	return s
10-}
11-
12 type GotDBMsg db.DB
13 
14 func CmsMiddleware(cfg *shared.ConfigSite) bm.Handler {
15@@ -460,5 +453,6 @@ func (m model) View() string {
16 		s = notifications.View(m.notifications)
17 		return s
18 	}
19-	return m.styles.App.Render(wrap.String(wordwrap.String(s, w), w))
20+	str := wrap.String(wordwrap.String(s, w), w)
21+	return m.styles.App.Render(str)
22 }
A tui/common/output.go
+67, -0
 1@@ -0,0 +1,67 @@
 2+package common
 3+
 4+import (
 5+	"fmt"
 6+	"os"
 7+	"strings"
 8+
 9+	"github.com/charmbracelet/ssh"
10+	"github.com/charmbracelet/wish"
11+	"github.com/kr/pty"
12+	"github.com/muesli/termenv"
13+)
14+
15+// Bridge Wish and Termenv so we can query for a user's terminal capabilities.
16+type sshOutput struct {
17+	ssh.Session
18+	tty *os.File
19+}
20+
21+func (s *sshOutput) Write(p []byte) (int, error) {
22+	return s.Session.Write(p)
23+}
24+
25+func (s *sshOutput) Read(p []byte) (int, error) {
26+	return s.Session.Read(p)
27+}
28+
29+func (s *sshOutput) Fd() uintptr {
30+	return s.tty.Fd()
31+}
32+
33+type sshEnviron struct {
34+	environ []string
35+}
36+
37+func (s *sshEnviron) Getenv(key string) string {
38+	for _, v := range s.environ {
39+		if strings.HasPrefix(v, key+"=") {
40+			return v[len(key)+1:]
41+		}
42+	}
43+	return ""
44+}
45+
46+func (s *sshEnviron) Environ() []string {
47+	return s.environ
48+}
49+
50+// Create a termenv.Output from the session.
51+func OutputFromSession(sesh ssh.Session) *termenv.Output {
52+	sshPty, _, _ := sesh.Pty()
53+	_, tty, err := pty.Open()
54+	if err != nil {
55+		wish.Fatalln(sesh, err)
56+		return nil
57+	}
58+	o := &sshOutput{
59+		Session: sesh,
60+		tty:     tty,
61+	}
62+	environ := sesh.Environ()
63+	environ = append(environ, fmt.Sprintf("TERM=%s", sshPty.Term))
64+	e := &sshEnviron{environ: environ}
65+	// We need to use unsafe mode here because the ssh session is not running
66+	// locally and we already know that the session is a TTY.
67+	return termenv.NewOutput(o, termenv.WithUnsafe(), termenv.WithEnvironment(e))
68+}
M tui/common/styles.go
+14, -90
  1@@ -1,88 +1,26 @@
  2 package common
  3 
  4 import (
  5-	"fmt"
  6-	"log"
  7-	"os"
  8-	"strings"
  9-
 10 	"github.com/charmbracelet/lipgloss"
 11-	"github.com/charmbracelet/ssh"
 12-	"github.com/kr/pty"
 13-	"github.com/muesli/termenv"
 14 )
 15 
 16-// Bridge Wish and Termenv so we can query for a user's terminal capabilities.
 17-type sshOutput struct {
 18-	ssh.Session
 19-	tty *os.File
 20-}
 21-
 22-func (s *sshOutput) Write(p []byte) (int, error) {
 23-	return s.Session.Write(p)
 24-}
 25-
 26-func (s *sshOutput) Read(p []byte) (int, error) {
 27-	return s.Session.Read(p)
 28-}
 29-
 30-func (s *sshOutput) Fd() uintptr {
 31-	return s.tty.Fd()
 32-}
 33-
 34-type sshEnviron struct {
 35-	environ []string
 36-}
 37-
 38-func (s *sshEnviron) Getenv(key string) string {
 39-	for _, v := range s.environ {
 40-		if strings.HasPrefix(v, key+"=") {
 41-			return v[len(key)+1:]
 42-		}
 43-	}
 44-	return ""
 45-}
 46-
 47-func (s *sshEnviron) Environ() []string {
 48-	return s.environ
 49-}
 50-
 51-// Create a termenv.Output from the session.
 52-func OutputFromSession(sess ssh.Session) *termenv.Output {
 53-	sshPty, _, _ := sess.Pty()
 54-	_, tty, err := pty.Open()
 55-	if err != nil {
 56-		// TODO: FIX
 57-		log.Fatal(err)
 58-	}
 59-	o := &sshOutput{
 60-		Session: sess,
 61-		tty:     tty,
 62-	}
 63-	environ := sess.Environ()
 64-	environ = append(environ, fmt.Sprintf("TERM=%s", sshPty.Term))
 65-	e := &sshEnviron{environ: environ}
 66-	// We need to use unsafe mode here because the ssh session is not running
 67-	// locally and we already know that the session is a TTY.
 68-	return termenv.NewOutput(o, termenv.WithUnsafe(), termenv.WithEnvironment(e))
 69-}
 70-
 71-// Color definitions.
 72 var (
 73 	Indigo       = lipgloss.AdaptiveColor{Light: "#5A56E0", Dark: "#7571F9"}
 74 	SubtleIndigo = lipgloss.AdaptiveColor{Light: "#7D79F6", Dark: "#514DC1"}
 75 	Cream        = lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}
 76 	Fuschia      = lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"}
 77-	Green        = lipgloss.Color("#04B575")
 78+	Green        = lipgloss.AdaptiveColor{Light: "#ABE5D1", Dark: "#04B575"}
 79+	DarkRed      = lipgloss.AdaptiveColor{Light: "#EBE5EC", Dark: "#2B2A2A"}
 80 	Red          = lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}
 81 	FaintRed     = lipgloss.AdaptiveColor{Light: "#FF6F91", Dark: "#C74665"}
 82+	Grey         = lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}
 83+	GreyLight    = lipgloss.AdaptiveColor{Light: "#BDB0BE", Dark: "#827983"}
 84 )
 85 
 86 type Styles struct {
 87 	Cursor,
 88 	Wrap,
 89 	Paragraph,
 90-	Keyword,
 91 	Code,
 92 	Subtle,
 93 	Error,
 94@@ -99,16 +37,11 @@ type Styles struct {
 95 	InactivePagination,
 96 	SelectionMarker,
 97 	SelectedMenuItem,
 98-	Checkmark,
 99 	Logo,
100 	BlurredButtonStyle,
101 	FocusedButtonStyle,
102 	HelpSection,
103 	HelpDivider,
104-	Spinner,
105-	CliPadding,
106-	CliBorder,
107-	CliHeader,
108 	App,
109 	RoundedBorder lipgloss.Style
110 	Renderer *lipgloss.Renderer
111@@ -121,20 +54,19 @@ func DefaultStyles(renderer *lipgloss.Renderer) Styles {
112 
113 	s.Cursor = renderer.NewStyle().Foreground(Fuschia)
114 	s.Wrap = renderer.NewStyle().Width(58)
115-	s.Keyword = renderer.NewStyle().Foreground(Green)
116 	s.Paragraph = s.Wrap.Copy().Margin(1, 0, 0, 2)
117 	s.Code = renderer.NewStyle().
118-		Foreground(lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}).
119-		Background(lipgloss.AdaptiveColor{Light: "#EBE5EC", Dark: "#2B2A2A"}).
120+		Foreground(Red).
121+		Background(DarkRed).
122 		Padding(0, 1)
123 	s.Subtle = renderer.NewStyle().
124-		Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"})
125+		Foreground(Grey)
126 	s.Error = renderer.NewStyle().Foreground(Red)
127-	s.Prompt = renderer.NewStyle().MarginRight(1).SetString(">")
128+	s.Prompt = renderer.NewStyle().MarginRight(1).SetString("•")
129 	s.FocusedPrompt = s.Prompt.Copy().Foreground(Fuschia)
130 	s.Note = renderer.NewStyle().Foreground(Green)
131 	s.NoteDim = renderer.NewStyle().
132-		Foreground(lipgloss.AdaptiveColor{Light: "#ABE5D1", Dark: "#2B4A3F"})
133+		Foreground(Green)
134 	s.Delete = s.Error.Copy()
135 	s.DeleteDim = renderer.NewStyle().Foreground(FaintRed)
136 	s.Label = renderer.NewStyle().Foreground(Fuschia)
137@@ -142,14 +74,11 @@ func DefaultStyles(renderer *lipgloss.Renderer) Styles {
138 	s.ListKey = renderer.NewStyle().Foreground(Indigo)
139 	s.ListDim = renderer.NewStyle().Foreground(SubtleIndigo)
140 	s.InactivePagination = renderer.NewStyle().
141-		Foreground(lipgloss.AdaptiveColor{Light: "#CACACA", Dark: "#4F4F4F"})
142+		Foreground(Grey)
143 	s.SelectionMarker = renderer.NewStyle().
144 		Foreground(Fuschia).
145 		PaddingRight(1).
146-		SetString(">")
147-	s.Checkmark = renderer.NewStyle().
148-		SetString("✔").
149-		Foreground(Green)
150+		SetString("•")
151 	s.SelectedMenuItem = renderer.NewStyle().Foreground(Fuschia)
152 	s.Logo = renderer.NewStyle().
153 		Foreground(Cream).
154@@ -157,22 +86,17 @@ func DefaultStyles(renderer *lipgloss.Renderer) Styles {
155 		Padding(0, 1)
156 	s.BlurredButtonStyle = renderer.NewStyle().
157 		Foreground(Cream).
158-		Background(lipgloss.AdaptiveColor{Light: "#BDB0BE", Dark: "#827983"}).
159+		Background(GreyLight).
160 		Padding(0, 3)
161 	s.FocusedButtonStyle = s.BlurredButtonStyle.Copy().
162 		Background(Fuschia)
163 	s.HelpDivider = renderer.NewStyle().
164-		Foreground(lipgloss.AdaptiveColor{Light: "#DDDADA", Dark: "#3C3C3C"}).
165+		Foreground(Grey).
166 		Padding(0, 1).
167 		SetString("•")
168 	s.HelpSection = renderer.NewStyle().
169-		Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"})
170+		Foreground(Grey)
171 	s.App = renderer.NewStyle().Margin(1, 0, 1, 2)
172-	s.Spinner = renderer.NewStyle().
173-		Foreground(lipgloss.AdaptiveColor{Light: "#8E8E8E", Dark: "#747373"})
174-	s.CliPadding = renderer.NewStyle().Padding(0, 1)
175-	s.CliHeader = s.CliPadding.Copy().Foreground(Indigo).Bold(true)
176-	s.CliBorder = renderer.NewStyle().Foreground(lipgloss.Color("238"))
177 	s.RoundedBorder = renderer.
178 		NewStyle().
179 		Padding(0, 1).