Skip to content

Commit

Permalink
feat: show line numbers configuration option
Browse files Browse the repository at this point in the history
closes #311
  • Loading branch information
caarlos0 committed Jul 11, 2024
1 parent 247c707 commit 2d5bd3b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
style string
width uint
showAllFiles bool
showLineNumbers bool
preserveNewLines bool
mouse bool

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2d5bd3b

Please sign in to comment.