Manual and automatic refresh

Hello Ratatui community,

What I would like to achieve is a terminal that I can refresh manually (by pressing R) and, inside this terminal, another section that refreshes automatically (the purple square).

The code is available here.

Currently, I am (almost) able to refresh the application manually:
In app.rs, line 603 there is run function how is an implementation of App structure. I use this function in main.rs to run the terminal.
At line 127 you can see that let result = app.run(&mut terminal); is in a loop. If R is pressed (line 155) the app will be manually refresh with the new values. But there is an issue:
I have to press R to times to refresh the app.
I suspect that the first press exits the terminal from the run function (app.rs, line 603). That’s why I have KeyCode::Char('R') => self.should_exit = true, in line 716. Thus, once this this first terminal exited, the app is able to listen key event from main.rs, line 155. And refresh when I press R for the second time.

For should_exit, I thought I needed it, but while writing this message, I tried removing it, and I still have to press R twice… I’m confused.

Issue 1: How can I make the app refresh with a single press of R instead of two?

Additionally, I need a section in the terminal that refreshes automatically. To test this, I tried displaying the current time at line 135 in main.rs. However, this issue seems related to the first one: I have to exit the terminal once (by pressing R) before I can see the time updating dynamically. But when this happens, the first terminal disappears, leaving only the time in a black background.

If I press R again, the normal terminal reappears and refreshes.

Issue 2: How can I make one part of the terminal refresh automatically while another part refreshes manually? Both should be displayed at the same time (first screenshot).

Note: I built this app to learn Rust and Ratatui, so I’m aware that the code is not very well structured. I apologize for that, and I hope you can understand my code and the issues I’m facing. Thank you in advance for taking the time to read my message and for your responses.

Problem solved :slight_smile:
I just had to call the App implementation in another way in main.rs.