mirror of
https://github.com/charmbracelet/glow
synced 2024-06-29 06:24:21 +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_passphrase: ${{ secrets.NFPM_PASSPHRASE }}
|
||||
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>"
|
||||
brew_commit_author_name: "Christian Muehlhaeuser"
|
||||
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/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
gap "github.com/muesli/go-app-paths"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -54,7 +54,7 @@ var configCmd = &cobra.Command{
|
|||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
// File doesn't exist yet, create all necessary directories and
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ func findGitHubREADME(s string) (*source, error) {
|
|||
v := u
|
||||
v.Path += "/master/" + r
|
||||
|
||||
// nolint:bodyclose
|
||||
// it is closed on the caller
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -32,6 +32,8 @@ func findGitLabREADME(s string) (*source, error) {
|
|||
v := u
|
||||
v.Path += "/raw/master/" + r
|
||||
|
||||
// nolint:bodyclose
|
||||
// it is closed on the caller
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
19
main.go
19
main.go
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -24,7 +23,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Version = ""
|
||||
// Version as provided by goreleaser.
|
||||
Version = ""
|
||||
// CommitSHA as provided by goreleaser.
|
||||
CommitSHA = ""
|
||||
|
||||
readmeNames = []string{"README.md", "README"}
|
||||
|
@ -87,6 +88,7 @@ func sourceFromArg(arg string) (*source, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close() //nolint:errcheck
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("HTTP status %d", resp.StatusCode)
|
||||
}
|
||||
|
@ -198,12 +200,11 @@ func execute(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
} else if yes {
|
||||
src := &source{reader: os.Stdin}
|
||||
defer src.reader.Close()
|
||||
defer src.reader.Close() //nolint:errcheck
|
||||
return executeCLI(cmd, src, os.Stdout)
|
||||
}
|
||||
|
||||
switch len(args) {
|
||||
|
||||
// TUI running on cwd
|
||||
case 0:
|
||||
return runTUI("", false)
|
||||
|
@ -239,12 +240,12 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.reader.Close()
|
||||
defer src.reader.Close() //nolint:errcheck
|
||||
return executeCLI(cmd, src, w)
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -301,7 +302,7 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
|
|||
}
|
||||
|
||||
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.Stdout = os.Stdout
|
||||
return c.Run()
|
||||
|
@ -324,7 +325,7 @@ func runTUI(workingDirectory string, stashedOnly bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer f.Close() //nolint:errcheck
|
||||
}
|
||||
|
||||
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(&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().MarkHidden("mouse")
|
||||
_ = rootCmd.Flags().MarkHidden("mouse")
|
||||
|
||||
// Config bindings
|
||||
_ = viper.BindPFlag("style", rootCmd.Flags().Lookup("style"))
|
||||
|
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -42,8 +42,8 @@ var (
|
|||
return fmt.Errorf("bad filename")
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
b, err := ioutil.ReadAll(f)
|
||||
defer f.Close() //nolint:errcheck
|
||||
b, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading file")
|
||||
}
|
||||
|
|
4
style.go
4
style.go
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
import . "github.com/charmbracelet/lipgloss" //nolint:revive
|
||||
|
||||
var (
|
||||
keyword = NewStyle().
|
||||
|
|
|
@ -21,10 +21,6 @@ type Config struct {
|
|||
GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" default:"true"`
|
||||
}
|
||||
|
||||
func (c Config) showLocalFiles() bool {
|
||||
return c.DocumentTypes.Contains(LocalDoc)
|
||||
}
|
||||
|
||||
func (c Config) localOnly() bool {
|
||||
return c.DocumentTypes.Equals(NewDocTypeSet(LocalDoc))
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ui
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//go:build !darwin
|
||||
// +build !darwin
|
||||
|
||||
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.
|
||||
func relativeTime(then time.Time) string {
|
||||
now := time.Now()
|
||||
ago := now.Sub(then)
|
||||
if ago < time.Minute {
|
||||
if ago := now.Sub(then); ago < time.Minute {
|
||||
return "just now"
|
||||
} else if ago < humanize.Week {
|
||||
return humanize.CustomRelTime(then, now, "ago", "from now", magnitudes)
|
||||
|
|
19
ui/pager.go
19
ui/pager.go
|
@ -98,8 +98,10 @@ var (
|
|||
Foreground(fuschia)
|
||||
)
|
||||
|
||||
type contentRenderedMsg string
|
||||
type noteSavedMsg *charm.Markdown
|
||||
type (
|
||||
contentRenderedMsg string
|
||||
noteSavedMsg *charm.Markdown
|
||||
)
|
||||
|
||||
type pagerState int
|
||||
|
||||
|
@ -227,10 +229,10 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
switch m.state {
|
||||
case pagerStateSetNote:
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
case keyEsc:
|
||||
m.state = pagerStateBrowse
|
||||
return m, nil
|
||||
case "enter":
|
||||
case keyEnter:
|
||||
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
|
||||
|
@ -242,7 +244,7 @@ func (m pagerModel) update(msg tea.Msg) (pagerModel, tea.Cmd) {
|
|||
}
|
||||
default:
|
||||
switch msg.String() {
|
||||
case "q", "esc":
|
||||
case "q", keyEsc:
|
||||
if m.state != pagerStateBrowse {
|
||||
m.state = pagerStateBrowse
|
||||
return m, nil
|
||||
|
@ -416,10 +418,9 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
|
|||
maxPercent float64 = 1.0
|
||||
percentToStringMagnitude float64 = 100.0
|
||||
)
|
||||
var (
|
||||
isStashed bool = m.currentDocument.docType == StashedDoc || m.currentDocument.docType == ConvertedDoc
|
||||
showStatusMessage bool = m.state == pagerStateStatusMessage
|
||||
)
|
||||
|
||||
isStashed := m.currentDocument.docType == StashedDoc || m.currentDocument.docType == ConvertedDoc
|
||||
showStatusMessage := m.state == pagerStateStatusMessage
|
||||
|
||||
// Logo
|
||||
logo := glowLogoView(" Glow ")
|
||||
|
|
40
ui/stash.go
40
ui/stash.go
|
@ -3,8 +3,8 @@ package ui
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -55,9 +55,11 @@ var (
|
|||
|
||||
// MSG
|
||||
|
||||
type deletedStashedItemMsg int
|
||||
type filteredMarkdownMsg []*markdown
|
||||
type fetchedMarkdownMsg *markdown
|
||||
type (
|
||||
deletedStashedItemMsg int
|
||||
filteredMarkdownMsg []*markdown
|
||||
fetchedMarkdownMsg *markdown
|
||||
)
|
||||
|
||||
type markdownFetchFailedMsg struct {
|
||||
err error
|
||||
|
@ -218,15 +220,6 @@ func (m stashModel) loadingDone() bool {
|
|||
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 {
|
||||
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)
|
||||
|
||||
// Clear filter (if applicable)
|
||||
case "esc":
|
||||
case keyEsc:
|
||||
if m.filterApplied() {
|
||||
m.resetFiltering()
|
||||
}
|
||||
|
@ -769,7 +762,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd {
|
|||
m.updatePagination()
|
||||
|
||||
// Open document
|
||||
case "enter":
|
||||
case keyEnter:
|
||||
m.hideStatusMessage()
|
||||
|
||||
if numDocs == 0 {
|
||||
|
@ -971,7 +964,6 @@ func (m *stashModel) handleDeleteConfirmation(msg tea.Msg) tea.Cmd {
|
|||
}
|
||||
|
||||
switch md.docType {
|
||||
|
||||
case ConvertedDoc:
|
||||
// If the document was stashed in this session, convert it
|
||||
// back to it's original document type
|
||||
|
@ -989,9 +981,7 @@ func (m *stashModel) handleDeleteConfirmation(msg tea.Msg) tea.Cmd {
|
|||
if err == nil {
|
||||
m.filteredMarkdowns = mds
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -1021,10 +1011,10 @@ func (m *stashModel) handleFiltering(msg tea.Msg) tea.Cmd {
|
|||
// Handle keys
|
||||
if msg, ok := msg.(tea.KeyMsg); ok {
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
case keyEsc:
|
||||
// Cancel filtering
|
||||
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()
|
||||
|
||||
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 {
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
case keyEsc:
|
||||
// Cancel note
|
||||
m.noteInput.Reset()
|
||||
m.selectionState = selectionIdle
|
||||
case "enter":
|
||||
case keyEnter:
|
||||
// Set new note
|
||||
md := m.selectedMarkdown()
|
||||
|
||||
|
@ -1235,7 +1225,7 @@ func (m stashModel) headerView() string {
|
|||
stashedCount := m.countMarkdowns(StashedDoc) + m.countMarkdowns(ConvertedDoc)
|
||||
newsCount := m.countMarkdowns(NewsDoc)
|
||||
|
||||
var sections []string
|
||||
var sections []string //nolint:prealloc
|
||||
|
||||
// Filter results
|
||||
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)
|
||||
if err != nil {
|
||||
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{
|
||||
err: err,
|
||||
|
@ -1406,7 +1396,7 @@ func loadLocalMarkdown(md *markdown) tea.Cmd {
|
|||
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 debug {
|
||||
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 {
|
||||
var (
|
||||
columns []helpColumn
|
||||
tallestCol int
|
||||
renderedCols [][]string // final rows grouped by column
|
||||
)
|
||||
var tallestCol int
|
||||
columns := make([]helpColumn, 0, len(groups))
|
||||
renderedCols := make([][]string, 0, len(groups)) // final rows grouped by column
|
||||
|
||||
// Get key/value pairs
|
||||
for _, g := range groups {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
. "github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
import . "github.com/charmbracelet/lipgloss" //nolint: revive
|
||||
|
||||
// Colors.
|
||||
var (
|
||||
|
@ -33,6 +31,7 @@ var (
|
|||
)
|
||||
|
||||
// Ulimately, we'll transition to named styles.
|
||||
// nolint:deadcode,unused,varcheck
|
||||
var (
|
||||
normalFg = NewStyle().Foreground(normal).Render
|
||||
dimNormalFg = NewStyle().Foreground(normalDim).Render
|
||||
|
|
12
ui/ui.go
12
ui/ui.go
|
@ -3,7 +3,6 @@ package ui
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -13,7 +12,6 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/charm"
|
||||
"github.com/charmbracelet/charm/keygen"
|
||||
"github.com/charmbracelet/charm/ui/keygen"
|
||||
"github.com/charmbracelet/glow/utils"
|
||||
"github.com/muesli/gitcha"
|
||||
te "github.com/muesli/termenv"
|
||||
|
@ -57,9 +55,9 @@ func NewProgram(cfg Config) *tea.Program {
|
|||
}
|
||||
config = cfg
|
||||
opts := []tea.ProgramOption{tea.WithAltScreen()}
|
||||
if cfg.EnableMouse {
|
||||
opts = append(opts, tea.WithMouseCellMotion())
|
||||
}
|
||||
if cfg.EnableMouse {
|
||||
opts = append(opts, tea.WithMouseCellMotion())
|
||||
}
|
||||
return tea.NewProgram(newModel(cfg), opts...)
|
||||
}
|
||||
|
||||
|
@ -77,6 +75,7 @@ type (
|
|||
ch chan gitcha.SearchResult
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
foundLocalFileMsg gitcha.SearchResult
|
||||
localFileSearchFinished struct{}
|
||||
|
@ -662,9 +661,8 @@ func stashDocument(cc *charm.Client, md markdown) tea.Cmd {
|
|||
// then we'll stash it anyway.
|
||||
if len(md.Body) == 0 {
|
||||
switch md.docType {
|
||||
|
||||
case LocalDoc:
|
||||
data, err := ioutil.ReadFile(md.localPath)
|
||||
data, err := os.ReadFile(md.localPath)
|
||||
if err != nil {
|
||||
if debug {
|
||||
log.Println("error loading document body for stashing:", err)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
// RemoveFrontmatter removes the front matter header of a markdown file.
|
||||
func RemoveFrontmatter(content []byte) []byte {
|
||||
if frontmatterBoundaries := detectFrontmatter(content); frontmatterBoundaries[0] == 0 {
|
||||
return content[frontmatterBoundaries[1]:]
|
||||
|
|
Loading…
Reference in New Issue
Block a user