Example #1
0
func trimStr2Runes(s string, w int) []rune {
	if w <= 0 {
		return []rune{}
	}
	sw := rw.StringWidth(s)
	if sw > w {
		return []rune(rw.Truncate(s, w, dot))
	}
	return str2runes(s) //[]rune(rw.Truncate(s, w, ""))
}
Example #2
0
// TrimStrIfAppropriate trim string to "s[:-1] + …"
// if string > width otherwise return string
func TrimStrIfAppropriate(s string, w int) string {
	if w <= 0 {
		return ""
	}

	sw := rw.StringWidth(s)
	if sw > w {
		return rw.Truncate(s, w, dot)
	}

	return s
}
Example #3
0
func (c *emojiConfig) formatCond(cur []string, cond iface.Cond, current bool) (ret []string) {
	codes := map[iface.WeatherCode][]string{
		iface.CodeUnknown:             {"✨"},
		iface.CodeCloudy:              {"☁️"},
		iface.CodeFog:                 {"🌫"},
		iface.CodeHeavyRain:           {"🌧"},
		iface.CodeHeavyShowers:        {"🌧"},
		iface.CodeHeavySnow:           {"❄️"},
		iface.CodeHeavySnowShowers:    {"❄️"},
		iface.CodeLightRain:           {"🌦"},
		iface.CodeLightShowers:        {"🌦"},
		iface.CodeLightSleet:          {"🌧"},
		iface.CodeLightSleetShowers:   {"🌧"},
		iface.CodeLightSnow:           {"🌨"},
		iface.CodeLightSnowShowers:    {"🌨"},
		iface.CodePartlyCloudy:        {"⛅️"},
		iface.CodeSunny:               {"☀️"},
		iface.CodeThunderyHeavyRain:   {"🌩"},
		iface.CodeThunderyShowers:     {"⛈"},
		iface.CodeThunderySnowShowers: {"⛈"},
		iface.CodeVeryCloudy:          {"☁️"},
	}

	icon, ok := codes[cond.Code]
	if !ok {
		log.Fatalln("emoji-frontend: The following weather code has no icon:", cond.Code)
	}

	desc := cond.Desc
	if !current {
		desc = runewidth.Truncate(runewidth.FillRight(desc, 13), 13, "…")
	}

	ret = append(ret, fmt.Sprintf("%v %v %v", cur[0], "", desc))
	ret = append(ret, fmt.Sprintf("%v %v %v", cur[1], icon[0], c.formatTemp(cond)))
	return
}