Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emoji icons for printing given a parameter #72

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions forecast/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,51 @@ func getIcon(iconStr string) (icon string, err error) {
return colorstring.Color("[" + color + "]" + icon), nil
}

func getEmojiIcon(iconStr string) (icon string, err error) {
color := "white"
// steralize the icon string name
iconStr = strings.Replace(strings.Replace(iconStr, "-", "", -1), "_", "", -1)

switch iconStr {
case "clear":
icon = "🔆"
case "clearday":
icon = "🔆"
case "clearnight":
icon = "🌙"
case "clouds":
icon = "☁️"
case "cloudy":
icon = "☁️"
case "cloudsnight":
icon = "☁️"
case "fog":
icon = "🌫️"
case "haze":
icon = "🌫️"
case "hazenight":
icon = "🌫️"
case "partlycloudyday":
icon = "⛅️"
case "partlycloudynight":
icon = "⛅️"
case "rain":
icon = "🌧"
case "sleet":
icon = "🌨"
case "snow":
icon = "🌨"
case "thunderstorm":
icon = "⛈"
case "tornado":
icon = "🌪"
case "wind":
icon = "💨"
}

return colorstring.Color("[" + color + "]" + "\n" + icon), nil
}

func getBearingDetails(degrees float64) string {
index := int(math.Mod((degrees+11.25)/22.5, 16))
return Directions[index]
Expand Down Expand Up @@ -212,11 +257,18 @@ func kmToMile(km float64) float64 {
}

// PrintCurrent pretty prints the current forecast data.
func PrintCurrent(forecast Forecast, geolocation geocode.Geocode, ignoreAlerts bool, hideIcon bool) error {
func PrintCurrent(forecast Forecast, geolocation geocode.Geocode, ignoreAlerts bool, hideIcon bool, emojiIcons bool) error {
andersfischernielsen marked this conversation as resolved.
Show resolved Hide resolved
unitsFormat := UnitFormats[forecast.Flags.Units]

if !hideIcon {
icon, err := getIcon(forecast.Currently.Icon)
var err error
var icon string

if emojiIcons {
icon, err = getEmojiIcon(forecast.Currently.Icon)
} else {
icon, err = getIcon(forecast.Currently.Icon)
}
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
days int
ignoreAlerts bool
hideIcon bool
emojiIcons bool
noForecast bool
jsonOut bool
server string
Expand Down Expand Up @@ -70,6 +71,7 @@ func main() {

p.FlagSet.BoolVar(&ignoreAlerts, "ignore-alerts", false, "Ignore alerts in weather output")
p.FlagSet.BoolVar(&hideIcon, "hide-icon", false, "Hide the weather icons from being output")
p.FlagSet.BoolVar(&emojiIcons, "use-emoji-icon", false, "Use emojis for weather icons")
p.FlagSet.BoolVar(&noForecast, "no-forecast", false, "Hide the forecast for the next 16 hours")

p.FlagSet.BoolVar(&jsonOut, "json", false, "Prints the raw JSON API response")
Expand Down Expand Up @@ -144,7 +146,7 @@ func main() {
return nil
}

if err := forecast.PrintCurrent(fc, geo, ignoreAlerts, hideIcon); err != nil {
if err := forecast.PrintCurrent(fc, geo, ignoreAlerts, hideIcon, emojiIcons); err != nil {
printError(err)
}

Expand Down