From 210877221372f20be3fea5aee52a176cca291520 Mon Sep 17 00:00:00 2001 From: kosay Date: Sat, 10 Jun 2023 01:21:49 +0900 Subject: [PATCH 1/3] Revert "Release version 1.3.0" This reverts commit a4a61125c25db4e6ff314993aeac2ca579faf297. --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01fe120bf..453e2a57c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1069,7 +1069,7 @@ dependencies = [ [[package]] name = "kubetui" -version = "1.3.0" +version = "1.2.2" dependencies = [ "anyhow", "arboard", diff --git a/Cargo.toml b/Cargo.toml index d339413b7..e0f311ef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kubetui" -version = "1.3.0" +version = "1.2.2" authors = ["kosay "] edition = "2021" license = "MIT" From fb2e8a88502031e084ef5163f12ee2f06536689a Mon Sep 17 00:00:00 2001 From: kosay Date: Sat, 10 Jun 2023 02:09:05 +0900 Subject: [PATCH 2/3] fix(ui): Fix occasional crash issue when resizing the window. --- src/event.rs | 1 - src/event/input.rs | 2 +- src/main.rs | 15 +++++---------- src/tui_wrapper/window.rs | 11 +++++++++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/event.rs b/src/event.rs index c6ed28c58..c803473c1 100644 --- a/src/event.rs +++ b/src/event.rs @@ -13,7 +13,6 @@ use self::kubernetes::Kube; pub enum UserEvent { Key(KeyEvent), Mouse(MouseEvent), - Resize(u16, u16), FocusGained, FocusLost, } diff --git a/src/event/input.rs b/src/event/input.rs index cd520e35e..3299b652c 100644 --- a/src/event/input.rs +++ b/src/event/input.rs @@ -50,7 +50,7 @@ fn inner(tx: Sender, is_terminated: Arc) -> Result<()> { } } CEvent::Mouse(ev) => tx.send(Event::User(UserEvent::Mouse(ev)))?, - CEvent::Resize(w, h) => tx.send(Event::User(UserEvent::Resize(w, h)))?, + CEvent::Resize(..) => {} CEvent::FocusGained => tx.send(UserEvent::FocusGained.into())?, CEvent::FocusLost => tx.send(UserEvent::FocusLost.into())?, CEvent::Paste(_) => {} diff --git a/src/main.rs b/src/main.rs index 4a941cd65..aefd32c6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ use std::{ thread, time, }; -use ratatui::{backend::CrosstermBackend, layout::Rect, Terminal, TerminalOptions, Viewport}; +use ratatui::{backend::CrosstermBackend, Terminal, TerminalOptions, Viewport}; macro_rules! enable_raw_mode { () => { @@ -102,21 +102,12 @@ fn run(config: Config) -> Result<()> { window.update_chunks(terminal.size()?); while !is_terminated.load(Ordering::Relaxed) { - terminal.draw(|f| { - window.render(f); - })?; - match window_action(&mut window, &rx_main) { WindowEvent::Continue => {} WindowEvent::CloseWindow => { is_terminated.store(true, std::sync::atomic::Ordering::Relaxed); // break } - WindowEvent::ResizeWindow(w, h) => { - let chunk = Rect::new(0, 0, w, h); - terminal.autoresize()?; - window.update_chunks(chunk); - } WindowEvent::UpdateContents(ev) => { update_contents( &mut window, @@ -126,6 +117,10 @@ fn run(config: Config) -> Result<()> { ); } } + + terminal.draw(|f| { + window.render(f); + })?; } match read_key_handler.join() { diff --git a/src/tui_wrapper/window.rs b/src/tui_wrapper/window.rs index 0562faad2..80d5eea2c 100644 --- a/src/tui_wrapper/window.rs +++ b/src/tui_wrapper/window.rs @@ -39,6 +39,7 @@ pub struct Window<'a> { open_popup_id: Option, header: Option>, layout_index: WindowLayoutIndex, + last_known_size: Rect, } #[derive(Default)] @@ -360,6 +361,14 @@ impl<'a> Window<'a> { // Render impl<'a> Window<'a> { pub fn render(&mut self, f: &mut Frame) { + let size = f.size(); + + if self.last_known_size != size { + self.update_chunks(size); + + self.last_known_size = size; + } + self.render_tab(f); self.render_header(f); @@ -407,7 +416,6 @@ pub enum WindowEvent { CloseWindow, Continue, UpdateContents(Kube), - ResizeWindow(u16, u16), } // Event @@ -416,7 +424,6 @@ impl Window<'_> { match ev { UserEvent::Key(ev) => self.on_key_event(ev), UserEvent::Mouse(ev) => self.on_mouse_event(ev), - UserEvent::Resize(w, h) => EventResult::Window(WindowEvent::ResizeWindow(w, h)), UserEvent::FocusLost => { self.focusable_tab_index = None; EventResult::Nop From 4d30bb307ff1134c27170f88ecbd4aa91fcf1e9f Mon Sep 17 00:00:00 2001 From: kosay Date: Sat, 10 Jun 2023 02:16:35 +0900 Subject: [PATCH 3/3] refactor(ui): remove unnecessary method call --- src/main.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index aefd32c6e..e405d8d4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,9 +99,12 @@ fn run(config: Config) -> Result<()> { WindowInit::new(split_mode, tx_main, context.clone(), namespace.clone()).build(); terminal.clear()?; - window.update_chunks(terminal.size()?); while !is_terminated.load(Ordering::Relaxed) { + terminal.draw(|f| { + window.render(f); + })?; + match window_action(&mut window, &rx_main) { WindowEvent::Continue => {} WindowEvent::CloseWindow => { @@ -117,10 +120,6 @@ fn run(config: Config) -> Result<()> { ); } } - - terminal.draw(|f| { - window.render(f); - })?; } match read_key_handler.join() {