diff --git a/ui/ignore_darwin.go b/ui/ignore_darwin.go index 6a0b4ef..cccd305 100644 --- a/ui/ignore_darwin.go +++ b/ui/ignore_darwin.go @@ -6,8 +6,8 @@ import "path/filepath" func ignorePatterns(m model) []string { return []string{ - filepath.Join(m.general.cfg.HomeDir, "Library"), - m.general.cfg.Gopath, + filepath.Join(m.common.cfg.HomeDir, "Library"), + m.common.cfg.Gopath, "node_modules", ".*", } diff --git a/ui/ignore_general.go b/ui/ignore_general.go index 838cea7..21f4734 100644 --- a/ui/ignore_general.go +++ b/ui/ignore_general.go @@ -4,7 +4,7 @@ package ui func ignorePatterns(m model) []string { return []string{ - m.general.cfg.Gopath, + m.common.cfg.Gopath, "node_modules", ".*", } diff --git a/ui/pager.go b/ui/pager.go index 0f4a9c6..262d54e 100644 --- a/ui/pager.go +++ b/ui/pager.go @@ -12,7 +12,7 @@ import ( "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/charm" - "github.com/charmbracelet/charm/ui/common" + lib "github.com/charmbracelet/charm/ui/common" "github.com/charmbracelet/glamour" runewidth "github.com/mattn/go-runewidth" "github.com/muesli/reflow/ansi" @@ -24,27 +24,27 @@ const statusBarHeight = 1 var ( pagerHelpHeight int - mintGreen = common.NewColorPair("#89F0CB", "#89F0CB") - darkGreen = common.NewColorPair("#1C8760", "#1C8760") + mintGreen = lib.NewColorPair("#89F0CB", "#89F0CB") + darkGreen = lib.NewColorPair("#1C8760", "#1C8760") noteHeading = te.String(" Set Memo "). - Foreground(common.Cream.Color()). - Background(common.Green.Color()). + Foreground(lib.Cream.Color()). + Background(lib.Green.Color()). String() - statusBarNoteFg = common.NewColorPair("#7D7D7D", "#656565") - statusBarBg = common.NewColorPair("#242424", "#E6E6E6") + statusBarNoteFg = lib.NewColorPair("#7D7D7D", "#656565") + statusBarBg = lib.NewColorPair("#242424", "#E6E6E6") // Styling funcs. - statusBarScrollPosStyle = newStyle(common.NewColorPair("#5A5A5A", "#949494"), statusBarBg, false) + statusBarScrollPosStyle = newStyle(lib.NewColorPair("#5A5A5A", "#949494"), statusBarBg, false) statusBarNoteStyle = newStyle(statusBarNoteFg, statusBarBg, false) - statusBarHelpStyle = newStyle(statusBarNoteFg, common.NewColorPair("#323232", "#DCDCDC"), false) - statusBarStashDotStyle = newStyle(common.Green, statusBarBg, false) + statusBarHelpStyle = newStyle(statusBarNoteFg, lib.NewColorPair("#323232", "#DCDCDC"), false) + statusBarStashDotStyle = newStyle(lib.Green, statusBarBg, false) statusBarMessageStyle = newStyle(mintGreen, darkGreen, false) statusBarMessageStashIconStyle = newStyle(mintGreen, darkGreen, false) statusBarMessageScrollPosStyle = newStyle(mintGreen, darkGreen, false) - statusBarMessageHelpStyle = newStyle(common.NewColorPair("#B6FFE4", "#B6FFE4"), common.Green, false) - helpViewStyle = newStyle(statusBarNoteFg, common.NewColorPair("#1B1B1B", "#f2f2f2"), false) + statusBarMessageHelpStyle = newStyle(lib.NewColorPair("#B6FFE4", "#B6FFE4"), lib.Green, false) + helpViewStyle = newStyle(statusBarNoteFg, lib.NewColorPair("#1B1B1B", "#f2f2f2"), false) ) type contentRenderedMsg string @@ -61,7 +61,7 @@ const ( ) type pagerModel struct { - general *general + common *commonModel viewport viewport.Model state pagerState showHelp bool @@ -80,7 +80,7 @@ type pagerModel struct { stashedDocument *markdown } -func newPagerModel(general *general) pagerModel { +func newPagerModel(common *commonModel) pagerModel { // Init viewport vp := viewport.Model{} vp.YPosition = 0 @@ -89,12 +89,12 @@ func newPagerModel(general *general) pagerModel { // Text input for notes/memos ti := textinput.NewModel() ti.Prompt = te.String(" > "). - Foreground(common.Color(darkGray)). - Background(common.YellowGreen.Color()). + Foreground(lib.Color(darkGray)). + Background(lib.YellowGreen.Color()). String() ti.TextColor = darkGray - ti.BackgroundColor = common.YellowGreen.String() - ti.CursorColor = common.Fuschia.String() + ti.BackgroundColor = lib.YellowGreen.String() + ti.CursorColor = lib.Fuschia.String() ti.CharLimit = noteCharacterLimit ti.Focus() @@ -106,7 +106,7 @@ func newPagerModel(general *general) pagerModel { sp.MinimumLifetime = time.Millisecond * 180 return pagerModel{ - general: general, + common: common, state: pagerStateBrowse, textInput: ti, viewport: vp, @@ -135,7 +135,7 @@ func (m *pagerModel) setContent(s string) { func (m *pagerModel) toggleHelp() { m.showHelp = !m.showHelp - m.setSize(m.general.width, m.general.height) + m.setSize(m.common.width, m.common.height) if m.viewport.PastBottom() { m.viewport.GotoBottom() } @@ -187,7 +187,7 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) { var cmd tea.Cmd if m.textInput.Value() != m.currentDocument.Note { // don't update if the note didn't change m.currentDocument.Note = m.textInput.Value() // update optimistically - cmd = saveDocumentNote(m.general.cc, m.currentDocument.ID, m.currentDocument.Note) + cmd = saveDocumentNote(m.common.cc, m.currentDocument.ID, m.currentDocument.Note) } m.state = pagerStateBrowse m.textInput.Reset() @@ -235,13 +235,13 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) { return m, textinput.Blink case "s": - if m.general.authStatus != authOK { + if m.common.authStatus != authOK { break } md := m.currentDocument - _, alreadyStashed := m.general.filesStashed[md.localID] + _, alreadyStashed := m.common.filesStashed[md.localID] if alreadyStashed { cmds = append(cmds, m.showStatusMessage("Already stashed")) break @@ -253,7 +253,7 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) { m.spinner.Start() cmds = append( cmds, - stashDocument(m.general.cc, md), + stashDocument(m.common.cc, md), spinner.Tick, ) } @@ -313,7 +313,7 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) { } case stashFailMsg: - delete(m.general.filesStashed, msg.markdown.localID) + delete(m.common.filesStashed, msg.markdown.localID) case statusMessageTimeoutMsg: m.state = pagerStateBrowse @@ -404,7 +404,7 @@ func (m pagerModel) statusBarView(b *strings.Builder) { } } note = truncate(" "+note+" ", max(0, - m.general.width- + m.common.width- ansi.PrintableRuneWidth(logo)- ansi.PrintableRuneWidth(statusIndicator)- ansi.PrintableRuneWidth(scrollPercent)- @@ -418,7 +418,7 @@ func (m pagerModel) statusBarView(b *strings.Builder) { // Empty space padding := max(0, - m.general.width- + m.common.width- ansi.PrintableRuneWidth(logo)- ansi.PrintableRuneWidth(statusIndicator)- ansi.PrintableRuneWidth(note)- @@ -449,7 +449,7 @@ func (m pagerModel) setNoteView(b *strings.Builder) { func (m pagerModel) helpView() (s string) { memoOrStash := "m set memo" - if m.general.authStatus == authOK && m.currentDocument.markdownType == LocalDoc { + if m.common.authStatus == authOK && m.currentDocument.markdownType == LocalDoc { memoOrStash = "s stash this document" } @@ -481,11 +481,11 @@ func (m pagerModel) helpView() (s string) { s = indent(s, 2) // Fill up empty cells with spaces for background coloring - if m.general.width > 0 { + if m.common.width > 0 { lines := strings.Split(s, "\n") for i := 0; i < len(lines); i++ { l := runewidth.StringWidth(lines[i]) - n := max(m.general.width-l, 0) + n := max(m.common.width-l, 0) lines[i] += strings.Repeat(" ", n) } @@ -518,13 +518,13 @@ func glamourRender(m pagerModel, markdown string) (string, error) { // initialize glamour var gs glamour.TermRendererOption - if m.general.cfg.GlamourStyle == "auto" { + if m.common.cfg.GlamourStyle == "auto" { gs = glamour.WithAutoStyle() } else { - gs = glamour.WithStylePath(m.general.cfg.GlamourStyle) + gs = glamour.WithStylePath(m.common.cfg.GlamourStyle) } - width := max(0, min(int(m.general.cfg.GlamourMaxWidth), m.viewport.Width)) + width := max(0, min(int(m.common.cfg.GlamourMaxWidth), m.viewport.Width)) r, err := glamour.NewTermRenderer( gs, glamour.WithWordWrap(width), diff --git a/ui/stash.go b/ui/stash.go index 2d8e26b..a3546b4 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -14,7 +14,7 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/charm" - "github.com/charmbracelet/charm/ui/common" + lib "github.com/charmbracelet/charm/ui/common" "github.com/muesli/reflow/ansi" te "github.com/muesli/termenv" "github.com/sahilm/fuzzy" @@ -29,7 +29,7 @@ const ( ) var ( - stashTextInputPromptStyle styleFunc = newFgStyle(common.YellowGreen) + stashTextInputPromptStyle styleFunc = newFgStyle(lib.YellowGreen) dividerDot string = darkGrayFg(" • ") dividerBar string = darkGrayFg(" │ ") offlineHeaderNote string = darkGrayFg("(Offline)") @@ -109,7 +109,7 @@ const ( ) type stashModel struct { - general *general + common *commonModel err error spinner spinner.Model noteInput textinput.Model @@ -149,15 +149,15 @@ type stashModel struct { } func (m stashModel) localOnly() bool { - return m.general.cfg.localOnly() + return m.common.cfg.localOnly() } func (m stashModel) stashedOnly() bool { - return m.general.cfg.stashedOnly() + return m.common.cfg.stashedOnly() } func (m stashModel) loadingDone() bool { - return m.loaded.Equals(m.general.cfg.DocumentTypes.Difference(ConvertedDoc)) + return m.loaded.Equals(m.common.cfg.DocumentTypes.Difference(ConvertedDoc)) } func (m stashModel) hasSection(key sectionKey) bool { @@ -192,12 +192,12 @@ func (m *stashModel) setCursor(i int) { // Returns whether or not we're online. That is, when "local-only" mode is // disabled and we've authenticated successfully. func (m stashModel) online() bool { - return !m.localOnly() && m.general.authStatus == authOK + return !m.localOnly() && m.common.authStatus == authOK } func (m *stashModel) setSize(width, height int) { - m.general.width = width - m.general.height = height + m.common.width = width + m.common.height = height m.noteInput.Width = width - stashViewHorizontalPadding*2 - ansi.PrintableRuneWidth(m.noteInput.Prompt) m.filterInput.Width = width - stashViewHorizontalPadding*2 - ansi.PrintableRuneWidth(m.filterInput.Prompt) @@ -230,7 +230,7 @@ func (m stashModel) shouldUpdateFilter() bool { func (m *stashModel) updatePagination() { _, helpHeight := m.helpView() - availableHeight := m.general.height - + availableHeight := m.common.height - stashViewTopPadding - helpHeight - stashViewBottomPadding @@ -345,7 +345,7 @@ func (m *stashModel) openMarkdown(md *markdown) tea.Cmd { if md.markdownType == LocalDoc { cmd = loadLocalMarkdown(md) } else { - cmd = loadRemoteMarkdown(m.general.cc, md) + cmd = loadRemoteMarkdown(m.common.cc, md) } return tea.Batch(cmd, spinner.Tick) @@ -412,32 +412,32 @@ func (m *stashModel) moveCursorDown() { // INIT -func newStashModel(general *general) stashModel { +func newStashModel(common *commonModel) stashModel { sp := spinner.NewModel() sp.Spinner = spinner.Line - sp.ForegroundColor = common.SpinnerColor.String() + sp.ForegroundColor = lib.SpinnerColor.String() sp.HideFor = time.Millisecond * 50 sp.MinimumLifetime = time.Millisecond * 180 sp.Start() ni := textinput.NewModel() ni.Prompt = stashTextInputPromptStyle("Memo: ") - ni.CursorColor = common.Fuschia.String() + ni.CursorColor = lib.Fuschia.String() ni.CharLimit = noteCharacterLimit ni.Focus() si := textinput.NewModel() si.Prompt = stashTextInputPromptStyle("Filter: ") - si.CursorColor = common.Fuschia.String() + si.CursorColor = lib.Fuschia.String() si.CharLimit = noteCharacterLimit si.Focus() var s []section - if general.cfg.localOnly() { + if common.cfg.localOnly() { s = []section{ sections[localSection], } - } else if general.cfg.stashedOnly() { + } else if common.cfg.stashedOnly() { s = []section{ sections[stashedSection], sections[newsSection], @@ -460,7 +460,7 @@ func newStashModel(general *general) stashModel { } m := stashModel{ - general: general, + common: common, spinner: sp, noteInput: ni, filterInput: si, @@ -548,7 +548,7 @@ func (m stashModel) update(msg tea.Msg) (stashModel, tea.Cmd) { case spinner.TickMsg: loading := !m.loadingDone() - stashing := m.general.isStashing() + stashing := m.common.isStashing() openingDocument := m.viewState == stashStateLoadingDocument spinnerVisible := m.spinner.Visible() @@ -726,7 +726,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd { break } - if _, alreadyStashed := m.general.filesStashed[md.localID]; alreadyStashed { + if _, alreadyStashed := m.common.filesStashed[md.localID]; alreadyStashed { cmds = append(cmds, m.newStatusMessage("Already stashed")) break } @@ -739,9 +739,9 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd { } // Checks passed; perform the stash - m.general.filesStashed[md.localID] = struct{}{} - m.general.filesStashing[md.localID] = struct{}{} - cmds = append(cmds, stashDocument(m.general.cc, *md)) + m.common.filesStashed[md.localID] = struct{}{} + m.common.filesStashing[md.localID] = struct{}{} + cmds = append(cmds, stashDocument(m.common.cc, *md)) if m.loadingDone() && !m.spinner.Visible() { m.spinner.Start() @@ -826,7 +826,7 @@ func (m *stashModel) handleDeleteConfirmation(msg tea.Msg) tea.Cmd { } // Remove from the things-we-stashed-this-session set - delete(m.general.filesStashed, md.localID) + delete(m.common.filesStashed, md.localID) // Delete optimistically and remove the stashed item before // we've received a success response. @@ -841,7 +841,7 @@ func (m *stashModel) handleDeleteConfirmation(msg tea.Msg) tea.Cmd { m.selectionState = selectionIdle m.updatePagination() - return deleteStashedItem(m.general.cc, smd.ID) + return deleteStashedItem(m.common.cc, smd.ID) default: // Any other keys cancels deletion @@ -927,7 +927,7 @@ func (m *stashModel) handleNoteInput(msg tea.Msg) tea.Cmd { // Set new note md := m.selectedMarkdown() newNote := m.noteInput.Value() - cmd := saveDocumentNote(m.general.cc, md.ID, newNote) + cmd := saveDocumentNote(m.common.cc, md.ID, newNote) md.Note = newNote m.noteInput.Reset() m.selectionState = selectionIdle @@ -981,7 +981,7 @@ func (m stashModel) view() string { var logoOrFilter string if m.showStatusMessage { const gutter = 3 - logoOrFilter = greenFg(truncate(m.statusMessage, m.general.width-gutter)) + logoOrFilter = greenFg(truncate(m.statusMessage, m.common.width-gutter)) } else if m.isFiltering() { logoOrFilter = m.filterInput.View() } else { @@ -995,7 +995,7 @@ func (m stashModel) view() string { // We need to fill any empty height with newlines so the footer reaches // the bottom. - availHeight := m.general.height - + availHeight := m.common.height - stashViewTopPadding - populatedViewHeight - helpHeight - @@ -1008,9 +1008,9 @@ func (m stashModel) view() string { // If the dot pagination is wider than the width of the window // switch to the arabic paginator. - if ansi.PrintableRuneWidth(pagination) > m.general.width-stashViewHorizontalPadding { + if ansi.PrintableRuneWidth(pagination) > m.common.width-stashViewHorizontalPadding { m.paginator().Type = paginator.Arabic - pagination = common.Subtle(m.paginator().View()) + pagination = lib.Subtle(m.paginator().View()) } // We could also look at m.stashFullyLoaded and add an indicator @@ -1036,7 +1036,7 @@ func glowLogoView(text string) string { return te.String(text). Bold(). Foreground(glowLogoTextColor). - Background(common.Fuschia.Color()). + Background(lib.Fuschia.Color()). String() } @@ -1069,14 +1069,14 @@ func (m stashModel) headerView() string { if m.loadingDone() && len(m.markdowns) == 0 { var maybeOffline string - if m.general.authStatus == authFailed { + if m.common.authStatus == authFailed { maybeOffline = " " + offlineHeaderNote } if m.stashedOnly() { - return common.Subtle("Can’t load stash") + maybeOffline + return lib.Subtle("Can’t load stash") + maybeOffline } - return common.Subtle("No markdown files found") + maybeOffline + return lib.Subtle("No markdown files found") + maybeOffline } // Tabs @@ -1110,7 +1110,7 @@ func (m stashModel) headerView() string { } s := strings.Join(sections, dividerBar) - if m.general.authStatus == authFailed { + if m.common.authStatus == authFailed { s += dividerDot + offlineHeaderNote } @@ -1140,7 +1140,7 @@ func (m stashModel) populatedView() string { f("Looking for local files...") } case stashedSection: - if m.general.authStatus == authFailed { + if m.common.authStatus == authFailed { f("Can't load your stash. Are you offline?") } else if m.loadingDone() { f("Nothing stashed yet.") @@ -1148,7 +1148,7 @@ func (m stashModel) populatedView() string { f("Loading your stash...") } case newsSection: - if m.general.authStatus == authFailed { + if m.common.authStatus == authFailed { f("Can't load news. Are you offline?") } else if m.loadingDone() { f("No stashed files found.") diff --git a/ui/stashhelp.go b/ui/stashhelp.go index 243ef15..567b2a1 100644 --- a/ui/stashhelp.go +++ b/ui/stashhelp.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/charmbracelet/charm/ui/common" + lib "github.com/charmbracelet/charm/ui/common" "github.com/muesli/reflow/ansi" ) @@ -195,14 +195,14 @@ func (m stashModel) miniHelpView(entries ...string) string { } var ( - truncationChar = common.Subtle("…") + truncationChar = lib.Subtle("…") truncationWidth = ansi.PrintableRuneWidth(truncationChar) ) var ( next string leftGutter = " " - maxWidth = m.general.width - + maxWidth = m.common.width - stashViewHorizontalPadding - truncationWidth - ansi.PrintableRuneWidth(leftGutter) diff --git a/ui/stashitem.go b/ui/stashitem.go index 03d4c5d..65c2bba 100644 --- a/ui/stashitem.go +++ b/ui/stashitem.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "github.com/charmbracelet/charm/ui/common" + lib "github.com/charmbracelet/charm/ui/common" rw "github.com/mattn/go-runewidth" "github.com/muesli/termenv" "github.com/sahilm/fuzzy" @@ -19,7 +19,7 @@ const ( func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { var ( - truncateTo = m.general.width - stashViewHorizontalPadding*2 + truncateTo = m.common.width - stashViewHorizontalPadding*2 gutter string title = md.Note date = md.relativeTime() @@ -70,7 +70,7 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { gutter = dullFuchsiaFg(verticalLine) icon = dullFuchsiaFg(icon) if m.filterState == filterApplied || singleFilteredItem { - s := termenv.Style{}.Foreground(common.Fuschia.Color()) + s := termenv.Style{}.Foreground(lib.Fuschia.Color()) title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline()) } else { title = fuchsiaFg(title) @@ -87,7 +87,7 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { title = dimIndigoFg(title) date = dimSubtleIndigoFg(date) } else { - s := termenv.Style{}.Foreground(common.Indigo.Color()) + s := termenv.Style{}.Foreground(lib.Indigo.Color()) title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline()) date = subtleIndigoFg(date) } @@ -105,7 +105,7 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { if title == noMemoTitle { title = brightGrayFg(title) } else { - s := termenv.Style{}.Foreground(common.NewColorPair("#dddddd", "#1a1a1a").Color()) + s := termenv.Style{}.Foreground(lib.NewColorPair("#dddddd", "#1a1a1a").Color()) title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline()) } gutter = " " diff --git a/ui/styles.go b/ui/styles.go index ea86835..6afc101 100644 --- a/ui/styles.go +++ b/ui/styles.go @@ -1,7 +1,7 @@ package ui import ( - "github.com/charmbracelet/charm/ui/common" + lib "github.com/charmbracelet/charm/ui/common" te "github.com/muesli/termenv" ) @@ -12,39 +12,39 @@ const ( ) var ( - normalFg = newFgStyle(common.NewColorPair("#dddddd", "#1a1a1a")) - dimNormalFg = newFgStyle(common.NewColorPair("#777777", "#A49FA5")) + normalFg = newFgStyle(lib.NewColorPair("#dddddd", "#1a1a1a")) + dimNormalFg = newFgStyle(lib.NewColorPair("#777777", "#A49FA5")) - brightGrayFg = newFgStyle(common.NewColorPair("#979797", "#847A85")) - dimBrightGrayFg = newFgStyle(common.NewColorPair("#4D4D4D", "#C2B8C2")) + brightGrayFg = newFgStyle(lib.NewColorPair("#979797", "#847A85")) + dimBrightGrayFg = newFgStyle(lib.NewColorPair("#4D4D4D", "#C2B8C2")) - grayFg = newFgStyle(common.NewColorPair("#626262", "#909090")) - midGrayFg = newFgStyle(common.NewColorPair("#4A4A4A", "#B2B2B2")) - darkGrayFg = newFgStyle(common.NewColorPair("#3C3C3C", "#DDDADA")) + grayFg = newFgStyle(lib.NewColorPair("#626262", "#909090")) + midGrayFg = newFgStyle(lib.NewColorPair("#4A4A4A", "#B2B2B2")) + darkGrayFg = newFgStyle(lib.NewColorPair("#3C3C3C", "#DDDADA")) - greenFg = newFgStyle(common.NewColorPair("#04B575", "#04B575")) - dimGreenFg = newFgStyle(common.NewColorPair("#0B5137", "#72D2B0")) + greenFg = newFgStyle(lib.NewColorPair("#04B575", "#04B575")) + dimGreenFg = newFgStyle(lib.NewColorPair("#0B5137", "#72D2B0")) - fuchsiaFg = newFgStyle(common.Fuschia) - dimFuchsiaFg = newFgStyle(common.NewColorPair("#99519E", "#F1A8FF")) + fuchsiaFg = newFgStyle(lib.Fuschia) + dimFuchsiaFg = newFgStyle(lib.NewColorPair("#99519E", "#F1A8FF")) - dullFuchsiaFg = newFgStyle(common.NewColorPair("#AD58B4", "#F793FF")) - dimDullFuchsiaFg = newFgStyle(common.NewColorPair("#6B3A6F", "#F6C9FF")) + dullFuchsiaFg = newFgStyle(lib.NewColorPair("#AD58B4", "#F793FF")) + dimDullFuchsiaFg = newFgStyle(lib.NewColorPair("#6B3A6F", "#F6C9FF")) - indigoFg = newFgStyle(common.Indigo) - dimIndigoFg = newFgStyle(common.NewColorPair("#494690", "#9498FF")) + indigoFg = newFgStyle(lib.Indigo) + dimIndigoFg = newFgStyle(lib.NewColorPair("#494690", "#9498FF")) - subtleIndigoFg = newFgStyle(common.NewColorPair("#514DC1", "#7D79F6")) - dimSubtleIndigoFg = newFgStyle(common.NewColorPair("#383584", "#BBBDFF")) + subtleIndigoFg = newFgStyle(lib.NewColorPair("#514DC1", "#7D79F6")) + dimSubtleIndigoFg = newFgStyle(lib.NewColorPair("#383584", "#BBBDFF")) - yellowFg = newFgStyle(common.YellowGreen) // renders light green on light backgrounds - dullYellowFg = newFgStyle(common.NewColorPair("#9BA92F", "#6BCB94")) // renders light green on light backgrounds - redFg = newFgStyle(common.Red) - faintRedFg = newFgStyle(common.FaintRed) + yellowFg = newFgStyle(lib.YellowGreen) // renders light green on light backgrounds + dullYellowFg = newFgStyle(lib.NewColorPair("#9BA92F", "#6BCB94")) // renders light green on light backgrounds + redFg = newFgStyle(lib.Red) + faintRedFg = newFgStyle(lib.FaintRed) ) // Returns a termenv style with foreground and background options. -func newStyle(fg, bg common.ColorPair, bold bool) func(string) string { +func newStyle(fg, bg lib.ColorPair, bold bool) func(string) string { s := te.Style{}.Foreground(fg.Color()).Background(bg.Color()) if bold { s = s.Bold() @@ -53,6 +53,6 @@ func newStyle(fg, bg common.ColorPair, bold bool) func(string) string { } // Returns a new termenv style with background options only. -func newFgStyle(c common.ColorPair) styleFunc { +func newFgStyle(c lib.ColorPair) styleFunc { return te.Style{}.Foreground(c.Color()).Styled } diff --git a/ui/ui.go b/ui/ui.go index 3fb71c6..29a1608 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -15,6 +15,7 @@ import ( "github.com/charmbracelet/charm" "github.com/charmbracelet/charm/keygen" "github.com/charmbracelet/charm/ui/common" + lib "github.com/charmbracelet/charm/ui/common" "github.com/charmbracelet/glow/utils" runewidth "github.com/mattn/go-runewidth" "github.com/muesli/gitcha" @@ -29,7 +30,7 @@ const ( var ( config Config - glowLogoTextColor = common.Color("#ECFD65") + glowLogoTextColor = lib.Color("#ECFD65") // True if we're logging to a file, in which case we'll log more stuff. debug = false @@ -124,8 +125,8 @@ const ( keygenFinished ) -// General stuff we'll need to access in all models. -type general struct { +// Common stuff we'll need to access in all models. +type commonModel struct { cfg Config cc *charm.Client cwd string @@ -142,12 +143,12 @@ type general struct { filesStashing map[ksuid.KSUID]struct{} } -func (g general) isStashing() bool { - return len(g.filesStashing) > 0 +func (c commonModel) isStashing() bool { + return len(c.filesStashing) > 0 } type model struct { - general *general + common *commonModel state state keygenState keygenState fatalErr error @@ -193,7 +194,7 @@ func newModel(cfg Config) tea.Model { cfg.DocumentTypes.Add(LocalDoc, StashedDoc, ConvertedDoc, NewsDoc) } - general := general{ + common := commonModel{ cfg: cfg, authStatus: authConnecting, filesStashed: make(map[ksuid.KSUID]struct{}), @@ -201,17 +202,17 @@ func newModel(cfg Config) tea.Model { } return model{ - general: &general, + common: &common, state: stateShowStash, keygenState: keygenUnstarted, - pager: newPagerModel(&general), - stash: newStashModel(&general), + pager: newPagerModel(&common), + stash: newStashModel(&common), } } func (m model) Init() tea.Cmd { var cmds []tea.Cmd - d := m.general.cfg.DocumentTypes + d := m.common.cfg.DocumentTypes if d.Contains(StashedDoc) || d.Contains(NewsDoc) { cmds = append(cmds, @@ -314,14 +315,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Window size is received when starting up and on every resize case tea.WindowSizeMsg: - m.general.width = msg.Width - m.general.height = msg.Height + m.common.width = msg.Width + m.common.height = msg.Height m.stash.setSize(msg.Width, msg.Height) m.pager.setSize(msg.Width, msg.Height) case initLocalFileSearchMsg: m.localFileFinder = msg.ch - m.general.cwd = msg.cwd + m.common.cwd = msg.cwd cmds = append(cmds, findNextLocalFile(m)) case sshAuthErrMsg: @@ -330,7 +331,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, generateSSHKeys) } else { // The keygen ran but things still didn't work and we can't auth - m.general.authStatus = authFailed + m.common.authStatus = authFailed m.stash.err = errors.New("SSH authentication failed; we tried ssh-agent, loading keys from disk, and generating SSH keys") if debug { log.Println("entering offline mode;", m.stash.err) @@ -342,7 +343,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case keygenFailedMsg: // Keygen failed. That sucks. - m.general.authStatus = authFailed + m.common.authStatus = authFailed m.stash.err = errors.New("could not authenticate; could not generate SSH keys") if debug { log.Println("entering offline mode;", m.stash.err) @@ -359,12 +360,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, newCharmClient) case newCharmClientMsg: - m.general.cc = msg - m.general.authStatus = authOK + m.common.cc = msg + m.common.authStatus = authOK cmds = append(cmds, loadStash(m.stash), loadNews(m.stash)) case stashLoadErrMsg: - m.general.authStatus = authFailed + m.common.authStatus = authFailed case fetchedMarkdownMsg: // We've loaded a markdown file's contents for rendering @@ -392,7 +393,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd case foundLocalFileMsg: - newMd := localFileToMarkdown(m.general.cwd, gitcha.SearchResult(msg)) + newMd := localFileToMarkdown(m.common.cwd, gitcha.SearchResult(msg)) m.stash.addMarkdowns(newMd) if m.stash.isFiltering() { newMd.buildFilterValue() @@ -406,8 +407,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Common handling that should happen regardless of application state md := markdown(msg) m.stash.addMarkdowns(&md) - m.general.filesStashed[msg.localID] = struct{}{} - delete(m.general.filesStashing, md.localID) + m.common.filesStashed[msg.localID] = struct{}{} + delete(m.common.filesStashing, md.localID) if m.stash.isFiltering() { cmds = append(cmds, filterMarkdowns(m.stash)) @@ -415,8 +416,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case stashFailMsg: // Common handling that should happen regardless of application state - delete(m.general.filesStashed, msg.markdown.localID) - delete(m.general.filesStashing, msg.markdown.localID) + delete(m.common.filesStashed, msg.markdown.localID) + delete(m.common.filesStashing, msg.markdown.localID) case filteredMarkdownMsg: if m.state == stateShowDocument { @@ -464,8 +465,8 @@ func errorView(err error, fatal bool) string { } s := fmt.Sprintf("%s\n\n%v\n\n%s", te.String(" ERROR "). - Foreground(common.Cream.Color()). - Background(common.Red.Color()). + Foreground(lib.Cream.Color()). + Background(lib.Red.Color()). String(), err, common.Subtle(exitMsg), @@ -486,7 +487,7 @@ func findLocalFiles(m model) tea.Cmd { } var ignore []string - if !m.general.cfg.ShowAllFiles { + if !m.common.cfg.ShowAllFiles { ignore = ignorePatterns(m) } @@ -542,14 +543,14 @@ func newCharmClient() tea.Msg { func loadStash(m stashModel) tea.Cmd { return func() tea.Msg { - if m.general.cc == nil { + if m.common.cc == nil { err := errors.New("no charm client") if debug { log.Println("error loading stash:", err) } return stashLoadErrMsg{err} } - stash, err := m.general.cc.GetStash(m.serverPage) + stash, err := m.common.cc.GetStash(m.serverPage) if err != nil { if debug { if _, ok := err.(charm.ErrAuthFailed); ok { @@ -569,14 +570,14 @@ func loadStash(m stashModel) tea.Cmd { func loadNews(m stashModel) tea.Cmd { return func() tea.Msg { - if m.general.cc == nil { + if m.common.cc == nil { err := errors.New("no charm client") if debug { log.Println("error loading news:", err) } return newsLoadErrMsg{err} } - news, err := m.general.cc.GetNews(1) // just fetch the first page + news, err := m.common.cc.GetNews(1) // just fetch the first page if err != nil { if debug { log.Println("error loading news:", err)