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)
| 300 | // formatCond builds the 5-line current/forecast condition block. |
| 301 | // prefix is " " for current condition, "│" for forecast blocks inside the box. |
| 302 | func (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 { |
no test coverage detected