summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-21 22:02:30 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-21 22:02:30 -0700
commitfdc4092d0276259c47a14cf2cc52c933fec633e4 (patch)
tree3c7583dae22640d446d088ec9a13a4faaeee4780 /src
parent01ffac500ab19d54548f0f69bf40c59f0ecb02b1 (diff)
Fix resizing issue
Turns out this is an issue running ncurses after crossterm
Diffstat (limited to 'src')
-rw-r--r--src/tui/views.rs29
-rw-r--r--src/utils.rs2
2 files changed, 16 insertions, 15 deletions
diff --git a/src/tui/views.rs b/src/tui/views.rs
index e4c8649..c131455 100644
--- a/src/tui/views.rs
+++ b/src/tui/views.rs
@@ -287,6 +287,7 @@ pub struct LayoutView {
layout: Layout,
layout_invalidated: bool,
size_invalidated: bool,
+ last_size: Option<Vec2>,
}
struct LayoutViewSizing {
@@ -305,31 +306,30 @@ impl ViewWrapper for LayoutView {
cursive::wrap_impl!(self.view: PaddedView<LinearLayout>);
fn wrap_on_event(&mut self, event: Event) -> EventResult {
- match event {
- Event::WindowResize => {
- println!("window resized");
- self.size_invalidated = true;
- }
- Event::Char(' ') => {
- self.cycle_layout();
- self.layout_invalidated = true;
- return EventResult::Consumed(None);
- }
- _ => (),
+ if let Event::Char(' ') = event {
+ self.cycle_layout();
+ self.layout_invalidated = true;
+ return EventResult::Consumed(None);
}
self.view.on_event(event)
}
fn wrap_required_size(&mut self, req: Vec2) -> Vec2 {
+ if self.last_size != Some(req) {
+ self.size_invalidated = true;
+ self.last_size = Some(req);
+ }
req
}
fn wrap_layout(&mut self, size: Vec2) {
- self.resize(size);
- self.relayout();
- self.layout_invalidated = false;
+ if self.layout_invalidated || self.size_invalidated {
+ self.resize(size);
+ self.relayout();
+ }
self.size_invalidated = false;
+ self.layout_invalidated = false;
self.view.layout(size);
}
@@ -354,6 +354,7 @@ impl LayoutView {
view,
layout_invalidated: true,
size_invalidated: true,
+ last_size: None,
layout: Layout::BothColumns,
})
.with_name(NAME_FULL_LAYOUT)
diff --git a/src/utils.rs b/src/utils.rs
index 560f186..e7a8830 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -26,8 +26,8 @@ pub fn create_file(filename: &PathBuf) -> Result<File> {
}
pub fn wait_for_char(c: char) -> Result<bool> {
- terminal::enable_raw_mode()?;
let mut pressed = false;
+ terminal::enable_raw_mode()?;
loop {
match read()? {
Event::Key(KeyEvent {