Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request repaint on stdout/stderr changes #53

Merged
merged 4 commits into from Nov 24, 2022

Conversation

barafael
Copy link
Contributor

@barafael barafael commented Nov 1, 2022

Proof-of-concept fix for #51, using an unsafe static mut CTX to save the egui::Context.

Doing this right could be done by adding a ctx field to the Klask type, however, this may be a big conceptual change? Also, egui::Context does not impl std::fmt::Debug, so it breaks the #[derive(Debug)] on Klask.

Let me know what you think when you have the time :)

@MichalGniadek
Copy link
Owner

Thanks for the PR! :) Could you explain why this is needed and why the issue happens? Why does the GUI not refresh on stdout changes?

Either way I think it would be better to either use once_cell or something similar or put the ctx in Klask instead of using unsafe

@barafael
Copy link
Contributor Author

Hi Michal,
here's a minimal example showing the issue:

use std::{thread, time::Duration};

use clap::Parser;
use klask::Settings;

#[derive(Debug, Parser)]
struct Args {
    #[clap(short)]
    verbose: bool,
}

fn main() {
    klask::run_derived::<Args, _>(Settings::default(), |_| {
        for _ in 0..5 {
            println!("hello");
            thread::sleep(Duration::from_millis(500));
        }
    });
}

Rafael Bachmann and others added 2 commits November 10, 2022 20:46
this time, without unsafe static mut gore
@barafael
Copy link
Contributor Author

This new fix gets away without unsafe and once_cell. We fixed it collaboratively in the Rust Nuremberg Meetup group :)

This fixes another slight bug, namely that the "Run" and "Kill" buttons did not correctly update when the application exited.

By calling request_repaint one last time when stdout or stderr close, the button reappears even when the mouse is not moved. This of course only happens if the application really closed, not if it is for some reason still running.

@MichalGniadek
Copy link
Owner

MichalGniadek commented Nov 24, 2022

This new fix gets away without unsafe and once_cell

That's amazing! Thank you :)

@MichalGniadek MichalGniadek merged commit 670f12a into MichalGniadek:master Nov 24, 2022
@barafael barafael deleted the stdout-update branch November 24, 2022 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants