-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
575 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
use crate::loader::Script; | ||
|
||
pub fn load_scripts() -> Vec<Script> { | ||
vec![ | ||
Script { | ||
id: 1, | ||
script: "build", | ||
command: "tsc", | ||
}, | ||
Script { | ||
id: 2, | ||
script: "build:watch", | ||
command: "tsc -w", | ||
}, | ||
Script { | ||
id: 3, | ||
script: "style", | ||
command: "npm run style:format && npm run style:lint", | ||
}, | ||
Script { | ||
id: 4, | ||
script: "style:format", | ||
command: "prettier --write \"src/**/*.ts\"", | ||
}, | ||
Script { | ||
id: 5, | ||
script: "style:lint", | ||
command: "eslint src --ext .js,.ts --fix", | ||
}, | ||
Script { | ||
id: 6, | ||
script: "install:g", | ||
command: "npm run build && npm i -g", | ||
}, | ||
] | ||
} |
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,7 @@ | ||
// Re-export public API. | ||
pub use script::Script; | ||
pub use loader::load_scripts; | ||
|
||
// Private modules. | ||
mod loader; | ||
mod script; |
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,14 @@ | ||
use std::fmt::{Display, Formatter, Result}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Script { | ||
pub id: usize, | ||
pub script: &'static str, | ||
pub command: &'static str, | ||
} | ||
|
||
impl Display for Script { | ||
fn fmt(&self, writer: &mut Formatter<'_>) -> Result { | ||
write!(writer, "{} {}", self.script, self.command) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,15 @@ | ||
mod loader; | ||
mod prompt; | ||
|
||
use prompt::{Prompt, SelectPrompt}; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let options = loader::load_scripts(); | ||
let mut prompt = SelectPrompt::new("Pick a script to execute", options, 64); | ||
|
||
match prompt.run() { | ||
| Ok(Some(item)) => println!("Executing: {} {}", item.script, item.command), | ||
| Ok(None) => println!("Nothing was picked. Bye!"), | ||
| Err(error) => println!("Oof, something happened: {:?}", error), | ||
} | ||
} |
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,25 @@ | ||
pub trait Prompt<T> { | ||
fn run(&mut self) -> std::result::Result<Option<T>, crossterm::ErrorKind>; | ||
fn render(&mut self) -> crossterm::Result<()>; | ||
fn handle(&mut self, event: crossterm::event::KeyEvent); | ||
} | ||
|
||
#[derive(Eq, PartialEq, Debug)] | ||
pub enum State { | ||
Created, | ||
Running, | ||
Aborted, | ||
Completed, | ||
} | ||
|
||
impl State { | ||
pub fn is_completed(&self) -> bool { | ||
*self == State::Aborted || *self == State::Completed | ||
} | ||
} | ||
|
||
impl Default for State { | ||
fn default() -> State { | ||
State::Created | ||
} | ||
} |
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,12 @@ | ||
// Re-export module public API. | ||
pub use base::{Prompt, State}; | ||
pub use select::SelectPrompt; | ||
pub use symbols::Symbols; | ||
|
||
// Private modules. | ||
mod base; | ||
mod select; | ||
mod symbols; | ||
|
||
// Public modules. | ||
pub mod utils; |
Oops, something went wrong.