mirror of
https://github.com/charmbracelet/glow
synced 2024-09-29 20:54:38 +00:00
chore: fmt & lint issues
This commit is contained in:
parent
60d98a01e5
commit
4dd3ba1d3c
2
.github/workflows/goreleaser.yml
vendored
2
.github/workflows/goreleaser.yml
vendored
|
@ -21,3 +21,5 @@ jobs:
|
||||||
nfpm_gpg_key: ${{ secrets.NFPM_GPG_KEY }}
|
nfpm_gpg_key: ${{ secrets.NFPM_GPG_KEY }}
|
||||||
nfpm_passphrase: ${{ secrets.NFPM_PASSPHRASE }}
|
nfpm_passphrase: ${{ secrets.NFPM_PASSPHRASE }}
|
||||||
snapcraft_token: ${{ secrets.SNAPCRAFT_TOKEN }}
|
snapcraft_token: ${{ secrets.SNAPCRAFT_TOKEN }}
|
||||||
|
|
||||||
|
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
|
||||||
|
|
|
@ -10,3 +10,5 @@ variables:
|
||||||
maintainer: "Christian Muehlhaeuser <muesli@charm.sh>"
|
maintainer: "Christian Muehlhaeuser <muesli@charm.sh>"
|
||||||
brew_commit_author_name: "Christian Muehlhaeuser"
|
brew_commit_author_name: "Christian Muehlhaeuser"
|
||||||
brew_commit_author_email: "muesli@charm.sh"
|
brew_commit_author_email: "muesli@charm.sh"
|
||||||
|
|
||||||
|
# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
gap "github.com/muesli/go-app-paths"
|
gap "github.com/muesli/go-app-paths"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -54,7 +54,7 @@ var configCmd = &cobra.Command{
|
||||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||||
// File doesn't exist yet, create all necessary directories and
|
// File doesn't exist yet, create all necessary directories and
|
||||||
// write the default config file
|
// write the default config file
|
||||||
if err := os.MkdirAll(filepath.Dir(configFile), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ func findGitHubREADME(s string) (*source, error) {
|
||||||
v := u
|
v := u
|
||||||
v.Path += "/master/" + r
|
v.Path += "/master/" + r
|
||||||
|
|
||||||
|
// nolint:bodyclose
|
||||||
|
// it is closed on the caller
|
||||||
resp, err := http.Get(v.String())
|
resp, err := http.Get(v.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -32,6 +32,8 @@ func findGitLabREADME(s string) (*source, error) {
|
||||||
v := u
|
v := u
|
||||||
v.Path += "/raw/master/" + r
|
v.Path += "/raw/master/" + r
|
||||||
|
|
||||||
|
// nolint:bodyclose
|
||||||
|
// it is closed on the caller
|
||||||
resp, err := http.Get(v.String())
|
resp, err := http.Get(v.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
19
main.go
19
main.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -24,7 +23,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = ""
|
// Version as provided by goreleaser.
|
||||||
|
Version = ""
|
||||||
|
// CommitSHA as provided by goreleaser.
|
||||||
CommitSHA = ""
|
CommitSHA = ""
|
||||||
|
|
||||||
readmeNames = []string{"README.md", "README"}
|
readmeNames = []string{"README.md", "README"}
|
||||||
|
@ -87,6 +88,7 @@ func sourceFromArg(arg string) (*source, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close() //nolint:errcheck
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
|
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
@ -198,12 +200,11 @@ func execute(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
} else if yes {
|
} else if yes {
|
||||||
src := &source{reader: os.Stdin}
|
src := &source{reader: os.Stdin}
|
||||||
defer src.reader.Close()
|
defer src.reader.Close() //nolint:errcheck
|
||||||
return executeCLI(cmd, src, os.Stdout)
|
return executeCLI(cmd, src, os.Stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
|
|
||||||
// TUI running on cwd
|
// TUI running on cwd
|
||||||
case 0:
|
case 0:
|
||||||
return runTUI("", false)
|
return runTUI("", false)
|
||||||
|
@ -239,12 +240,12 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer src.reader.Close()
|
defer src.reader.Close() //nolint:errcheck
|
||||||
return executeCLI(cmd, src, w)
|
return executeCLI(cmd, src, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
||||||
b, err := ioutil.ReadAll(src.reader)
|
b, err := io.ReadAll(src.reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -301,7 +302,7 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
pa := strings.Split(pagerCmd, " ")
|
pa := strings.Split(pagerCmd, " ")
|
||||||
c := exec.Command(pa[0], pa[1:]...)
|
c := exec.Command(pa[0], pa[1:]...) // nolint:gosec
|
||||||
c.Stdin = strings.NewReader(content)
|
c.Stdin = strings.NewReader(content)
|
||||||
c.Stdout = os.Stdout
|
c.Stdout = os.Stdout
|
||||||
return c.Run()
|
return c.Run()
|
||||||
|
@ -324,7 +325,7 @@ func runTUI(workingDirectory string, stashedOnly bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close() //nolint:errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.WorkingDirectory = workingDirectory
|
cfg.WorkingDirectory = workingDirectory
|
||||||
|
@ -375,7 +376,7 @@ func init() {
|
||||||
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)")
|
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)")
|
||||||
rootCmd.Flags().BoolVarP(&localOnly, "local", "l", false, "show local files only; no network (TUI-mode only)")
|
rootCmd.Flags().BoolVarP(&localOnly, "local", "l", false, "show local files only; no network (TUI-mode only)")
|
||||||
rootCmd.Flags().BoolVarP(&mouse, "mouse", "m", false, "enable mouse wheel (TUI-mode only)")
|
rootCmd.Flags().BoolVarP(&mouse, "mouse", "m", false, "enable mouse wheel (TUI-mode only)")
|
||||||
rootCmd.Flags().MarkHidden("mouse")
|
_ = rootCmd.Flags().MarkHidden("mouse")
|
||||||
|
|
||||||
// Config bindings
|
// Config bindings
|
||||||
_ = viper.BindPFlag("style", rootCmd.Flags().Lookup("style"))
|
_ = viper.BindPFlag("style", rootCmd.Flags().Lookup("style"))
|
||||||
|
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -42,8 +42,8 @@ var (
|
||||||
return fmt.Errorf("bad filename")
|
return fmt.Errorf("bad filename")
|
||||||
}
|
}
|
||||||
|
|
||||||
defer f.Close()
|
defer f.Close() //nolint:errcheck
|
||||||
b, err := ioutil.ReadAll(f)
|
b, err := io.ReadAll(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error reading file")
|
return fmt.Errorf("error reading file")
|
||||||
}
|
}
|
||||||
|
|
4
style.go
4
style.go
|
@ -1,8 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import . "github.com/charmbracelet/lipgloss" //nolint:revive
|
||||||
. "github.com/charmbracelet/lipgloss"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
keyword = NewStyle().
|
keyword = NewStyle().
|
||||||
|
|
|
@ -21,10 +21,6 @@ type Config struct {
|
||||||
GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" default:"true"`
|
GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" default:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) showLocalFiles() bool {
|
|
||||||
return c.DocumentTypes.Contains(LocalDoc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c Config) localOnly() bool {
|
func (c Config) localOnly() bool {
|
||||||
return c.DocumentTypes.Equals(NewDocTypeSet(LocalDoc))
|
return c.DocumentTypes.Equals(NewDocTypeSet(LocalDoc))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build !windows
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build !darwin
|
||||||
// +build !darwin
|
// +build !darwin
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
6
ui/keys.go
Normal file
6
ui/keys.go
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package ui
|
||||||
|
|
||||||
|
const (
|
||||||
|
keyEnter = "enter"
|
||||||
|
keyEsc = "esc"
|
||||||
|
)
|
|
@ -168,8 +168,7 @@ func wrapMarkdowns(t DocType, md []*charm.Markdown) (m []*markdown) {
|
||||||
// Return the time in a human-readable format relative to the current time.
|
// Return the time in a human-readable format relative to the current time.
|
||||||
func relativeTime(then time.Time) string {
|
func relativeTime(then time.Time) string {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
ago := now.Sub(then)
|
if ago := now.Sub(then); ago < time.Minute {
|
||||||
if ago < time.Minute {
|
|
||||||
return "just now"
|
return "just now"
|
||||||
} else if ago < humanize.Week {
|
} else if ago < humanize.Week {
|
||||||
return humanize.CustomRelTime(then, now, "ago", "from now", magnitudes)
|
return humanize.CustomRelTime(then, now, "ago", "from now", magnitudes)
|
||||||
|
|
19
ui/pager.go
19
ui/pager.go
|
@ -98,8 +98,10 @@ var (
|
||||||
Foreground(fuschia)
|
Foreground(fuschia)
|
||||||
)
|
)
|
||||||
|
|
||||||
type contentRenderedMsg string
|
type (
|
||||||
type noteSavedMsg *charm.Markdown
|
contentRenderedMsg string
|
||||||
|
noteSavedMsg *charm.Markdown
|
||||||
|
)
|
||||||
|
|
||||||
type pagerState int
|
type pagerState int
|
||||||
|
|
||||||
|
@ -227,10 +229,10 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case pagerStateSetNote:
|
case pagerStateSetNote:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "esc":
|
case keyEsc:
|
||||||
m.state = pagerStateBrowse
|
m.state = pagerStateBrowse
|
||||||
return m, nil
|
return m, nil
|
||||||
case "enter":
|
case keyEnter:
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
if m.textInput.Value() != m.currentDocument.Note { // don't update if the note didn't change
|
if m.textInput.Value() != m.currentDocument.Note { // don't update if the note didn't change
|
||||||
m.currentDocument.Note = m.textInput.Value() // update optimistically
|
m.currentDocument.Note = m.textInput.Value() // update optimistically
|
||||||
|
@ -242,7 +244,7 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "q", "esc":
|
case "q", keyEsc:
|
||||||
if m.state != pagerStateBrowse {
|
if m.state != pagerStateBrowse {
|
||||||
m.state = pagerStateBrowse
|
m.state = pagerStateBrowse
|
||||||
return m, nil
|
return m, nil
|
||||||
|
@ -416,10 +418,9 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
|
||||||
maxPercent float64 = 1.0
|
maxPercent float64 = 1.0
|
||||||
percentToStringMagnitude float64 = 100.0
|
percentToStringMagnitude float64 = 100.0
|
||||||
)
|
)
|
||||||
var (
|
|
||||||
isStashed bool = m.currentDocument.docType == StashedDoc || m.currentDocument.docType == ConvertedDoc
|
isStashed := m.currentDocument.docType == StashedDoc || m.currentDocument.docType == ConvertedDoc
|
||||||
showStatusMessage bool = m.state == pagerStateStatusMessage
|
showStatusMessage := m.state == pagerStateStatusMessage
|
||||||
)
|
|
||||||
|
|
||||||
// Logo
|
// Logo
|
||||||
logo := glowLogoView(" Glow ")
|
logo := glowLogoView(" Glow ")
|
||||||
|
|
40
ui/stash.go
40
ui/stash.go
|
@ -3,8 +3,8 @@ package ui
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -55,9 +55,11 @@ var (
|
||||||
|
|
||||||
// MSG
|
// MSG
|
||||||
|
|
||||||
type deletedStashedItemMsg int
|
type (
|
||||||
type filteredMarkdownMsg []*markdown
|
deletedStashedItemMsg int
|
||||||
type fetchedMarkdownMsg *markdown
|
filteredMarkdownMsg []*markdown
|
||||||
|
fetchedMarkdownMsg *markdown
|
||||||
|
)
|
||||||
|
|
||||||
type markdownFetchFailedMsg struct {
|
type markdownFetchFailedMsg struct {
|
||||||
err error
|
err error
|
||||||
|
@ -218,15 +220,6 @@ func (m stashModel) loadingDone() bool {
|
||||||
return m.loaded.Equals(m.common.cfg.DocumentTypes.Difference(ConvertedDoc))
|
return m.loaded.Equals(m.common.cfg.DocumentTypes.Difference(ConvertedDoc))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m stashModel) hasSection(key sectionKey) bool {
|
|
||||||
for _, v := range m.sections {
|
|
||||||
if key == v.key {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m stashModel) currentSection() *section {
|
func (m stashModel) currentSection() *section {
|
||||||
return &m.sections[m.sectionIndex]
|
return &m.sections[m.sectionIndex]
|
||||||
}
|
}
|
||||||
|
@ -741,7 +734,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
|
||||||
m.setCursor(m.paginator().ItemsOnPage(numDocs) - 1)
|
m.setCursor(m.paginator().ItemsOnPage(numDocs) - 1)
|
||||||
|
|
||||||
// Clear filter (if applicable)
|
// Clear filter (if applicable)
|
||||||
case "esc":
|
case keyEsc:
|
||||||
if m.filterApplied() {
|
if m.filterApplied() {
|
||||||
m.resetFiltering()
|
m.resetFiltering()
|
||||||
}
|
}
|
||||||
|
@ -769,7 +762,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
|
||||||
m.updatePagination()
|
m.updatePagination()
|
||||||
|
|
||||||
// Open document
|
// Open document
|
||||||
case "enter":
|
case keyEnter:
|
||||||
m.hideStatusMessage()
|
m.hideStatusMessage()
|
||||||
|
|
||||||
if numDocs == 0 {
|
if numDocs == 0 {
|
||||||
|
@ -971,7 +964,6 @@ func (m *stashModel) handleDeleteConfirmation(msg tea.Msg) tea.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch md.docType {
|
switch md.docType {
|
||||||
|
|
||||||
case ConvertedDoc:
|
case ConvertedDoc:
|
||||||
// If the document was stashed in this session, convert it
|
// If the document was stashed in this session, convert it
|
||||||
// back to it's original document type
|
// back to it's original document type
|
||||||
|
@ -989,9 +981,7 @@ func (m *stashModel) handleDeleteConfirmation(msg tea.Msg) tea.Cmd {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.filteredMarkdowns = mds
|
m.filteredMarkdowns = mds
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1021,10 +1011,10 @@ func (m *stashModel) handleFiltering(msg tea.Msg) tea.Cmd {
|
||||||
// Handle keys
|
// Handle keys
|
||||||
if msg, ok := msg.(tea.KeyMsg); ok {
|
if msg, ok := msg.(tea.KeyMsg); ok {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "esc":
|
case keyEsc:
|
||||||
// Cancel filtering
|
// Cancel filtering
|
||||||
m.resetFiltering()
|
m.resetFiltering()
|
||||||
case "enter", "tab", "shift+tab", "ctrl+k", "up", "ctrl+j", "down":
|
case keyEnter, "tab", "shift+tab", "ctrl+k", "up", "ctrl+j", "down":
|
||||||
m.hideStatusMessage()
|
m.hideStatusMessage()
|
||||||
|
|
||||||
if len(m.markdowns) == 0 {
|
if len(m.markdowns) == 0 {
|
||||||
|
@ -1087,11 +1077,11 @@ func (m *stashModel) handleNoteInput(msg tea.Msg) tea.Cmd {
|
||||||
|
|
||||||
if msg, ok := msg.(tea.KeyMsg); ok {
|
if msg, ok := msg.(tea.KeyMsg); ok {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "esc":
|
case keyEsc:
|
||||||
// Cancel note
|
// Cancel note
|
||||||
m.noteInput.Reset()
|
m.noteInput.Reset()
|
||||||
m.selectionState = selectionIdle
|
m.selectionState = selectionIdle
|
||||||
case "enter":
|
case keyEnter:
|
||||||
// Set new note
|
// Set new note
|
||||||
md := m.selectedMarkdown()
|
md := m.selectedMarkdown()
|
||||||
|
|
||||||
|
@ -1235,7 +1225,7 @@ func (m stashModel) headerView() string {
|
||||||
stashedCount := m.countMarkdowns(StashedDoc) + m.countMarkdowns(ConvertedDoc)
|
stashedCount := m.countMarkdowns(StashedDoc) + m.countMarkdowns(ConvertedDoc)
|
||||||
newsCount := m.countMarkdowns(NewsDoc)
|
newsCount := m.countMarkdowns(NewsDoc)
|
||||||
|
|
||||||
var sections []string
|
var sections []string //nolint:prealloc
|
||||||
|
|
||||||
// Filter results
|
// Filter results
|
||||||
if m.filterState == filtering {
|
if m.filterState == filtering {
|
||||||
|
@ -1384,7 +1374,7 @@ func loadRemoteMarkdown(cc *charm.Client, md *markdown) tea.Cmd {
|
||||||
newMD, err := fetchMarkdown(cc, md.ID, md.docType)
|
newMD, err := fetchMarkdown(cc, md.ID, md.docType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if debug {
|
if debug {
|
||||||
log.Printf("error loading %s markdown (ID %s, Note: '%s'): %v", md.docType, md.ID, md.Note, err)
|
log.Printf("error loading %s markdown (ID %d, Note: '%s'): %v", md.docType, md.ID, md.Note, err)
|
||||||
}
|
}
|
||||||
return markdownFetchFailedMsg{
|
return markdownFetchFailedMsg{
|
||||||
err: err,
|
err: err,
|
||||||
|
@ -1406,7 +1396,7 @@ func loadLocalMarkdown(md *markdown) tea.Cmd {
|
||||||
return errMsg{errors.New("could not load file: missing path")}
|
return errMsg{errors.New("could not load file: missing path")}
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(md.localPath)
|
data, err := os.ReadFile(md.localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if debug {
|
if debug {
|
||||||
log.Println("error reading local markdown:", err)
|
log.Println("error reading local markdown:", err)
|
||||||
|
|
|
@ -240,11 +240,9 @@ func (m stashModel) miniHelpView(entries ...string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m stashModel) fullHelpView(groups ...[]string) string {
|
func (m stashModel) fullHelpView(groups ...[]string) string {
|
||||||
var (
|
var tallestCol int
|
||||||
columns []helpColumn
|
columns := make([]helpColumn, 0, len(groups))
|
||||||
tallestCol int
|
renderedCols := make([][]string, 0, len(groups)) // final rows grouped by column
|
||||||
renderedCols [][]string // final rows grouped by column
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get key/value pairs
|
// Get key/value pairs
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import . "github.com/charmbracelet/lipgloss" //nolint: revive
|
||||||
. "github.com/charmbracelet/lipgloss"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Colors.
|
// Colors.
|
||||||
var (
|
var (
|
||||||
|
@ -33,6 +31,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ulimately, we'll transition to named styles.
|
// Ulimately, we'll transition to named styles.
|
||||||
|
// nolint:deadcode,unused,varcheck
|
||||||
var (
|
var (
|
||||||
normalFg = NewStyle().Foreground(normal).Render
|
normalFg = NewStyle().Foreground(normal).Render
|
||||||
dimNormalFg = NewStyle().Foreground(normalDim).Render
|
dimNormalFg = NewStyle().Foreground(normalDim).Render
|
||||||
|
|
12
ui/ui.go
12
ui/ui.go
|
@ -3,7 +3,6 @@ package ui
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -13,7 +12,6 @@ import (
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/charm"
|
"github.com/charmbracelet/charm"
|
||||||
"github.com/charmbracelet/charm/keygen"
|
"github.com/charmbracelet/charm/keygen"
|
||||||
"github.com/charmbracelet/charm/ui/keygen"
|
|
||||||
"github.com/charmbracelet/glow/utils"
|
"github.com/charmbracelet/glow/utils"
|
||||||
"github.com/muesli/gitcha"
|
"github.com/muesli/gitcha"
|
||||||
te "github.com/muesli/termenv"
|
te "github.com/muesli/termenv"
|
||||||
|
@ -57,9 +55,9 @@ func NewProgram(cfg Config) *tea.Program {
|
||||||
}
|
}
|
||||||
config = cfg
|
config = cfg
|
||||||
opts := []tea.ProgramOption{tea.WithAltScreen()}
|
opts := []tea.ProgramOption{tea.WithAltScreen()}
|
||||||
if cfg.EnableMouse {
|
if cfg.EnableMouse {
|
||||||
opts = append(opts, tea.WithMouseCellMotion())
|
opts = append(opts, tea.WithMouseCellMotion())
|
||||||
}
|
}
|
||||||
return tea.NewProgram(newModel(cfg), opts...)
|
return tea.NewProgram(newModel(cfg), opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +75,7 @@ type (
|
||||||
ch chan gitcha.SearchResult
|
ch chan gitcha.SearchResult
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
foundLocalFileMsg gitcha.SearchResult
|
foundLocalFileMsg gitcha.SearchResult
|
||||||
localFileSearchFinished struct{}
|
localFileSearchFinished struct{}
|
||||||
|
@ -662,9 +661,8 @@ func stashDocument(cc *charm.Client, md markdown) tea.Cmd {
|
||||||
// then we'll stash it anyway.
|
// then we'll stash it anyway.
|
||||||
if len(md.Body) == 0 {
|
if len(md.Body) == 0 {
|
||||||
switch md.docType {
|
switch md.docType {
|
||||||
|
|
||||||
case LocalDoc:
|
case LocalDoc:
|
||||||
data, err := ioutil.ReadFile(md.localPath)
|
data, err := os.ReadFile(md.localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if debug {
|
if debug {
|
||||||
log.Println("error loading document body for stashing:", err)
|
log.Println("error loading document body for stashing:", err)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RemoveFrontmatter removes the front matter header of a markdown file.
|
||||||
func RemoveFrontmatter(content []byte) []byte {
|
func RemoveFrontmatter(content []byte) []byte {
|
||||||
if frontmatterBoundaries := detectFrontmatter(content); frontmatterBoundaries[0] == 0 {
|
if frontmatterBoundaries := detectFrontmatter(content); frontmatterBoundaries[0] == 0 {
|
||||||
return content[frontmatterBoundaries[1]:]
|
return content[frontmatterBoundaries[1]:]
|
||||||
|
|
Loading…
Reference in a new issue