Description
Describe the bug
When glow is called by the user for the very first time (so that width is not given explicitly via -w
), glow output with will be inferred from the terminal width (as I suppose it's intended). However, subsequent repetitions of the invocation will have glow output width at 80.
Setup
glow between v2.0.0 and 7b3bfac (master as of writing this).
To Reproduce
Open a shell in a terminal so that its width is way below 80.
See the line widtths when glow output witdth is expilicty set to that of the terminal:
$ unbuffer glow -s notty -w $(stty size | awk '{print $2}') sample.md | \
ruby -ne 'puts $_.size' | sort | uniq
1
28
29
31
(Note: the width does not stricty adhere to the specified value - cf. issue #668 - but it's at least close to the speicified witdh.)
Expected behavior without using -w
:
$ unbuffer glow -s notty sample.md | ruby -ne 'puts $_.size' | sort | uniq
1
28
29
31
Actual behavior:
$ unbuffer glow -s notty sample.md | ruby -ne 'puts $_.size' | sort | uniq
1
88
89
Except for the case when the user runs this command as their very first invocation of glow - in that case we do get the expected output.
Additional context
The difference between very first invocation and subsequent ones is that upon that very first invocation glow deploys a basic configuration file. And the code that calculates the actual runtime witdth in validateOptions
behaves as if it were granted that no config file exists (which holds only for the very first invocation):
Lines 180 to 192 in 7b3bfac
width == 0
is used in the sense that width
is "pristine". However, after the deployment of the config file, which includes a setting of width
to 80, if -w
is not passed, the execution flow will arrive to this code block with width
already being 80. Ie. the pristine value is whatever what's been placed into config - a static value check cannot capture this condition.