2

Based on this answer, I hoped that the following would work:

# Is emoji supported by the terminal?
function is_emoji_supported {
  [ "$(echo -ne '\xE0\xA5\xA5' | wc -m)" -eq 1 ]
}

I'm guessing that this doesn't work because wc never looks at the terminal's view of characters, but rather LC_*.

Is there a (ideally POSIX) way of determining whether the terminal purports to support emoji?

Tom Hale
  • 28,728
  • 32
  • 139
  • 229
  • 2
    That answer is complete nonsense. – Michael Homer Aug 16 '19 at 09:37
  • 1
    All terminals support _emojis_ since [`*` and `#` are emojis as per unicode](https://unicode.org/Public/emoji/12.0/emoji-data.txt). – Stéphane Chazelas Aug 16 '19 at 12:04
  • All terminals that support at least one Unicode encoding (UTF-8, GB18030) support the full list of unicode emojis provided they're configured to use a font that has them all (bear in mind that the list of emojis varies from one version of unicode to the next and it takes time for fonts to be updated) – Stéphane Chazelas Aug 16 '19 at 12:07
  • Related: [Can a script determine which characters a terminal can display?](https://unix.stackexchange.com/q/284990/143394) – Tom Hale Aug 16 '19 at 14:41
  • What exactly do you mean by _emoji_. Assuming that code was meant to check whether the locale's encoding is UTF-8 (it's not working properly even to do that), `0xE0 0xA5 0xA5` is the UTF-8 encoding of U+0965, a character in the Devanagari script, not an _emoji_ in any definition of emoji I can think of. Do you mean _non-ASCII character_? – Stéphane Chazelas Aug 17 '19 at 07:26
  • @StéphaneChazelas I mean an emoji as defined by https://unicode.org/emoji/charts/index.html Oops about the particular example character, I copied it from the flawed answer listed in my question. I'd be happy to determine if UTF-8 is supported by the terminal. – Tom Hale Aug 22 '19 at 07:23
  • If possible, I'd like to ensure that something common like the USA flag (emoji 1.0) is printed as a single emoji, rather than as followed by . – Tom Hale Aug 22 '19 at 07:35

0 Answers0