Skip to content

Commit

Permalink
Added confirm_yes_strings and confirm_no_strings opts in Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrieleInvernizzi committed Jan 3, 2025
1 parent 3cda4bc commit 3acd1bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Themes/SimpleTheme.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const opts: Options = .{
.confirm_invalid_msg = "The only valid values are: y/yes and n/no, case insensitive",
.option_aborted_msg = "Selection aborted",
.passwd_echo_indicator = true,
.passwd_indicator = '*'
.passwd_indicator = '*',
.confirm_yes_strings = &[_][]const u8{"y", "yes"},
.confirm_no_strings = &[_][]const u8{"n", "no"},
};

const vtable: VTable = .{
Expand Down
4 changes: 4 additions & 0 deletions src/Themes/Theme.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub const Options = struct {
passwd_echo_indicator: bool,
/// The indicator char that will used in the password prompt.
passwd_indicator: u8,
/// Slice of strings that are to be treated by the confirm prompt as affermative (case insensitive).
confirm_yes_strings: []const []const u8,
/// Slice of strings that are to be treated by the confirm prompt as negative (case insensitive).
confirm_no_strings: []const []const u8,
};

/// Stores all the format functions used in the `Theme` struct.
Expand Down
5 changes: 1 addition & 4 deletions src/prompt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ pub fn stringValidated(self: *Self, prompt: []const u8, default: ?[]const u8, va
pub fn confirm(self: *Self, prompt: []const u8) !bool {
const out = std.io.getStdOut().writer();

const yes_strings = [_][]const u8{ "y", "yes" };
const no_strings = [_][]const u8{ "n", "no" };

while (true) {
const str = try self.string(prompt, null);
const ret = utils.parse_confirmation(str, &yes_strings, &no_strings) catch {
const ret = utils.parse_confirmation(str, self.theme.opts.confirm_yes_strings, self.theme.opts.confirm_no_strings) catch {
try out.print("{s}\n", .{self.theme.opts.confirm_invalid_msg});
self.allocator.free(str);
continue;
Expand Down

0 comments on commit 3acd1bd

Please sign in to comment.