mirror of
https://github.com/charmbracelet/glow
synced 2024-12-13 13:42:34 +00:00
parent
247c707b25
commit
2d5bd3b799
3 changed files with 7 additions and 1 deletions
5
main.go
5
main.go
|
@ -36,6 +36,7 @@ var (
|
|||
style string
|
||||
width uint
|
||||
showAllFiles bool
|
||||
showLineNumbers bool
|
||||
preserveNewLines bool
|
||||
mouse bool
|
||||
|
||||
|
@ -324,6 +325,7 @@ func runTUI(workingDirectory string) error {
|
|||
cfg.WorkingDirectory = workingDirectory
|
||||
|
||||
cfg.ShowAllFiles = showAllFiles
|
||||
cfg.ShowLineNumbers = showLineNumbers
|
||||
cfg.GlamourMaxWidth = width
|
||||
cfg.GlamourStyle = style
|
||||
cfg.EnableMouse = mouse
|
||||
|
@ -368,6 +370,7 @@ func init() {
|
|||
rootCmd.Flags().StringVarP(&style, "style", "s", glamour.AutoStyle, "style name or JSON path")
|
||||
rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width")
|
||||
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)")
|
||||
rootCmd.Flags().BoolVarP(&showLineNumbers, "line-numbers", "l", false, "show line numbers (TUI-mode only)")
|
||||
rootCmd.Flags().BoolVarP(&preserveNewLines, "preserve-new-lines", "n", false, "preserve newlines in the output")
|
||||
rootCmd.Flags().BoolVarP(&mouse, "mouse", "m", false, "enable mouse wheel (TUI-mode only)")
|
||||
_ = rootCmd.Flags().MarkHidden("mouse")
|
||||
|
@ -378,6 +381,8 @@ func init() {
|
|||
_ = viper.BindPFlag("debug", rootCmd.Flags().Lookup("debug"))
|
||||
_ = viper.BindPFlag("mouse", rootCmd.Flags().Lookup("mouse"))
|
||||
_ = viper.BindPFlag("preserveNewLines", rootCmd.Flags().Lookup("preserve-new-lines"))
|
||||
_ = viper.BindPFlag("showLineNumbers", rootCmd.Flags().Lookup("line-numbers"))
|
||||
_ = viper.BindPFlag("showAllFiles", rootCmd.Flags().Lookup("all"))
|
||||
|
||||
viper.SetDefault("style", glamour.AutoStyle)
|
||||
viper.SetDefault("width", 0)
|
||||
|
|
|
@ -3,6 +3,7 @@ package ui
|
|||
// Config contains TUI-specific configuration.
|
||||
type Config struct {
|
||||
ShowAllFiles bool
|
||||
ShowLineNumbers bool
|
||||
Gopath string `env:"GOPATH"`
|
||||
HomeDir string `env:"HOME"`
|
||||
GlamourMaxWidth uint
|
||||
|
|
|
@ -436,7 +436,7 @@ func glamourRender(m pagerModel, markdown string) (string, error) {
|
|||
|
||||
var content strings.Builder
|
||||
for i, s := range lines {
|
||||
if isCode {
|
||||
if isCode || m.common.cfg.ShowLineNumbers {
|
||||
content.WriteString(lineNumberStyle(fmt.Sprintf("%"+fmt.Sprint(lineNumberWidth)+"d", i+1)))
|
||||
content.WriteString(trunc(s))
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue