-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from romancitodev/refactor/core
feat: 💄 refactored totally UI and functionality
- Loading branch information
Showing
17 changed files
with
505 additions
and
351 deletions.
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
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 |
---|---|---|
@@ -1,22 +1,18 @@ | ||
use inquire::ui::{Attributes, Color, RenderConfig, StyleSheet, Styled}; | ||
use promptuity::themes::FancyTheme; | ||
use promptuity::{Promptuity, Term, Terminal, Theme}; | ||
|
||
/// Generates the config for the TUI | ||
/// | ||
/// Returns a [`RenderConfig`] from the inquire TUI. | ||
pub fn generate_tui_config<'config>() -> RenderConfig<'config> { | ||
let prefix = Styled::new("").with_fg(Color::White); | ||
let selected = Styled::new("►").with_fg(Color::DarkGrey); | ||
let skipped = Styled::new("*skipped*").with_fg(Color::DarkGrey); | ||
let option = StyleSheet::empty().with_fg(Color::DarkGrey); | ||
let selected_option = StyleSheet::empty().with_fg(Color::Grey); | ||
let msg = StyleSheet::empty() | ||
.with_fg(Color::DarkGrey) | ||
.with_attr(Attributes::BOLD); | ||
RenderConfig::default_colored() | ||
.with_prompt_prefix(prefix) | ||
.with_highlighted_option_prefix(selected) | ||
.with_selected_option(Some(selected_option)) | ||
.with_option(option) | ||
.with_canceled_prompt_indicator(skipped) | ||
.with_help_message(msg) | ||
pub fn generate_prompt<'a, W>( | ||
term: &'a mut dyn Terminal<W>, | ||
theme: &'a mut dyn Theme<W>, | ||
) -> Promptuity<'a, W> | ||
where | ||
W: std::io::Write, | ||
{ | ||
Promptuity::new(term, theme) | ||
} | ||
pub fn generate_config() -> (Term<std::io::Stderr>, FancyTheme) { | ||
(Term::default(), FancyTheme::default()) | ||
} |
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,32 +1,7 @@ | ||
use std::error::Error; | ||
|
||
use inquire::list_option::ListOption; | ||
use inquire::validator::Validation; | ||
|
||
type ValidationError = Box<dyn Error + Send + Sync>; | ||
|
||
use crate::gen::Emoji; | ||
|
||
use crate::tui::structs::Commit; | ||
|
||
pub fn format_emojis(list: ListOption<&Emoji>) -> String { | ||
let Emoji { emoji, .. } = list.value; | ||
let correct = '\u{2705}'; | ||
format!("{emoji} | {correct}") | ||
} | ||
|
||
pub fn format_commits(list: ListOption<&Commit<'_>>) -> String { | ||
let Commit { label, .. } = list.value; | ||
let correct = '\u{2705}'; | ||
format!("{label} | {correct}") | ||
} | ||
|
||
pub fn valid_length(text: &str) -> Result<Validation, ValidationError> { | ||
if !text.is_empty() { | ||
Ok(Validation::Valid) | ||
pub fn valid_length(text: &str, min: usize, msg: &str) -> Result<(), String> { | ||
if text.len() > min { | ||
Ok(()) | ||
} else { | ||
Ok(Validation::Invalid( | ||
"Commit must contain 1 letter at least".into(), | ||
)) | ||
Err(msg.to_owned()) | ||
} | ||
} |
Oops, something went wrong.