MCPcopy
hub / github.com/chubin/wttr.in / formatCond

Method formatCond

internal/renderer/v1/format.go:302–403  ·  view source on GitHub ↗

formatCond builds the 5-line current/forecast condition block. prefix is " " for current condition, "│" for forecast blocks inside the box.

(prefix string, c cond, isCurrent bool, opts *options.Options)

Source from the content-addressed store, hash-verified

300// formatCond builds the 5-line current/forecast condition block.
301// prefix is " " for current condition, "│" for forecast blocks inside the box.
302func (r *V1Renderer) formatCond(prefix string, c cond, isCurrent bool, opts *options.Options) []string {
303 if opts == nil {
304 opts = &options.Options{}
305 }
306 if prefix == "" {
307 prefix = " "
308 }
309
310 var ret []string
311
312 // Get icon
313 icon := getIcon("iconUnknown")
314 if i, ok := codes()[c.WeatherCode]; ok {
315 icon = i
316 }
317
318 // Inverse color adjustments
319 if opts.InvertedColors {
320 for i := range icon {
321 icon[i] = strings.ReplaceAll(icon[i], "38;5;226", "38;5;94")
322 icon[i] = strings.ReplaceAll(icon[i], "38;5;250", "38;5;243")
323 icon[i] = strings.ReplaceAll(icon[i], "38;5;21", "38;5;18")
324 icon[i] = strings.ReplaceAll(icon[i], "38;5;255", "38;5;245")
325 icon[i] = strings.ReplaceAll(icon[i], "38;5;111", "38;5;63")
326 icon[i] = strings.ReplaceAll(icon[i], "38;5;251", "38;5;238")
327 }
328 }
329
330 // Safe description handling
331 desc := "Unknown"
332 if len(c.WeatherDesc) > 0 {
333 desc = c.WeatherDesc[0].Value
334 }
335
336 descWidth := 15
337 if !isCurrent {
338 // Pad/truncate description to descWidth characters
339 if r.rightToLeft {
340 for displaywidth.String(desc) < descWidth {
341 desc = " " + desc
342 }
343 for displaywidth.String(desc) > descWidth {
344 _, size := utf8.DecodeLastRuneInString(desc)
345 desc = desc[:len(desc)-size]
346 }
347 } else {
348 for displaywidth.String(desc) < descWidth {
349 desc += " "
350 }
351 for displaywidth.String(desc) > descWidth {
352 _, size := utf8.DecodeLastRuneInString(desc)
353 desc = desc[:len(desc)-size]
354 }
355 }
356 }
357
358 if isCurrent {
359 if r.rightToLeft && displaywidth.String(desc) < descWidth {

Callers 2

RenderMethod · 0.95
printDayMethod · 0.95

Calls 7

formatTempMethod · 0.95
formatWindMethod · 0.95
formatVisibilityMethod · 0.95
formatRainMethod · 0.95
getIconFunction · 0.85
codesFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected