Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Q: How to avoid overlapping content in the MainScreen mode? #573

Closed
arazabishov opened this issue Dec 18, 2021 · 2 comments
Closed

Q: How to avoid overlapping content in the MainScreen mode? #573

arazabishov opened this issue Dec 18, 2021 · 2 comments

Comments

@arazabishov
Copy link

Description

Use case

First of all, thanks for the awesome crate!

I'm building a simple application that grabs data from a server and dumps it onto a screen. The idea was to render the content inline within the MainScreen right after the invocation. You can think of it as of cat, which dumps some data onto the screen and exists immediately.

I've followed the "getting started" guide to get something up and running (see the snippet in the "To Reproduce" section). As the result, the snippet is overlapping with the existing content in the terminal:

Screenshot 2021-12-18 at 19 52 13

What I'm trying to achieve is to render the block right after the cargo run command logs (without overlapping). I understand that the current behaviour might be the expected one, as tui might not care if there is existing content and treats the terminal window as canvas. But I was curious, if anyone has come across the same use case / problem before, and what would be the right solution?

To Reproduce

Here is the snippet:

let stdout = io::stdout();
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;

terminal.draw(|f| {
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .margin(1)
        .constraints(
            [
                Constraint::Percentage(10),
                Constraint::Percentage(80),
                Constraint::Percentage(10),
            ]
            .as_ref(),
        )
        .split(f.size());

    let block = Block::default().title("Test").borders(Borders::ALL);
    f.render_widget(block, chunks[2]);
})?;

Expected behavior

A mode or a way to instruct "tui" to append rendered contents to the existing content in terminal.

Environment

  • OS: macOS Big Sur v11.6.1
  • Terminal Emulator: Terminal.app
  • Font: San Francisco
  • Crate version: v0.16.0
  • Backend: crossterm v0.22.1
@fdehau fdehau added enhancement and removed bug labels Dec 23, 2021
@fdehau
Copy link
Owner

fdehau commented Dec 23, 2021

Hey 👋, so this is a bit related to #518. This is not currently supported by tui-rs that assumes you are running your application in an alternate screen or fullscreen.

The good news is that I've started working on this topic in #552 as I also think that it could be really valuable to be able to use tui widgets in cli outputs. This is still very much in progress but you can see a preview by running cargo run --example inline.

@arazabishov
Copy link
Author

Thanks a bunch! I will try out the preview and let you know how it goes :)

@fdehau fdehau closed this as completed Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants