~mariusor/motley

4e7887c89c8294a2f7ad5e9ef2c995eee9bda9cf — Marius Orcsik 6 months ago 0a9f3e6
Updated charm and bubbletea
2 files changed, 45 insertions(+), 70 deletions(-)

M go.mod
M ui.go
M go.mod => go.mod +14 -8
@@ 3,22 3,28 @@ module git.sr.ht/~marius/motley
go 1.14

require (
	github.com/charmbracelet/bubbles v0.7.6
	github.com/charmbracelet/bubbletea v0.12.2
	github.com/charmbracelet/glamour v0.2.0
	github.com/charmbracelet/bubbles v0.7.8
	github.com/charmbracelet/bubbletea v0.13.2
	github.com/charmbracelet/glamour v0.3.0
	github.com/charmbracelet/lipgloss v0.1.2
	github.com/containerd/console v1.0.2 // indirect
	github.com/dlclark/regexp2 v1.4.0 // indirect
	github.com/go-ap/activitypub v0.0.0-20210113095250-247f1fbf224c
	github.com/go-ap/auth v0.0.0-20210113101207-103038d69797
	github.com/go-ap/errors v0.0.0-20200702155720-f662512ba418
	github.com/go-ap/fedbox v0.0.0-20210116130525-fd9377430e3e
	github.com/go-ap/storage v0.0.0-20210113100905-747cc07ec1b1
	github.com/go-chi/chi v4.1.2+incompatible
	github.com/jackc/pgx v3.6.2+incompatible
	github.com/joho/godotenv v1.3.0
	github.com/mattn/go-runewidth v0.0.10
	github.com/mattn/go-runewidth v0.0.12
	github.com/microcosm-cc/bluemonday v1.0.9 // indirect
	github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68
	github.com/muesli/termenv v0.7.4
	github.com/muesli/termenv v0.8.1
	github.com/openshift/osin v1.0.1
	github.com/sirupsen/logrus v1.7.0
	golang.org/x/crypto v0.0.0-20201217014255-9d1352758620
	github.com/yuin/goldmark v1.3.5 // indirect
	golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
	golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 // indirect
	golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 // indirect
	golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect
	gopkg.in/urfave/cli.v2 v2.0.0-20190806201727-b62605953717
)

M ui.go => ui.go +31 -62
@@ 7,6 7,7 @@ import (
	"github.com/charmbracelet/bubbles/viewport"
	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/glamour"
	"github.com/charmbracelet/lipgloss"
	pub "github.com/go-ap/activitypub"
	"github.com/go-ap/storage"
	rw "github.com/mattn/go-runewidth"


@@ 65,7 66,7 @@ var (
var (
	// Color wraps termenv.ColorProfile.Color, which produces a termenv color
	// for use in termenv styling.
	Color func(string) te.Color = te.ColorProfile().Color
	Color = lipgloss.ColorProfile().Color

	// HasDarkBackground stores whether or not the terminal has a dark
	// background.


@@ 74,24 75,24 @@ var (

// Colors for dark and light backgrounds.
var (
	Indigo       ColorPair = NewColorPair("#7571F9", "#5A56E0")
	SubtleIndigo           = NewColorPair("#514DC1", "#7D79F6")
	Cream                  = NewColorPair("#FFFDF5", "#FFFDF5")
	YellowGreen            = NewColorPair("#ECFD65", "#04B575")
	Fuschia                = NewColorPair("#EE6FF8", "#EE6FF8")
	Green                  = NewColorPair("#04B575", "#04B575")
	Red                    = NewColorPair("#ED567A", "#FF4672")
	FaintRed               = NewColorPair("#C74665", "#FF6F91")
	SpinnerColor           = NewColorPair("#747373", "#8E8E8E")
	NoColor                = NewColorPair("", "")
	Indigo        = NewColorPair("#7571F9", "#5A56E0")
	SubtleIndigo  = NewColorPair("#514DC1", "#7D79F6")
	Cream        = NewColorPair("#FFFDF5", "#FFFDF5")
	YellowGreen  = NewColorPair("#ECFD65", "#04B575")
	Fuschia      = NewColorPair("#EE6FF8", "#EE6FF8")
	Green        = NewColorPair("#04B575", "#04B575")
	Red          = NewColorPair("#ED567A", "#FF4672")
	FaintRed     = NewColorPair("#C74665", "#FF6F91")
	SpinnerColor = NewColorPair("#747373", "#8E8E8E")
	NoColor      = NewColorPair("", "")
)

// Functions for styling strings.
var (
	IndigoFg       func(string) string = te.Style{}.Foreground(Indigo.Color()).Styled
	SubtleIndigoFg                     = te.Style{}.Foreground(SubtleIndigo.Color()).Styled
	RedFg                              = te.Style{}.Foreground(Red.Color()).Styled
	FaintRedFg                         = te.Style{}.Foreground(FaintRed.Color()).Styled
	IndigoFg       func(string) string = lipgloss.Style{}.Foreground(Indigo).Render
	SubtleIndigoFg                     = lipgloss.Style{}.Foreground(SubtleIndigo).Render
	RedFg                              = lipgloss.Style{}.Foreground(Red).Render
	FaintRedFg                         = lipgloss.Style{}.Foreground(FaintRed).Render
)

var (


@@ 150,18 151,23 @@ func newPagerModel(common *commonModel) pagerModel {
	ti := textinput.NewModel()
	ti.Prompt = te.String(" > ").
		Foreground(Color(darkGray)).
		Background(YellowGreen.Color()).
		Background(Color(YellowGreen.Dark)).
		String()

	/*
	ti.TextColor = darkGray
	ti.BackgroundColor = YellowGreen.String()
	ti.CursorColor = Fuschia.String()
	ti.CharLimit = noteCharacterLimit
	ti.Focus()
	 */

	// Text input for search
	sp := spinner.NewModel()
	/*
	sp.ForegroundColor = statusBarNoteFg.String()
	sp.BackgroundColor = statusBarBg.String()
	 */
	sp.HideFor = time.Millisecond * 50
	sp.MinimumLifetime = time.Millisecond * 180



@@ 247,33 253,11 @@ func (m model) View() string {
// ColorPair is a pair of colors, one intended for a dark background and the
// other intended for a light background. We'll automatically determine which
// of these colors to use.
type ColorPair struct {
	Dark  string
	Light string
}
type ColorPair = lipgloss.AdaptiveColor

// NewColorPair is a helper function for creating a ColorPair.
func NewColorPair(dark, light string) ColorPair {
	return ColorPair{dark, light}
}

// Color returns the appropriate termenv.Color for the terminal background.
func (c ColorPair) Color() te.Color {
	if HasDarkBackground {
		return Color(c.Dark)
	}

	return Color(c.Light)
}

// String returns a string representation of the color appropriate for the
// current terminal background.
func (c ColorPair) String() string {
	if HasDarkBackground {
		return c.Dark
	}

	return c.Light
	return lipgloss.AdaptiveColor{Dark: dark, Light: light}
}

// Wrap wraps lines at a predefined width via package muesli/reflow.


@@ 283,35 267,20 @@ func Wrap(s string) string {

// Keyword applies special formatting to imporant words or phrases.
func Keyword(s string) string {
	return te.String(s).Foreground(Green.Color()).String()
}

// Code applies special formatting to strings indeded to read as code.
func Code(s string) string {
	return te.String(" " + s + " ").
		Foreground(NewColorPair("#ED567A", "#FF4672").Color()).
		Background(NewColorPair("#2B2A2A", "#EBE5EC").Color()).
		String()
}

// Subtle applies formatting to strings intended to be "subtle".
func Subtle(s string) string {
	return te.String(s).Foreground(NewColorPair("#5C5C5C", "#9B9B9B").Color()).String()
	return te.String(s).Foreground(Color(Green.Dark)).String()
}

type styleFunc func(string) string
// Returns a termenv style with foreground and background options.
func newStyle(fg, bg ColorPair, bold bool) func(string) string {
	s := te.Style{}.Foreground(fg.Color()).Background(bg.Color())
	if bold {
		s = s.Bold()
	}
	return s.Styled
	s := lipgloss.Style{}.Foreground(fg).Background(bg)
	s = s.Bold(bold)
	return s.Render
}

// Returns a new termenv style with background options only.
func newFgStyle(c ColorPair) styleFunc {
	return te.Style{}.Foreground(c.Color()).Styled
	return te.Style{}.Foreground(Color(c.Dark)).Styled
}




@@ 469,7 438,7 @@ func logoView(text string) string {
	return te.String(withPadding(text)).
		Bold().
		Foreground(glowLogoTextColor).
		Background(Fuschia.Color()).
		Background(Color(Fuschia.Dark)).
		String()
}



@@ 483,7 452,7 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
	// Logo
	name := "FedBOX Admin TUI"
	haveErr := false
	if ob, _, err := m.r.LoadObjects(pub.IRI("http://example.com")); err == nil {
	if ob, _, err := m.r.LoadObjects(pub.IRI("https://fedbox.git/")); err == nil {
		pub.OnActor(ob.Collection().First(), func(a *pub.Actor) error {
			m.statusMessage = a.Summary.String()
			return nil