-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format options are set in the string itself.
`header` and `table` options are now part of the format string, instead of fields of the builtin state.
- Loading branch information
Showing
10 changed files
with
154 additions
and
50 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
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,81 @@ | ||
//! Extract options from a format string. | ||
|
||
#[cfg_attr(test, derive(PartialEq, Debug))] | ||
pub struct FormatOptions<'a> { | ||
pub header: bool, | ||
pub table: bool, | ||
pub format: &'a str, | ||
} | ||
|
||
impl FormatOptions<'_> { | ||
pub fn parse(mut format: &str) -> FormatOptions { | ||
let mut header = false; | ||
let mut table = false; | ||
|
||
if format.starts_with('[') { | ||
if let Some(end) = format.find(']') { | ||
let (options, fmt) = format[1..].split_at(end - 1); | ||
format = &fmt[1..]; | ||
|
||
for option in options.split(',') { | ||
match option { | ||
"header" => header = true, | ||
"table" => table = true, | ||
o => bash_builtins::warning!("'{}': invalid format option.", o), | ||
} | ||
} | ||
} | ||
} | ||
|
||
FormatOptions { | ||
header, | ||
table, | ||
format, | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn parse_options() { | ||
assert_eq!( | ||
FormatOptions::parse("abc"), | ||
FormatOptions { | ||
header: false, | ||
table: false, | ||
format: "abc" | ||
} | ||
); | ||
|
||
assert_eq!( | ||
FormatOptions::parse("[header]abc"), | ||
FormatOptions { | ||
header: true, | ||
table: false, | ||
format: "abc" | ||
} | ||
); | ||
|
||
assert_eq!( | ||
FormatOptions::parse("[table,header]abc"), | ||
FormatOptions { | ||
header: true, | ||
table: true, | ||
format: "abc" | ||
} | ||
); | ||
|
||
assert_eq!( | ||
FormatOptions::parse("[]abc"), | ||
FormatOptions { | ||
header: false, | ||
table: false, | ||
format: "abc" | ||
} | ||
); | ||
} | ||
|
||
#[cfg(test)] | ||
mod mock_bash_fns { | ||
#[no_mangle] | ||
extern "C" fn builtin_warning(_: *const libc::c_char) {} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
load_builtin | ||
|
||
timehistory -s format='%n' | ||
|
||
/bin/true | ||
test -n "$(timehistory)" | ||
|
||
|
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