mirror of
https://github.com/charmbracelet/glow
synced 2024-12-14 06:02:27 +00:00
Rename a function
This commit is contained in:
parent
25dd530fb7
commit
64da53ede6
2 changed files with 26 additions and 27 deletions
51
ui/stash.go
51
ui/stash.go
|
@ -1194,7 +1194,7 @@ func (m stashModel) populatedView() string {
|
||||||
// loadRemoteMarkdown is a command for loading markdown from the server.
|
// loadRemoteMarkdown is a command for loading markdown from the server.
|
||||||
func loadRemoteMarkdown(cc *charm.Client, md *markdown) tea.Cmd {
|
func loadRemoteMarkdown(cc *charm.Client, md *markdown) tea.Cmd {
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
newMD, err := loadMarkdownFromCharm(cc, md.ID, md.markdownType)
|
newMD, err := fetchMarkdown(cc, md.ID, md.markdownType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if debug {
|
if debug {
|
||||||
log.Printf("error loading %s markdown (ID %d, Note: '%s'): %v", md.markdownType, md.ID, md.Note, err)
|
log.Printf("error loading %s markdown (ID %d, Note: '%s'): %v", md.markdownType, md.ID, md.Note, err)
|
||||||
|
@ -1210,31 +1210,6 @@ func loadRemoteMarkdown(cc *charm.Client, md *markdown) tea.Cmd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadMarkdownFromCharm performs the actual I/O for loading markdown from the
|
|
||||||
// sever.
|
|
||||||
func loadMarkdownFromCharm(cc *charm.Client, id int, t DocType) (*markdown, error) {
|
|
||||||
var md *charm.Markdown
|
|
||||||
var err error
|
|
||||||
|
|
||||||
switch t {
|
|
||||||
case StashedDoc, ConvertedDoc:
|
|
||||||
md, err = cc.GetStashMarkdown(id)
|
|
||||||
case NewsDoc:
|
|
||||||
md, err = cc.GetNewsMarkdown(id)
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("unknown markdown type: %s", t)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &markdown{
|
|
||||||
markdownType: t,
|
|
||||||
Markdown: *md,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadLocalMarkdown(md *markdown) tea.Cmd {
|
func loadLocalMarkdown(md *markdown) tea.Cmd {
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
if md.markdownType != LocalDoc {
|
if md.markdownType != LocalDoc {
|
||||||
|
@ -1296,6 +1271,30 @@ func filterMarkdowns(m stashModel) tea.Cmd {
|
||||||
|
|
||||||
// ETC
|
// ETC
|
||||||
|
|
||||||
|
// fetchMarkdown performs the actual I/O for loading markdown from the sever.
|
||||||
|
func fetchMarkdown(cc *charm.Client, id int, t DocType) (*markdown, error) {
|
||||||
|
var md *charm.Markdown
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch t {
|
||||||
|
case StashedDoc, ConvertedDoc:
|
||||||
|
md, err = cc.GetStashMarkdown(id)
|
||||||
|
case NewsDoc:
|
||||||
|
md, err = cc.GetNewsMarkdown(id)
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("unknown markdown type: %s", t)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &markdown{
|
||||||
|
markdownType: t,
|
||||||
|
Markdown: *md,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Delete a markdown from a slice of markdowns.
|
// Delete a markdown from a slice of markdowns.
|
||||||
func deleteMarkdown(markdowns []*markdown, target *markdown) ([]*markdown, error) {
|
func deleteMarkdown(markdowns []*markdown, target *markdown) ([]*markdown, error) {
|
||||||
index := -1
|
index := -1
|
||||||
|
|
2
ui/ui.go
2
ui/ui.go
|
@ -658,7 +658,7 @@ func stashDocument(cc *charm.Client, md markdown) tea.Cmd {
|
||||||
md.Body = string(data)
|
md.Body = string(data)
|
||||||
|
|
||||||
case NewsDoc:
|
case NewsDoc:
|
||||||
newMD, err := loadMarkdownFromCharm(cc, md.ID, md.markdownType)
|
newMD, err := fetchMarkdown(cc, md.ID, md.markdownType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stashFailMsg{err, md}
|
return stashFailMsg{err, md}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue