#Have to abort? Is there a better way to prevent this buffer from flushing to term on exit?

16 messages · Page 1 of 1 (latest)

lilac garden
#

🔰

hazy folio
#

Out of curiosity, why do you need to prevent the buffer from flushing?

Since you are using abort, it doesn't matter what the destructor does.
https://doc.rust-lang.org/std/process/fn.abort.html

Note that because this function never returns, and that it terminates the process, no destructors on the current stack or any other thread’s stack will be run.

Are you on an old windows version?
https://docs.rs/crossterm/latest/crossterm/macro.queue.html#notes

In case of Windows versions lower than 10, a direct WinAPI call will be made. The reason for this is that Windows versions lower than 10 do not support ANSI codes, and can therefore not be written to the given writer. Therefore, there is no difference between execute and queue for those old Windows versions.

#

Oh I see, you mean how to not have to abort to stop it from flushing.

lilac garden
#

Yes!

#

Can not figure out how to prevent it from happening without using abort. There should be a way to do it pro..bably?

#

On linux mint

hazy folio
lilac garden
#
use std::io::{Stdout, stdout};
use std::mem::ManuallyDrop;
use std::process;
use crossterm::cursor::MoveTo;
use crossterm::queue;
use crossterm::style::Print;
use crossterm::terminal::{Clear, ClearType};

struct NonStdout(Stdout);

impl Drop for NonStdout {
    fn drop(&mut self) {
        process::abort();
        queue!(self.0, MoveTo(0,0), Print(" ")).unwrap();
    }
}

fn main() {
    let mut custom_stdout = ManuallyDrop::new((stdout())); //tried this..
    queue!(custom_stdout,
        MoveTo(0, 0),
        Clear(ClearType::FromCursorDown),
        Print("🤠")
    ).unwrap();
    //?!

    //unsafe { ManuallyDrop::drop(&mut custom_stdout); } //TRYING REALLY HARD

    //process::abort(); //? !?@#?!@?#! - OKAY, so, abort stops it... hmmm!
    process::exit(1);//?!?!
}
#

no such luck

hazy folio
#

The drop is what does the flush, so you don't want to drop it.

lilac garden
#

well I tried replacing the drop with nothing so when the drop eventually happens it has nothing to do

#

oh you mean the unsafe call, yes, still problem even without that

hazy folio
#

Can you post what the queue! macro expands to?

lilac garden
#
#[macro_export]
macro_rules! queue {
    ($writer:expr $(, $command:expr)* $(,)?) => {{
        use ::std::io::Write;

        // This allows the macro to take both mut impl Write and &mut impl Write.
        Ok($writer.by_ref())
            $(.and_then(|writer| $crate::QueueableCommand::queue(writer, $command)))*
            .map(|_| ())
    }}
}
#

I suppose I'm willing to give up on this one it's a really particular behavior that involves a dependency

#

A better solution will be not write garbage into stream buffers for no reason and quit I suppose