Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lutetium-Vanadium committed Oct 25, 2021
1 parent 962cb81 commit e322486
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog

## `0.1.3`

- `requestty`

- Fix #3

- `requestty-ui`
- Update crossterm dependency

## `0.1.2`

- `requestty`
Expand Down
4 changes: 2 additions & 2 deletions 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"
Expand All @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions 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."
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion requestty-ui/src/select/mod.rs
Expand Up @@ -140,7 +140,7 @@ impl<L: List> Select<L> {
if self.is_paginating() {
if at >= self.list.len() {
self.init_page();
} else {
} else if self.heights.is_some() {
self.maybe_adjust_page(dir);
}
}
Expand Down
4 changes: 3 additions & 1 deletion requestty-ui/src/select/tests.rs
Expand Up @@ -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);
Expand Down

0 comments on commit e322486

Please sign in to comment.