mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-21 07:34:18 +02:00
Crudely load local markdown files into the stash
This commit is contained in:
parent
71b9387e01
commit
e0bd2dd466
2 changed files with 40 additions and 1 deletions
2
go.mod
2
go.mod
|
|
@ -10,7 +10,7 @@ require (
|
|||
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
|
||||
github.com/mattn/go-runewidth v0.0.9
|
||||
github.com/meowgorithm/babyenv v1.2.1
|
||||
github.com/muesli/gitcha v0.0.0-20200714001838-c071c3c6c6e1 // indirect
|
||||
github.com/muesli/gitcha v0.0.0-20200714001838-c071c3c6c6e1
|
||||
github.com/muesli/termenv v0.5.3-0.20200625163851-04b5c30e4c04
|
||||
github.com/spf13/cobra v0.0.7
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
|
||||
|
|
|
|||
39
ui/stash.go
39
ui/stash.go
|
|
@ -2,7 +2,9 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -15,6 +17,7 @@ import (
|
|||
"github.com/charmbracelet/charm/ui/common"
|
||||
"github.com/dustin/go-humanize"
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/muesli/gitcha"
|
||||
te "github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
|
@ -32,6 +35,7 @@ type gotStashMsg []*charm.Markdown
|
|||
type gotNewsMsg []*charm.Markdown
|
||||
type fetchedMarkdownMsg *markdown
|
||||
type deletedStashedItemMsg int
|
||||
type fileWalkFinishedMsg []string
|
||||
|
||||
// MODEL
|
||||
|
||||
|
|
@ -42,6 +46,7 @@ type markdownType int
|
|||
const (
|
||||
userMarkdown markdownType = iota
|
||||
newsMarkdown
|
||||
localFile
|
||||
)
|
||||
|
||||
// markdown wraps charm.Markdown so we can differentiate between stashed items
|
||||
|
|
@ -171,6 +176,7 @@ func stashInit(cc *charm.Client) (stashModel, tea.Cmd) {
|
|||
}
|
||||
|
||||
return m, tea.Batch(
|
||||
loadLocalFiles,
|
||||
loadStash(m),
|
||||
loadNews(m),
|
||||
spinner.Tick(s),
|
||||
|
|
@ -187,6 +193,21 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
// We've received a list of local markdowns
|
||||
case fileWalkFinishedMsg:
|
||||
if len(msg) > 0 {
|
||||
now := time.Now()
|
||||
for _, mdPath := range msg {
|
||||
m.markdowns = append(m.markdowns, &markdown{
|
||||
markdownType: localFile,
|
||||
Markdown: &charm.Markdown{
|
||||
Note: mdPath,
|
||||
CreatedAt: &now,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Stash results have come in from the server
|
||||
case gotStashMsg:
|
||||
m.loading = false
|
||||
|
|
@ -518,6 +539,24 @@ func stashHelpView(m stashModel) string {
|
|||
|
||||
// CMD
|
||||
|
||||
func loadLocalFiles() tea.Msg {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return errMsg(err)
|
||||
}
|
||||
|
||||
// For now, wait to collect all the results before delivering them back
|
||||
var agg []string
|
||||
|
||||
ch := gitcha.FindFileFromList(cwd, []string{"*.md"})
|
||||
for v := range ch {
|
||||
log.Println("found file", v)
|
||||
agg = append(agg, v)
|
||||
}
|
||||
|
||||
return fileWalkFinishedMsg(agg)
|
||||
}
|
||||
|
||||
func loadStash(m stashModel) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
stash, err := m.cc.GetStash(m.page)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue