apognu / tuigreet

Graphical console greeter for greetd
GNU General Public License v3.0
912 stars 41 forks source link

Messy output when using reboot/shutdown #126

Closed techtruth closed 4 months ago

techtruth commented 5 months ago

The system (in my case OpenRC) prints to stdout when the runlevel changes. This is normally very good.

I believe tuigreet is somehow holding onto the cursor position and the screen contents, forcing what character position stdout gets shown from.

I think this because the stdout messages get written to the spot where the username/password input is at on tuigreet. This indicates to me that the tuigreet is 'grabbing' the text input position, and as stdout prints, it prints from where tuigreet says is the position.

This is different than other issues https://github.com/apognu/tuigreet/issues/68 because this is shutdown, not startup. While I could set the system not to log these to stdout, I'd rather see them and have them land properly with tuigreet.

One solution I could think of would be to clear the screen, and stop the 'render loop' of tuigreet whenever the reboot or shutdown commands are invoked. This would let the terminal start in the top left character and not be disturbed from tuigreet setting the prompt for username/password.

This solution wont work for the startup flavor of this issue. This is only for shutting down.

As a note, if i run the shutdown from within wayland, it works as expected showing the last output and "skipping" the tuigreet. This is only an issue when i shutdown/reboot before logging in, OR if i exit wayland to see tuigreet and then shutdown/reboot.

Here is an image of the behavior I'd like to resolve: badlog

techtruth commented 5 months ago

It might be the case that you can stop the running set/get loop when the code reaches https://github.com/apognu/tuigreet/blob/master/src/power.rs#L18 -- This may stop the rendering, but let stdout still print from a different process.

techtruth commented 5 months ago

Or maybe a cleaner approach would be to do it when the main module receives the power event https://github.com/apognu/tuigreet/blob/master/src/main.rs#L93

techtruth commented 5 months ago

Some progress, it looks like clearing is not enough, as it still retains its cursor position.

This patch does clear all the visual elements off the screen as intended, but still need to look at resetting the position of the cursor. ... This should also call clear only once, but used it twice when experimenting.


index c26877d..5d0ab7d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -79,7 +79,9 @@ async fn run() -> Result<(), Box<dyn Error>> {
         let command = greeter.write().await.power_command.take();

         if let Some(command) = command {
+          clear_screen(); // Call clear_screen after receiving the power command event
           power::run(&greeter, command).await;
+          clear_screen(); // Call clear_screen after receiving the power command event
         }
       }
     }
apognu commented 4 months ago

We probably need to exit raw mode before clearing the screen. I'll look into it if I can reproduce.

techtruth commented 4 months ago

I'll look into it if I can reproduce.

I should have included... I reach this state when I set tuigreet to use the openrc-shutdown -p now command in its command line arguments. Tuigreet is launched by greetd. I'm assuming it's similar behavior to most other shutdown commands.

apognu commented 4 months ago

Are you able to build the binary out of the dev/clear-screen-on-power branch and tell if it improves your experience?

techtruth commented 4 months ago

This seems to have resolved the issue! Thank you!

I did notice however that the password input is now on a line lower than it should be. image

apognu commented 4 months ago

Yeah this was reported in #130 and fixed on the main branch. It should not be present once merged.