Skip to content

Printing continues at wrong position when the terminal instance gets out of scope #11

@phil0x2e

Description

@phil0x2e

Take this Code (I'm using crossterm-backend):

use terminal::{Action, Clear, error, Retrieved, Value};
use std::io::Write;
pub fn main() -> error::Result<()> {
    {
        let mut terminal = terminal::stdout();
        // perform an single action.
        terminal.act(Action::ClearTerminal(Clear::All))?;
        // batch multiple actions.
        for i in 0..10 {
            terminal.batch(Action::MoveCursorTo(0, i))?;
            terminal.write(format!("{}", i).as_bytes());
        }
        // execute batch.
        terminal.flush_batch();

        println!("\ntest1");
    }
    println!("test2");
    Ok(())
}

The output for me looks something like this:

test2
[user@host]$ 
2
3
4
5
6
7
8
9
test1

Is there a way to prevent this behaviour?
If not terminal seems to be not suited for use in a library, because anyone that's using the library would always need to keep an instance of the Terminal struct alive (Or at least a struct from the library using it, that itself keeps an instance of Terminal) to be able to properly print something afterwards.

EDIT:
Even when you just create an instance of Terminal and do nothing with it and end its scope, this problem occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions