MCPcopy Index your code
hub / github.com/git-bug/git-bug / bugsDefaultFormatter

Function bugsDefaultFormatter

commands/bug/bug.go:215–270  ·  view source on GitHub ↗
(env *execenv.Env, excerpts []*cache.BugExcerpt)

Source from the content-addressed store, hash-verified

213}
214
215func bugsDefaultFormatter(env *execenv.Env, excerpts []*cache.BugExcerpt) error {
216 width := env.Out.Width()
217 widthId := entity.HumanIdLength
218 widthStatus := len("closed")
219 widthComment := 6
220
221 widthRemaining := width -
222 widthId - 1 -
223 widthStatus - 1 -
224 widthComment - 1
225
226 widthTitle := int(float32(widthRemaining-3) * 0.7)
227 if widthTitle < 0 {
228 widthTitle = 0
229 }
230
231 widthRemaining = widthRemaining - widthTitle - 3 - 2
232 widthAuthor := widthRemaining
233
234 for _, b := range excerpts {
235 author, err := env.Backend.Identities().ResolveExcerpt(b.AuthorId)
236 if err != nil {
237 return err
238 }
239
240 var labelsTxt strings.Builder
241 for _, l := range b.Labels {
242 lc256 := l.Color().Term256()
243 labelsTxt.WriteString(lc256.Escape())
244 labelsTxt.WriteString(" ◼")
245 labelsTxt.WriteString(lc256.Unescape())
246 }
247
248 // truncate + pad if needed
249 labelsFmt := text.TruncateMax(labelsTxt.String(), 10)
250 titleFmt := text.LeftPadMaxLine(strings.TrimSpace(b.Title), widthTitle-text.Len(labelsFmt), 0)
251 authorFmt := text.LeftPadMaxLine(author.DisplayName(), widthAuthor, 0)
252
253 comments := fmt.Sprintf("%3d 💬", b.LenComments-1)
254 if b.LenComments-1 <= 0 {
255 comments = ""
256 }
257 if b.LenComments-1 > 999 {
258 comments = " ∞ 💬"
259 }
260
261 env.Out.Printf("%s\t%s\t%s %s %s\n",
262 colors.Cyan(b.Id().Human()),
263 colors.Yellow(b.Status),
264 titleFmt+labelsFmt,
265 colors.Magenta(authorFmt),
266 comments,
267 )
268 }
269 return nil
270}
271
272func bugsPlainFormatter(env *execenv.Env, excerpts []*cache.BugExcerpt) error {

Callers 1

runBugFunction · 0.85

Calls 13

ResolveExcerptMethod · 0.80
IdentitiesMethod · 0.80
Term256Method · 0.80
EscapeMethod · 0.80
UnescapeMethod · 0.80
WidthMethod · 0.65
ColorMethod · 0.65
StringMethod · 0.65
DisplayNameMethod · 0.65
PrintfMethod · 0.65
IdMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected