-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::theme::ColoredTheme; | ||
use dialoguer::OrderList; | ||
use std::io::Result; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
/// Prompt that allows the user to sort items in a list | ||
pub struct Sort { | ||
#[structopt(short, long)] | ||
/// Message for the prompt | ||
message: String, | ||
|
||
/// Enables paging. Uses your terminal size | ||
#[structopt(short, long)] | ||
paged: bool, | ||
|
||
/// Do not print the sorted items on the prompt line | ||
#[structopt(long)] | ||
no_inline: bool, | ||
|
||
/// Items that can be sorted | ||
items: Vec<String>, | ||
} | ||
|
||
impl Sort { | ||
pub fn run(&self) -> Result<()> { | ||
let item_len = self.items.len(); | ||
|
||
if item_len == 0 { | ||
return Ok(()); | ||
} | ||
|
||
let theme = ColoredTheme::default() | ||
.set_sort(true) | ||
.inline_selections(!self.no_inline); | ||
let mut input = OrderList::with_theme(&theme); | ||
|
||
input | ||
.with_prompt(&self.message) | ||
.paged(self.paged) | ||
.clear(true) | ||
.items(&self.items); | ||
|
||
let value = input.interact()?; | ||
|
||
for i in value { | ||
println!("{}", self.items[i]); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters