Skip to main content

normalize_emoji

Function normalize_emoji 

Source
pub fn normalize_emoji(text: &str) -> Cow<'_, str>
Expand description

Removes the emoji variation selector U+FE0F after a one-column character.

Terminals disagree about ⚠️ (U+26A0 U+FE0F): the Unicode standard makes it a two-column emoji, but several widely used terminals (VTE, the base of GNOME Terminal, among them) keep the single column of the bare ⚠. No width calculation is right for both, and a wrong one pushes the right border of a box out of line. Text that goes into a box is therefore normalised to the bare symbol, whose width is one everywhere. Emoji that are wide anyway, such as 💡, are left alone.

use shellgame::ui::text::{normalize_emoji, visible_width};

assert_eq!(normalize_emoji("⚠\u{fe0f} pozor"), "⚠ pozor");
assert_eq!(visible_width(&normalize_emoji("⚠\u{fe0f}")), 1);
assert_eq!(normalize_emoji("💡\u{fe0f}"), "💡\u{fe0f}");