feat(weather): add TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE option#515
feat(weather): add TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE option#515turtle11311 wants to merge 3 commits into
Conversation
Some terminals miscount the tmux status-bar width when weather condition symbols use VS16 variation selectors (e.g. ☀️ is U+2600 + U+FE0F): tmux measures the base character as 1 cell while the terminal renders the pair as 2, causing the right side of the status bar to overflow or wrap. Adds TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE with four values: emoji - VS16 preserved (default, original behaviour) emoji_fixed - VS16 stripped; fixes width for affected terminals nerdfonts - Nerd Font PUA icons (fixed 1-cell width, no ambiguity) auto - nerdfonts when tp_patched_font_in_use(), else emoji The default is "emoji" so existing users see no change. Related: PR erikw#511 (deanbear) which addresses the same width issue. This is a focused split of erikw#513, extracted as a standalone change. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a configurable weather icon style option so users can choose the existing emoji rendering, VS16-stripped emoji, Nerd Font icons, or automatic selection based on patched-font detection.
Changes:
- Adds
TMUX_POWERLINE_SEG_WEATHER_ICON_STYLEdefaults and generated config documentation. - Resolves icon style during weather rendering, including
autodetection. - Expands weather condition symbol selection to support emoji, fixed emoji, and Nerd Font output.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if [ "$style" = "nerdfonts" ]; then | ||
| # All Nerd Font icons are PUA (1 cell), no width ambiguity | ||
| case "$condition" in | ||
| "clearsky_day") printf "\UF0599" ;; # mdi-weather-sunny |
There was a problem hiding this comment.
Fixed — replaced all printf "\\UF..." calls with literal UTF-8 glyphs embedded directly in the source file. Bash 3.2-safe.
Also took this opportunity to fix the related portability issue raised in the adjacent Copilot comment (line 236): the sed 's/\xef\xb8\x8f//g' VS16-stripping (GNU sed only) has been replaced with an explicit emoji_fixed lookup table that pre-defines each symbol without VS16, so no sed is needed at all.
| *) symbol="?" ;; | ||
| esac | ||
| if [ "$style" = "emoji_fixed" ]; then | ||
| printf '%s' "$symbol" | sed 's/\xef\xb8\x8f//g' |
There was a problem hiding this comment.
Fixed — the entire sed-based approach has been dropped. emoji_fixed is now a standalone lookup table with the VS16-free symbols pre-defined, so no post-processing is needed at all.
| local icon_style="${TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE:-$TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE_DEFAULT}" | ||
| if [ "$icon_style" = "auto" ]; then | ||
| tp_patched_font_in_use && icon_style="nerdfonts" || icon_style="emoji" | ||
| fi | ||
| # condition_symbol=$(__get_yrno_condition_symbol "$condition" "$sunrise" "$sunset") | ||
| condition_symbol=$(__get_yrno_condition_symbol "$condition") | ||
| local condition_symbol | ||
| condition_symbol=$(__get_yrno_condition_symbol "$condition" "$icon_style") |
There was a problem hiding this comment.
Fixed — icon style is now resolved at the top of run_segment() before the cache read, and the cache file path encodes the style (weather_cache_data_${icon_style}.txt). Switching TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE takes effect immediately without waiting for the cache to expire.
| "heavyrainandthunder" | "heavyrainshowersandthunder_day" | "heavyrainshowersandthunder_night" | "heavysleetandthunder" | "heavysleetshowersandthunder_day" | "heavysnowandthunder" | "heavysnowshowersandthunder_day" | "heavysnowshowersandthunder_night" | "lightrainandthunder" | "lightrainshowersandthunder_day" | "lightrainshowersandthunder_night" | "lightsleetandthunder" | "lightsnowandthunder" | "lightssleetshowersandthunder_day" | "lightssleetshowersandthunder_night" | "lightssnowshowersandthunder_day" | "lightssnowshowersandthunder_night" | "rainandthunder" | "rainshowersandthunder_day" | "rainshowersandthunder_night" | "sleetandthunder" | "sleetshowersandthunder_day" | "sleetshowersandthunder_night" | "snowandthunder" | "snowshowersandthunder_day" | "snowshowersandthunder_night") | ||
| printf "\UF067E" ;; # mdi-weather-lightning-rainy | ||
| "heavyrainshowers_day" | "heavysleetshowers_day" | "heavysleetshowersandthunder_night" | "lightrainshowers_day" | "lightsleetshowers_day" | "rainshowers_day" | "sleetshowers_day") |
There was a problem hiding this comment.
Fixed — heavysleetshowersandthunder_night moved into the thunder/lightning group across all three style branches (nerdfonts, emoji_fixed, emoji).
erikw
left a comment
There was a problem hiding this comment.
@turtle11311 please address comments abovce
- Replace printf \U Unicode escapes with literal UTF-8 glyphs (Bash 3.2 / macOS-safe; \U is a bash 4+ extension) - Replace sed \xHH VS16-stripping with an explicit emoji_fixed lookup table (BSD sed does not support \xHH escape syntax) - Move heavysleetshowersandthunder_night into the thunder/lightning group across all three style branches (was incorrectly placed in the partly-rainy showers group) - Resolve icon_style in run_segment() before the cache read and encode it into the cache file path, so changing ICON_STYLE takes effect immediately without waiting for the weather cache to expire Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
d7c5488 to
d6d3762
Compare
Literal UTF-8 glyphs are unreadable in diffs without Nerd Fonts; U+XXXXX comments let reviewers identify each icon without the font. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| # Icon style: "emoji" (default), "nerdfonts", "emoji_fixed", "auto" | ||
| TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE_DEFAULT="emoji" |
|
|
||
| run_segment() { | ||
| local weather="" | ||
| # Resolve icon style before the cache read so the cache file path is |
There was a problem hiding this comment.
Would this block of code added make sense to do in __process_settings(), my hunch is that it would.
Problem
Some terminals miscount the tmux status-bar width when weather condition symbols use VS16 variation selectors. For example, ☀️ is U+2600 + U+FE0F: tmux measures the base character as 1 cell while the terminal renders the pair as 2, causing the right side of the status bar to overflow or wrap.
Related: #511 (deanbear) which addresses the same width issue via a different approach.
Fix
Adds
TMUX_POWERLINE_SEG_WEATHER_ICON_STYLEwith four values:emojiemoji_fixednerdfontsautonerdfontswhentp_patched_font_in_use()detects a patched font, otherwiseemojiThe default is
emoji, so existing users see no change without opting in.The
nerdfontspath uses MDI icons already in the Nerd Font PUA range, consistent with how other tmux-powerline segments use patched-font icons.Configuration
This is a focused split of #513 (which also fixed a separate non-blocking fetch issue — that is tracked in a companion PR #514).