Skip to content

Commit

Permalink
ratatui cleanup fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardicus committed Nov 3, 2024
1 parent 9274d98 commit 8911a95
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 210 deletions.
22 changes: 15 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ use ncurses::*;

mod terminal;
use terminal::{
format_chat_msg, format_chat_msg_fmt, ChatClosedCommand, PrintChatCommand, PrintCommand,
SetChatMessagesCommand, TextStyle, WindowCommand, WindowManager, WindowPipe,
format_chat_msg, format_chat_msg_fmt, AppCurrentState, ChatClosedCommand, PrintChatCommand,
PrintCommand, SetAppStateCommand, SetChatMessagesCommand, TextStyle, WindowCommand,
WindowManager, WindowPipe,
};

#[derive(Parser)]
Expand Down Expand Up @@ -101,6 +102,14 @@ async fn chat_reset_messages() {
}))
.await;
}
async fn set_app_state(state: AppCurrentState) {
PIPE.get()
.unwrap()
.send(WindowCommand::SetAppState(SetAppStateCommand {
state: AppCurrentState::Commands,
}))
.await;
}
async fn println_chat_message(chatid: String, message: String) {
PIPE.get()
.unwrap()
Expand Down Expand Up @@ -336,11 +345,8 @@ async fn cb_closed(public_key: String, _session_id: String) {
))
.await;

// Spawn a new process
tokio::spawn(async move {
tokio::time::sleep(Duration::from_secs(1)).await;
chat_reset_messages().await;
});
set_app_state(AppCurrentState::Commands).await;
chat_reset_messages().await;
}
_ => {}
}
Expand Down Expand Up @@ -569,6 +575,8 @@ async fn launch_terminal_program(
.await;

keep_running = false;

terminate(session_tx.clone()).await;
continue;
}
let input = input.unwrap();
Expand Down
23 changes: 6 additions & 17 deletions src/session/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ impl ZenohHandler {
impl MessagebleTopicAsync for ZenohHandler {
async fn read_message(&self, topic: &str) -> Result<SessionMessage, MessagingError> {
let s = self.session.lock().await;
let subscriber = s.declare_subscriber(topic)
.await
.unwrap();
let subscriber = s.declare_subscriber(topic).await.unwrap();
match subscriber.recv_async().await {
Ok(incoming) => {
let incoming = incoming
Expand All @@ -121,9 +119,7 @@ impl MessagebleTopicAsync for ZenohHandler {
let message = message.serialize().unwrap();
let s = self.session.lock().await;

s.put(topic, message)
.await
.unwrap();
s.put(topic, message).await.unwrap();
Ok(())
}
}
Expand All @@ -136,9 +132,7 @@ impl MessagebleTopicAsyncPublishReads for ZenohHandler {
) -> Result<(), MessagingError> {
let mut topic_in = topic.to_string();
let s = self.session.lock().await;
let subscriber = s.declare_subscriber(topic)
.await
.unwrap();
let subscriber = s.declare_subscriber(topic).await.unwrap();
loop {
let msg = match subscriber.recv_async().await {
Ok(incoming) => {
Expand Down Expand Up @@ -180,13 +174,10 @@ impl MessagebleTopicAsyncReadTimeout for ZenohHandler {
timeout_duration: std::time::Duration,
) -> Result<SessionMessage, MessagingError> {
let s = self.session.lock().await;
let subscriber = s.declare_subscriber(topic)
.await
.unwrap();
let subscriber = s.declare_subscriber(topic).await.unwrap();
match timeout(timeout_duration, subscriber.recv_async()).await {
Ok(incoming) => {
let incoming = incoming
.unwrap();
let incoming = incoming.unwrap();
let incoming = incoming
.payload()
.try_to_string()
Expand All @@ -207,9 +198,7 @@ impl MessagebleTopicAsyncReadTimeout for ZenohHandler {
) -> Result<Vec<SessionMessage>, MessagingError> {
let mut messages = Vec::new();
let s = self.session.lock().await;
let subscriber = s.declare_subscriber(topic)
.await
.unwrap();
let subscriber = s.declare_subscriber(topic).await.unwrap();

let end_time = Instant::now() + timeout_duration;

Expand Down
3 changes: 1 addition & 2 deletions src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
if session_init_ok_msg.is_some() {
let zc = self.middleware_config.clone();
let zenoh_config = Config::from_file(zc).unwrap();
let zenoh_session =
Arc::new(Mutex::new(zenoh::open(zenoh_config).await.unwrap()));
let zenoh_session = Arc::new(Mutex::new(zenoh::open(zenoh_config).await.unwrap()));
let handler = ZenohHandler::new(zenoh_session);
let msg = session_init_ok_msg.unwrap().clone();
let _ = self
Expand Down
Loading

0 comments on commit 8911a95

Please sign in to comment.