X Tutup
Skip to content

Commit 232dc7b

Browse files
committed
change condition for single file, remove empty lines in single file mode
1 parent 8e86129 commit 232dc7b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

pkg/cmd/gist/view/view.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func viewRun(opts *ViewOptions) error {
8989
return err
9090
}
9191

92+
cs := opts.IO.ColorScheme()
93+
if gist.Description != "" && opts.Filename == "" {
94+
fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description))
95+
}
96+
9297
if opts.Filename != "" {
9398
gistFile, ok := gist.Files[opts.Filename]
9499
if !ok {
@@ -102,11 +107,6 @@ func viewRun(opts *ViewOptions) error {
102107

103108
showFilenames := len(gist.Files) > 1
104109

105-
cs := opts.IO.ColorScheme()
106-
if gist.Description != "" && showFilenames {
107-
fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description))
108-
}
109-
110110
outs := []string{} // to ensure consistent ordering
111111

112112
for filename, gistFile := range gist.Files {
@@ -122,7 +122,10 @@ func viewRun(opts *ViewOptions) error {
122122
content = rendered
123123
}
124124
}
125-
out += fmt.Sprintf("%s\n\n", content)
125+
out += fmt.Sprintf("%s", content)
126+
if opts.Filename == "" {
127+
out += fmt.Sprintf("\n\n")
128+
}
126129

127130
outs = append(outs, out)
128131
}

pkg/cmd/gist/view/view_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func Test_viewRun(t *testing.T) {
129129
},
130130
},
131131
},
132-
wantOut: "bwhiizzzbwhuiiizzzz\n\n",
132+
wantOut: "bwhiizzzbwhuiiizzzz",
133133
},
134134
{
135135
name: "filename selected, raw",
@@ -150,7 +150,7 @@ func Test_viewRun(t *testing.T) {
150150
},
151151
},
152152
},
153-
wantOut: "bwhiizzzbwhuiiizzzz\n\n",
153+
wantOut: "bwhiizzzbwhuiiizzzz",
154154
},
155155
{
156156
name: "multiple files, no description",

0 commit comments

Comments
 (0)
X Tutup