mirror of
https://github.com/boolean-maybe/tiki
synced 2026-04-21 13:37:20 +00:00
refresh markdown viewer
This commit is contained in:
parent
16dd296b07
commit
6d65d07c10
3 changed files with 28 additions and 4 deletions
2
go.mod
2
go.mod
|
|
@ -3,7 +3,7 @@ module github.com/boolean-maybe/tiki
|
|||
go 1.25.0
|
||||
|
||||
require (
|
||||
github.com/boolean-maybe/navidown v0.4.14
|
||||
github.com/boolean-maybe/navidown v0.4.15
|
||||
github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7
|
||||
github.com/charmbracelet/bubbletea v1.3.10
|
||||
github.com/charmbracelet/huh v0.8.0
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -25,8 +25,8 @@ github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3v
|
|||
github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E=
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/boolean-maybe/navidown v0.4.14 h1:PMk/Sdz5OigAp20fZhUpFNNeTYMrJBokKnxwfYL/GI8=
|
||||
github.com/boolean-maybe/navidown v0.4.14/go.mod h1:uF4Z/5uTnEtC6ZWyfKRv5Qw8Nir1nfp4kUraggTRfrk=
|
||||
github.com/boolean-maybe/navidown v0.4.15 h1:xQqn7FUy1Eh9eHHNj2bMEBSk07lvkvMeORNtJHpYuzA=
|
||||
github.com/boolean-maybe/navidown v0.4.15/go.mod h1:uF4Z/5uTnEtC6ZWyfKRv5Qw8Nir1nfp4kUraggTRfrk=
|
||||
github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY=
|
||||
github.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
|
||||
github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7 h1:JFgG/xnwFfbezlUnFMJy0nusZvytYysV4SCS2cYbvws=
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ func Run(input InputSpec) error {
|
|||
case 'q':
|
||||
app.Stop()
|
||||
return nil
|
||||
case 'r':
|
||||
refreshContent(app, md, provider)
|
||||
return nil
|
||||
case 'e':
|
||||
srcPath := md.SourceFilePath()
|
||||
if srcPath == "" || strings.HasPrefix(srcPath, "http://") || strings.HasPrefix(srcPath, "https://") {
|
||||
|
|
@ -112,6 +115,27 @@ func Run(input InputSpec) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// refreshContent clears image/diagram caches, re-reads the current file from disk, and re-renders.
|
||||
func refreshContent(app *tview.Application, md *markdown.NavigableMarkdown, provider *loaders.FileHTTP) {
|
||||
srcPath := md.SourceFilePath()
|
||||
if srcPath == "" {
|
||||
return // stdin content — nothing to reload
|
||||
}
|
||||
|
||||
content, err := provider.FetchContent(nav.NavElement{URL: srcPath})
|
||||
if err != nil {
|
||||
content = markdown.FormatErrorContent(err)
|
||||
}
|
||||
|
||||
// one-shot before-draw to get the screen for Kitty image purge
|
||||
app.SetBeforeDrawFunc(func(screen tcell.Screen) bool {
|
||||
md.Viewer().InvalidateForDocument(screen)
|
||||
md.SetMarkdownWithSource(content, srcPath, false)
|
||||
app.SetBeforeDrawFunc(nil)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func loadInitialContent(input InputSpec, provider *loaders.FileHTTP) (string, string, error) {
|
||||
if input.Kind == InputStdin {
|
||||
content, err := io.ReadAll(os.Stdin)
|
||||
|
|
@ -191,7 +215,7 @@ func updateStatusBar(statusBar *tview.TextView, v *navtview.TextViewViewer) {
|
|||
} else {
|
||||
status += "[gray]▶[-]"
|
||||
}
|
||||
status += fmt.Sprintf(" | Scroll:[%s]j/k[-] Top/End:[%s]g/G[-] Edit:[%s]e[-] Quit:[%s]q[-]", keyColor, keyColor, keyColor, keyColor)
|
||||
status += fmt.Sprintf(" | Scroll:[%s]j/k[-] Top/End:[%s]g/G[-] Refresh:[%s]r[-] Edit:[%s]e[-] Quit:[%s]q[-]", keyColor, keyColor, keyColor, keyColor, keyColor)
|
||||
|
||||
statusBar.SetText(status)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue