oyvindberg / tui-scala

Beautiful Text-based User Interfaces for Scala
MIT License
207 stars 11 forks source link

Emoji is not rendered correctly #67

Open tsobako opened 1 month ago

tsobako commented 1 month ago

Description

Emojis are not rendered in tui widgets in terminal

Minimal Reproducible Example

OS - Debian 12.4 Terminal - Alacritty 0.14.0 Font configuration

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
  <alias>
    <family>terminal-font</family>
    <prefer>
      <family>CaskaydiaMono Nerd Font</family>
      <family>Noto Color Emoji</family>
     </prefer>
  </alias>
</fontconfig>

Example code

package tuiexamples

import tui._
import tui.crossterm.CrosstermJni
import tui.widgets.ParagraphWidget

object BugExample {

  def main(args: Array[String]): Unit =
    withTerminal { (jni, terminal) =>
    run_app(terminal, jni)
  }

  def run_app(terminal: Terminal, jni: CrosstermJni): Unit =
    while (true) {
      terminal.draw(ui)
      jni.read() match {
        case key: tui.crossterm.Event.Key =>
          key.keyEvent.code match {
            case char: tui.crossterm.KeyCode.Char if char.c() == 'q' => return
            case _ => ()
          }
        case _ => ()
      }
  }

  def ui(f: Frame): Unit = {
    val size = f.size
    val label = ParagraphWidget(text = Text.nostyle("\uD83C\uDF52"))
    f.renderWidget(label, size)
  }
}

Screenshot

2024-09-26_12:41:25

Println example

package tuiexamples

import tui._
import tui.crossterm.CrosstermJni
import tui.widgets.ParagraphWidget

object BugExample {

  def main(args: Array[String]): Unit = print("\uD83C\uDF52")
}

Screenshot

2024-09-26_12:43:34

oyvindberg commented 1 month ago

I have no clue about this, honestly. I know emojis stress unicode a bit, and tui contains some interesting unicode code like this https://github.com/oyvindberg/tui-scala/blob/master/tui/src/scala/tui/internal/Wcwidth.scala

so I'm gonna have to leave this as an exercise to the reader for now, unfortunately.