Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
fix(utils): Resolve bgColor before pager starts
Browse files Browse the repository at this point in the history
So far we have started the pager and then got background color glamour
style from enviorment.

If enviorment value is not set it defaults to auto. Which in turn uses
termenv to resolve background color using some terminal escape code
sequences. The problem with this is that doing this when a pager like
less is running, just doesn't work and leaves less in a broken state.

To fix this we are now checking the background color manually and before
we start the pager.

Issue #636
  • Loading branch information
zemzale committed Mar 11, 2021
1 parent b192000 commit da87c2e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 41 deletions.
3 changes: 2 additions & 1 deletion commands/issue/view/issue_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
}
}

f.IO.ResolveBackgroundColor()
err = f.IO.StartPager()
if err != nil {
return err
Expand Down Expand Up @@ -154,7 +155,7 @@ func printTTYIssuePreview(opts *ViewOpts) error {

// Description
if opts.Issue.Description != "" {
opts.Issue.Description, _ = utils.RenderMarkdown(opts.Issue.Description, opts.GlamourStyle)
opts.Issue.Description, _ = utils.RenderMarkdown(opts.Issue.Description, opts.IO.BackgroundColor())
fmt.Fprintln(opts.IO.StdOut, opts.Issue.Description)
}

Expand Down
3 changes: 2 additions & 1 deletion commands/mr/view/mr_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
}
}

f.IO.ResolveBackgroundColor()
if err := f.IO.StartPager(); err != nil {
return err
}
Expand Down Expand Up @@ -140,7 +141,7 @@ func printTTYMRPreview(opts *ViewOpts, mr *gitlab.MergeRequest, notes []*gitlab.

// Description
if mr.Description != "" {
mr.Description, _ = utils.RenderMarkdown(mr.Description, glamourStyle)
mr.Description, _ = utils.RenderMarkdown(mr.Description, opts.IO.BackgroundColor())
fmt.Fprintln(out, mr.Description)
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/mattn/go-runewidth v0.0.10
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/mitchellh/go-homedir v1.1.0
github.com/muesli/termenv v0.6.0
github.com/otiai10/copy v1.5.0
github.com/pkg/errors v0.9.1
github.com/rivo/tview v0.0.0-20210117162420-745e4ceeb711
Expand Down
Loading

0 comments on commit da87c2e

Please sign in to comment.