tui 描画に ftxui を取り入れる。

unknown: html => {"type":"html","value":"<!-- truncate -->","position":{"start":{"line":4,"column":1,"offset":24},"end":{"line":4,"column":18,"offset":41}}}

試しに screen の出力に ftxui を使ってみたところ、 さくと動いた。

void refresh(FILE *ttyf) {
  // using namespace ftxui;
  auto screen = ftxui::Screen::Create(ftxui::Dimension::Fixed(COLS()),
                                      ftxui::Dimension::Fixed(LINES()));

  for (int y = 0; y <= LASTLINE(); y++) {
    auto pc = ScreenImage[y]->lineimage;
    auto pr = ScreenImage[y]->lineprop;
    for (int x = 0; x < COLS(); x++) {
      if (CHMODE(pr[x]) == C_WCHAR2) {
      } else {
        auto &pixel = screen.PixelAt(x, y);
        auto &utf8 = pc[x];
        if (utf8.view().size() == 0) {
          pixel.character = " ";
        } else {
          pixel.character = pc[x].view();
        }

        auto p = pr[x];
        pixel.inverted = p & S_STANDOUT;
        pixel.underlined = p & S_UNDERLINE;
        pixel.bold = p & S_BOLD;
      }
    }
  }

  term_move(0, 0);
  auto str = screen.ToString();
  fwrite(str.data(), str.size(), 1, ttyf);

  term_move(CurLine, CurColumn);
  flush_tty();
}

よさそう。 termcap/terminfo 依存が除去できる。 libuv と ftxui の導入で Windows ビルドの見通しがついた。

ncurses 依存を削除できた

ncurses というか tgetent 系の termcap 関数に対する依存なのだけど、 ftxui の Screen で代替して削除できた。