glow icon indicating copy to clipboard operation
glow copied to clipboard

fix: allow config file to load showLineNumbers

Open prithvijj opened this issue 1 year ago • 0 comments

Changes

  • Added in a fix to allow the showLineNumbers config option to be loaded from the config file
  • Previously it seems unclear on how to setup the showLineNumbers key within the config, and while there was support added for configuring the showLineNumbers flag, it couldn't be read from the config file, since the validateOptions method would not retrieve the key from the config file
  • Hence changed it so that it does retrieve the showLineNumbers key from the config file, and use it as needed
  • Updated the README.md to also provide an example on how to setup both the keys

Testing Notes

Ran

go build
./glow config

# added in `preserveNewLines: true` and `showLineNumbers: true` key 

and for testing purposes to see if the config option was being read added in

func validateOptions(cmd *cobra.Command) error {
	// grab config values from Viper
	width = viper.GetUint("width")
	mouse = viper.GetBool("mouse")
	pager = viper.GetBool("pager")
	showAllFiles = viper.GetBool("all")
	preserveNewLines = viper.GetBool("preserveNewLines")

+	panic(fmt.Sprintf("preserveNewLines: %v, showLineNumbers: %v", preserveNewLines, showLineNumbers))

to showcase the configurations are being read

Previously: When preserveNewLines: true and showLineNumbers: true within the config, the panic output shows that preserveNewLines is being recognized, but showLineNumbers is not being recognized, which is unexpected

image

When ./glow -l is used, the panic output shows that the preserveNewLines is being recognized, and showLineNumbers is being recognized which is expected

image


After:

When preserveNewLines: true and showLineNumbers: true within the config, the panic output shows that preserveNewLines is being recognized and showLineNumbers is being recognized, which is expected image

When preserveNewLines: true and showLineNumbers: false within the config, the panic output shows that preserveNewLines is being recognized and showLineNumbers is being recognized, which is expected image

Removed the panic line used for testing purposes, ran go build; ./glow then navigated to the README.md to show that the line numbers are being shown, since the config has showLineNumbers: true image

Other Notes

Related to https://github.com/charmbracelet/glow/issues/652

  • [ ] Any tests that I can write?

prithvijj avatar Oct 16 '24 13:10 prithvijj