Skip to content

Commit

Permalink
trim _string
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Feb 18, 2024
1 parent 33c1bc8 commit 057cb50
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/core/text_editor/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ pub struct Renderer {
pub suggest: Suggest,

/// Prompt string displayed before the input text.
pub ps: String,
pub prefix: String,
/// Optional character used for masking the input string (e.g., for password fields).
pub mask: Option<char>,

/// Style applied to the prompt string.
pub ps_style: ContentStyle,
pub prefix_style: ContentStyle,
/// Style applied to the currently selected character.
pub active_char_style: ContentStyle,
/// Style applied to characters that are not currently selected.
Expand All @@ -50,7 +50,10 @@ pub struct Renderer {
impl Renderable for Renderer {
fn make_pane(&self, width: u16) -> Pane {
let mut buf = Graphemes::default();
buf.append(&mut Graphemes::new_with_style(&self.ps, self.ps_style));
buf.append(&mut Graphemes::new_with_style(
&self.prefix,
self.prefix_style,
));

let text = match self.mask {
Some(mask) => self.texteditor.masking(mask),
Expand Down
12 changes: 6 additions & 6 deletions src/preset/queryselect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ impl QuerySelect {
texteditor: Default::default(),
history: None,
suggest: Default::default(),
ps: String::from("❯❯ "),
prefix: String::from("❯❯ "),
mask: None,
ps_style: Style::new().fgc(Color::DarkGreen).build(),
prefix_style: Style::new().fgc(Color::DarkGreen).build(),
active_char_style: Style::new().bgc(Color::DarkCyan).build(),
inactive_char_style: Style::new().build(),
edit_mode: Default::default(),
Expand Down Expand Up @@ -99,14 +99,14 @@ impl QuerySelect {
}

/// Sets the prefix string displayed before the input text in the text editor component.
pub fn prefix_string<T: AsRef<str>>(mut self, ps: T) -> Self {
self.text_editor_renderer.ps = ps.as_ref().to_string();
pub fn prefix<T: AsRef<str>>(mut self, prefix: T) -> Self {
self.text_editor_renderer.prefix = prefix.as_ref().to_string();
self
}

/// Sets the style for the prefix string in the text editor component.
pub fn prefix_string_style(mut self, style: ContentStyle) -> Self {
self.text_editor_renderer.ps_style = style;
pub fn prefix_style(mut self, style: ContentStyle) -> Self {
self.text_editor_renderer.prefix_style = style;
self
}

Expand Down
12 changes: 6 additions & 6 deletions src/preset/readline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ impl Default for Readline {
texteditor: Default::default(),
history: Default::default(),
suggest: Default::default(),
ps: String::from("❯❯ "),
prefix: String::from("❯❯ "),
mask: Default::default(),
ps_style: Style::new().fgc(Color::DarkGreen).build(),
prefix_style: Style::new().fgc(Color::DarkGreen).build(),
active_char_style: Style::new().bgc(Color::DarkCyan).build(),
inactive_char_style: Style::new().build(),
edit_mode: Default::default(),
Expand Down Expand Up @@ -91,8 +91,8 @@ impl Readline {
}

/// Sets the prefix string displayed before the input text.
pub fn prefix_string<T: AsRef<str>>(mut self, ps: T) -> Self {
self.text_editor_renderer.ps = ps.as_ref().to_string();
pub fn prefix<T: AsRef<str>>(mut self, prefix: T) -> Self {
self.text_editor_renderer.prefix = prefix.as_ref().to_string();
self
}

Expand All @@ -103,8 +103,8 @@ impl Readline {
}

/// Sets the style for the prefix string.
pub fn prefix_string_style(mut self, style: ContentStyle) -> Self {
self.text_editor_renderer.ps_style = style;
pub fn prefix_style(mut self, style: ContentStyle) -> Self {
self.text_editor_renderer.prefix_style = style;
self
}

Expand Down
2 changes: 1 addition & 1 deletion src/preset/readline/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Confirm {
pub fn new<T: AsRef<str>>(text: T) -> Self {
Self(
Readline::default()
.prefix_string(format!("{} (y/n) ", text.as_ref()))
.prefix(format!("{} (y/n) ", text.as_ref()))
.validator(
|text| -> bool {
["yes", "no", "y", "n", "Y", "N"]
Expand Down

0 comments on commit 057cb50

Please sign in to comment.