mirror of
https://github.com/nushell/reedline.git
synced 2024-09-11 15:55:50 +03:00
Add const to some new functions. (#555)
* Add const to some new functions. * Add const to SearchFilter builders. * Add const to SearchQuery builders.
This commit is contained in:
parent
781e73a2be
commit
31743c8488
@ -27,7 +27,7 @@ impl Default for Editor {
|
|||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
/// Get the current [`LineBuffer`]
|
/// Get the current [`LineBuffer`]
|
||||||
pub fn line_buffer(&self) -> &LineBuffer {
|
pub const fn line_buffer(&self) -> &LineBuffer {
|
||||||
&self.line_buffer
|
&self.line_buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ impl EditMode for Emacs {
|
|||||||
|
|
||||||
impl Emacs {
|
impl Emacs {
|
||||||
/// Emacs style input parsing constructor if you want to use custom keybindings
|
/// Emacs style input parsing constructor if you want to use custom keybindings
|
||||||
pub fn new(keybindings: Keybindings) -> Self {
|
pub const fn new(keybindings: Keybindings) -> Self {
|
||||||
Emacs { keybindings }
|
Emacs { keybindings }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ pub struct SearchFilter {
|
|||||||
/// Filter whether the command completed
|
/// Filter whether the command completed
|
||||||
pub exit_successful: Option<bool>,
|
pub exit_successful: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SearchFilter {
|
impl SearchFilter {
|
||||||
/// Create a search filter with a [`CommandLineSearch`]
|
/// Create a search filter with a [`CommandLineSearch`]
|
||||||
pub fn from_text_search(cmd: CommandLineSearch) -> SearchFilter {
|
pub fn from_text_search(cmd: CommandLineSearch) -> SearchFilter {
|
||||||
@ -61,8 +62,9 @@ impl SearchFilter {
|
|||||||
s.command_line = Some(cmd);
|
s.command_line = Some(cmd);
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
/// No filter constraint
|
/// No filter constraint
|
||||||
pub fn anything() -> SearchFilter {
|
pub const fn anything() -> SearchFilter {
|
||||||
SearchFilter {
|
SearchFilter {
|
||||||
command_line: None,
|
command_line: None,
|
||||||
not_command_line: None,
|
not_command_line: None,
|
||||||
@ -106,8 +108,9 @@ impl SearchQuery {
|
|||||||
filter: SearchFilter::from_text_search(CommandLineSearch::Substring(contains)),
|
filter: SearchFilter::from_text_search(CommandLineSearch::Substring(contains)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the most recent entry matching [`SearchFilter`]
|
/// Get the most recent entry matching [`SearchFilter`]
|
||||||
pub fn last_with_search(filter: SearchFilter) -> SearchQuery {
|
pub const fn last_with_search(filter: SearchFilter) -> SearchQuery {
|
||||||
SearchQuery {
|
SearchQuery {
|
||||||
direction: SearchDirection::Backward,
|
direction: SearchDirection::Backward,
|
||||||
start_time: None,
|
start_time: None,
|
||||||
@ -118,14 +121,16 @@ impl SearchQuery {
|
|||||||
filter,
|
filter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the most recent entry starting with the `prefix`
|
/// Get the most recent entry starting with the `prefix`
|
||||||
pub fn last_with_prefix(prefix: String) -> SearchQuery {
|
pub fn last_with_prefix(prefix: String) -> SearchQuery {
|
||||||
SearchQuery::last_with_search(SearchFilter::from_text_search(CommandLineSearch::Prefix(
|
SearchQuery::last_with_search(SearchFilter::from_text_search(CommandLineSearch::Prefix(
|
||||||
prefix,
|
prefix,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Query to get all entries in the given [`SearchDirection`]
|
/// Query to get all entries in the given [`SearchDirection`]
|
||||||
pub fn everything(direction: SearchDirection) -> SearchQuery {
|
pub const fn everything(direction: SearchDirection) -> SearchQuery {
|
||||||
SearchQuery {
|
SearchQuery {
|
||||||
direction,
|
direction,
|
||||||
start_time: None,
|
start_time: None,
|
||||||
|
@ -16,7 +16,7 @@ pub struct HistoryCursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryCursor {
|
impl HistoryCursor {
|
||||||
pub fn new(query: HistoryNavigationQuery) -> HistoryCursor {
|
pub const fn new(query: HistoryNavigationQuery) -> HistoryCursor {
|
||||||
HistoryCursor {
|
HistoryCursor {
|
||||||
query,
|
query,
|
||||||
current: None,
|
current: None,
|
||||||
|
@ -6,7 +6,7 @@ use std::{fmt::Display, time::Duration};
|
|||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct HistoryItemId(pub(crate) i64);
|
pub struct HistoryItemId(pub(crate) i64);
|
||||||
impl HistoryItemId {
|
impl HistoryItemId {
|
||||||
pub(crate) fn new(i: i64) -> HistoryItemId {
|
pub(crate) const fn new(i: i64) -> HistoryItemId {
|
||||||
HistoryItemId(i)
|
HistoryItemId(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ impl Display for HistoryItemId {
|
|||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct HistorySessionId(pub(crate) i64);
|
pub struct HistorySessionId(pub(crate) i64);
|
||||||
impl HistorySessionId {
|
impl HistorySessionId {
|
||||||
pub(crate) fn new(i: i64) -> HistorySessionId {
|
pub(crate) const fn new(i: i64) -> HistorySessionId {
|
||||||
HistorySessionId(i)
|
HistorySessionId(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ impl Default for StyledText {
|
|||||||
|
|
||||||
impl StyledText {
|
impl StyledText {
|
||||||
/// Construct a new `StyledText`
|
/// Construct a new `StyledText`
|
||||||
pub fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self { buffer: vec![] }
|
Self { buffer: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ pub struct PromptHistorySearch {
|
|||||||
|
|
||||||
impl PromptHistorySearch {
|
impl PromptHistorySearch {
|
||||||
/// A constructor to create a history search
|
/// A constructor to create a history search
|
||||||
pub fn new(status: PromptHistorySearchStatus, search_term: String) -> Self {
|
pub const fn new(status: PromptHistorySearchStatus, search_term: String) -> Self {
|
||||||
PromptHistorySearch {
|
PromptHistorySearch {
|
||||||
status,
|
status,
|
||||||
term: search_term,
|
term: search_term,
|
||||||
|
@ -104,7 +104,7 @@ impl DefaultPrompt {
|
|||||||
/// Constructor for the default prompt, which takes a configurable left and right prompt.
|
/// Constructor for the default prompt, which takes a configurable left and right prompt.
|
||||||
/// For less customization, use [`DefaultPrompt::default`].
|
/// For less customization, use [`DefaultPrompt::default`].
|
||||||
/// For more fine-tuned configuration, implement the [`Prompt`] trait.
|
/// For more fine-tuned configuration, implement the [`Prompt`] trait.
|
||||||
pub fn new(
|
pub const fn new(
|
||||||
left_prompt: DefaultPromptSegment,
|
left_prompt: DefaultPromptSegment,
|
||||||
right_prompt: DefaultPromptSegment,
|
right_prompt: DefaultPromptSegment,
|
||||||
) -> DefaultPrompt {
|
) -> DefaultPrompt {
|
||||||
|
Loading…
Reference in New Issue
Block a user