From e32248620955c956b9d6d253a9a51123cf7f1dec Mon Sep 17 00:00:00 2001 From: Lutetium-Vanadium Date: Mon, 25 Oct 2021 19:01:30 +0530 Subject: [PATCH] Fix #3 The `set_at` function for `requestty_ui::widgets::Select` adjusts the page bounds if required. However, it wouldn't check if the component has never been rendered (and so heights never calculated) and thus cause a panic if called before ever being rendered. Now `set_at` can be called at any point. --- CHANGELOG.md | 9 +++++++++ Cargo.toml | 4 ++-- requestty-ui/Cargo.toml | 4 ++-- requestty-ui/src/select/mod.rs | 2 +- requestty-ui/src/select/tests.rs | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a1eaa..91e861b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## `0.1.3` + +- `requestty` + + - Fix #3 + +- `requestty-ui` + - Update crossterm dependency + ## `0.1.2` - `requestty` diff --git a/Cargo.toml b/Cargo.toml index fc1a0a5..4225de4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "requestty" -version = "0.1.2" +version = "0.1.3" authors = ["Lutetium Vanadium"] edition = "2018" description = "An easy-to-use collection of interactive cli prompts" @@ -22,7 +22,7 @@ members = [ [dependencies] tempfile = "3" -ui = { package = "requestty-ui", path = "./requestty-ui", version = "=0.2.0" } +ui = { package = "requestty-ui", path = "./requestty-ui", version = "=0.2.1" } macro = { package = "requestty-macro", path = "./requestty-macro", optional = true, version = "=0.1.1" } smallvec = { version = "1.6", optional = true } diff --git a/requestty-ui/Cargo.toml b/requestty-ui/Cargo.toml index 5721370..c0783c4 100644 --- a/requestty-ui/Cargo.toml +++ b/requestty-ui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "requestty-ui" -version = "0.2.0" +version = "0.2.1" authors = ["Lutetium Vanadium"] edition = "2018" description = "A widget based terminal ui rendering library." @@ -18,7 +18,7 @@ bitflags = "1.2" textwrap = "0.14" unicode-segmentation = "1.7" -crossterm = { version = "0.21", optional = true } +crossterm = { version = "0.22", optional = true } termion = { version = "1.5", optional = true } [dev-dependencies] diff --git a/requestty-ui/src/select/mod.rs b/requestty-ui/src/select/mod.rs index 1496a6e..3eb60cc 100644 --- a/requestty-ui/src/select/mod.rs +++ b/requestty-ui/src/select/mod.rs @@ -140,7 +140,7 @@ impl Select { if self.is_paginating() { if at >= self.list.len() { self.init_page(); - } else { + } else if self.heights.is_some() { self.maybe_adjust_page(dir); } } diff --git a/requestty-ui/src/select/tests.rs b/requestty-ui/src/select/tests.rs index e818cbb..8914d03 100644 --- a/requestty-ui/src/select/tests.rs +++ b/requestty-ui/src/select/tests.rs @@ -139,10 +139,12 @@ fn test_selectable() { let list = select.into_inner().with_should_loop(false); let mut select = Select::new(list); + select.set_at(2); + select.maybe_update_heights(Layout::new(0, (100, 20).into())); select.init_page(); - assert_eq!(select.get_at(), 1); + assert_eq!(select.get_at(), 2); select.set_at(0); assert_eq!(select.prev_selectable(), 1); select.set_at(1);