ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.96k stars 420 forks source link

Resize ScreenInteractive::TerminalOutput() on SIGWINCH issue #951

Open dangooddd opened 2 days ago

dangooddd commented 2 days ago

Hi! I got problem with terminal resizing and ScreenInteractive::TerminalOutput component. This issue appears not only in tmux, but also in plain terminal (tested on Kitty, Alacritty, Foot and Konsole). Redrawing works well when fullscreen.

How can I solve this? Compiled with clang 19, version of ftxui is 5.0.0

I am new to the TUI thing and this community, so sorry if this issue well known, I can't find anything about this.

redrawing_issue.webm

dangooddd commented 2 days ago

Code is almost identical to menu example from repo

#include "embf/directory.hpp"
#include "ftxui/component/component.hpp"
#include "ftxui/component/component_options.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
#include <ftxui/dom/elements.hpp>
#include <iostream>

int main(int argc, char *argv[]) {
    using namespace ftxui;
    auto screen = ScreenInteractive::TerminalOutput();

    std::vector<std::string> entries = {
        "entry 1",
        "entry 2",
        "entry 3",
    };
    int selected = 0;

    MenuOption option;
    option.on_enter = screen.ExitLoopClosure();
    auto menu = Menu(&entries, &selected, option) | borderLight;

    screen.Loop(menu);

    std::cout << "Selected element = " << selected << std::endl;

    return 0;
}
ArthurSonzogni commented 1 day ago

Hello, Line wrapping are implemented by the terminal emulator. I don't think I know any solution against this.

If you used ScreenInteractive::Fullscreen we would draw over the whole area, on an alternate screen, which would avoid seeing all the garbage.

If you know about any other solution, I would happily implement it.

dangooddd commented 1 day ago

I see that fzf does this, but only when resize left/right. I guess that after sigwinch it redraws window at top of terminal, so it becomes fullscreen-like. See video below.

I think that is not a bad solution, because anyway output of terminal becomes crap, so why not to clear it? What do you think about this?

fzf_resizing.webm

ArthurSonzogni commented 1 day ago

clearing the terminal during a screen width change looks like a good idea! Do you want to try submitting a PR?

dangooddd commented 21 hours ago

I think I can try, will open draft PR soon!