Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

width calculation logic has the tacit assumption that no confiig file exists #666

Open
csabahenk opened this issue Dec 21, 2024 · 0 comments · May be fixed by #667
Open

width calculation logic has the tacit assumption that no confiig file exists #666

csabahenk opened this issue Dec 21, 2024 · 0 comments · May be fixed by #667

Comments

@csabahenk
Copy link

csabahenk commented Dec 21, 2024

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):

glow/main.go

Lines 180 to 192 in 7b3bfac

if isTerminal && width == 0 {
w, _, err := term.GetSize(int(os.Stdout.Fd()))
if err == nil {
width = uint(w)
}
if width > 120 {
width = 120
}
}
if width == 0 {
width = 80
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant