-
Notifications
You must be signed in to change notification settings - Fork 532
/
markdownviewer.go
49 lines (39 loc) · 924 Bytes
/
markdownviewer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package markdownviewer
import (
"os"
"github.com/charmbracelet/glow/ui"
"golang.org/x/term"
)
// View starts the Markdown viewer at path that .md files are located at.
func View(path string) error {
conf, err := config(path)
if err != nil {
return err
}
// TODO: Enable bubbletea WithAltScreen and WithMouseCellMotion options when glow supports them
p := ui.NewProgram(conf)
_, err = p.Run()
return err
}
func config(path string) (ui.Config, error) {
var width uint
w, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
return ui.Config{}, err
}
width = uint(w)
if width > 120 {
width = 120
}
docTypes := ui.NewDocTypeSet()
docTypes.Add(ui.LocalDoc)
conf := ui.Config{
WorkingDirectory: path,
DocumentTypes: docTypes,
GlamourStyle: "auto",
HighPerformancePager: true,
GlamourEnabled: true,
GlamourMaxWidth: width,
}
return conf, nil
}