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

Fix(pager): Resolve background color before staring pager #650

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions commands/issue/view/issue_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ type ViewOpts struct {
CommentPageNumber int
CommentLimit int

Notes []*gitlab.Note
Issue *gitlab.Issue
GlamourStyle string
Notes []*gitlab.Note
Issue *gitlab.Issue

IO *iostreams.IOStreams
}
Expand Down Expand Up @@ -75,8 +74,6 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
return utils.OpenInBrowser(opts.Issue.WebURL, browser)
}

opts.GlamourStyle, _ = cfg.Get(baseRepo.RepoHost(), "glamour_style")

if opts.ShowComments {
l := &gitlab.ListIssueNotesOptions{
Sort: gitlab.String("asc"),
Expand All @@ -93,6 +90,8 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
}
}

glamourStyle, _ := cfg.Get(baseRepo.RepoHost(), "glamour_style")
f.IO.ResolveBackgroundColor(glamourStyle)
err = f.IO.StartPager()
if err != nil {
return err
Expand Down Expand Up @@ -154,7 +153,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 Expand Up @@ -195,7 +194,7 @@ func printTTYIssuePreview(opts *ViewOpts) error {
fmt.Fprintf(opts.IO.StdOut, " %s ", note.Body)
fmt.Fprintln(opts.IO.StdOut, c.Gray(createdAt))
} else {
body, _ := utils.RenderMarkdown(note.Body, opts.GlamourStyle)
body, _ := utils.RenderMarkdown(note.Body, opts.IO.BackgroundColor())
fmt.Fprint(opts.IO.StdOut, " commented ")
fmt.Fprintf(opts.IO.StdOut, c.Gray("%s\n"), createdAt)
fmt.Fprintln(opts.IO.StdOut, utils.Indent(body, " "))
Expand Down
11 changes: 6 additions & 5 deletions commands/mr/view/mr_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ func NewCmdView(f *cmdutils.Factory) *cobra.Command {
}
}

glamourStyle, _ := cfg.Get(baseRepo.RepoHost(), "glamour_style")
f.IO.ResolveBackgroundColor(glamourStyle)
if err := f.IO.StartPager(); err != nil {
return err
}
defer f.IO.StopPager()

if f.IO.IsOutputTTY() {
glamourStyle, _ := cfg.Get(baseRepo.RepoHost(), "glamour_style")
return printTTYMRPreview(opts, mr, notes, glamourStyle)
return printTTYMRPreview(opts, mr, notes)
}
return printRawMRPreview(opts, mr)
},
Expand Down Expand Up @@ -127,7 +128,7 @@ func mrState(c *iostreams.ColorPalette, mr *gitlab.MergeRequest) (mrState string
return mrState
}

func printTTYMRPreview(opts *ViewOpts, mr *gitlab.MergeRequest, notes []*gitlab.Note, glamourStyle string) error {
func printTTYMRPreview(opts *ViewOpts, mr *gitlab.MergeRequest, notes []*gitlab.Note) error {
c := opts.IO.Color()
out := opts.IO.StdOut
mrTimeAgo := utils.TimeToPrettyTimeAgo(*mr.CreatedAt)
Expand All @@ -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 Expand Up @@ -206,7 +207,7 @@ func printTTYMRPreview(opts *ViewOpts, mr *gitlab.MergeRequest, notes []*gitlab.
fmt.Fprintf(out, " %s ", note.Body)
fmt.Fprintln(out, c.Gray(createdAt))
} else {
body, _ := utils.RenderMarkdown(note.Body, glamourStyle)
body, _ := utils.RenderMarkdown(note.Body, opts.IO.BackgroundColor())
fmt.Fprint(out, " commented ")
fmt.Fprintf(out, c.Gray("%s\n"), createdAt)
fmt.Fprintln(out, utils.Indent(body, " "))
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