This commit is contained in:
Alexandre Bury 2019-04-11 17:08:55 -07:00
parent 158bc65c33
commit 51c6450688
3 changed files with 29 additions and 19 deletions

View File

@ -276,7 +276,8 @@ impl backend::Backend for Backend {
"{}{}", "{}{}",
termion::cursor::Goto(1 + pos.x as u16, 1 + pos.y as u16), termion::cursor::Goto(1 + pos.x as u16, 1 + pos.y as u16),
text text
).unwrap(); )
.unwrap();
let mut dupes_left = repetitions - 1; let mut dupes_left = repetitions - 1;
while dupes_left > 0 { while dupes_left > 0 {

View File

@ -390,7 +390,8 @@ impl<T: 'static> SelectView<T> {
/// selection will likely be changed by the sorting. /// selection will likely be changed by the sorting.
/// This sort is stable: items with identical label will not be reordered. /// This sort is stable: items with identical label will not be reordered.
pub fn sort_by_label(&mut self) { pub fn sort_by_label(&mut self) {
self.items.sort_by(|a, b| a.label.source().cmp(b.label.source())); self.items
.sort_by(|a, b| a.label.source().cmp(b.label.source()));
} }
/// Sort the current items with the given comparator function. /// Sort the current items with the given comparator function.
@ -401,7 +402,9 @@ impl<T: 'static> SelectView<T> {
/// unspecified. /// unspecified.
/// This sort is stable: equal items will not be reordered. /// This sort is stable: equal items will not be reordered.
pub fn sort_by<F>(&mut self, mut compare: F) pub fn sort_by<F>(&mut self, mut compare: F)
where F: FnMut(&T, &T) -> Ordering { where
F: FnMut(&T, &T) -> Ordering,
{
self.items.sort_by(|a, b| compare(&a.value, &b.value)); self.items.sort_by(|a, b| compare(&a.value, &b.value));
} }
@ -410,7 +413,10 @@ impl<T: 'static> SelectView<T> {
/// selection will likely be changed by the sorting. /// selection will likely be changed by the sorting.
/// This sort is stable: items with equal keys will not be reordered. /// This sort is stable: items with equal keys will not be reordered.
pub fn sort_by_key<K, F>(&mut self, mut key_of: F) pub fn sort_by_key<K, F>(&mut self, mut key_of: F)
where F: FnMut(&T) -> K, K: Ord { where
F: FnMut(&T) -> K,
K: Ord,
{
self.items.sort_by_key(|item| key_of(&item.value)); self.items.sort_by_key(|item| key_of(&item.value));
} }
@ -700,7 +706,10 @@ impl SelectView<String> {
} }
} }
impl<T: 'static> SelectView<T> where T: Ord { impl<T: 'static> SelectView<T>
where
T: Ord,
{
/// Sort the current items by their natural ordering. /// Sort the current items by their natural ordering.
/// Note that this does not change the current focus index, which means that the current /// Note that this does not change the current focus index, which means that the current
/// selection will likely be changed by the sorting. /// selection will likely be changed by the sorting.
@ -877,7 +886,7 @@ mod tests {
// We add items in no particular order, from going by their key value. // We add items in no particular order, from going by their key value.
#[derive(Eq, PartialEq, Debug)] #[derive(Eq, PartialEq, Debug)]
struct MyStruct { struct MyStruct {
key: i32 key: i32,
} }
let mut view = SelectView::new(); let mut view = SelectView::new();