New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user to manually input a date #4
Comments
Yes, it would be great. E.g, I prefer
When moving through data parts, are arrow up and down supported? To increase/decrease the currently selected data part? I remember seeing it somewhere and it looked helpful. |
Yes, up and down arrows work to move around the candelar (the main demo shows this iirc). It is implemented by simply subtracting/adding a week from the current selected date. |
There's going to be an API to customize there for sure. Do you think this would be a good idea for the default format? On one hand, it is the ISO8601, the standard, etc, which makes it a sensible choice for developers. However, I can't quite see it being the best default option for end users, probably (mostly) developers but I for one would prefer other formats. I'm considering making dd/mm/yyyy the default. |
I'm fine your default. While there is a way to set any format to display a date ;)
Just a thought: it should be possible to disable automatic displaying calendar(if it is not implemented) when editing a date field. On the other hand, calendar makes it easier to move by weeks :) I wonder if it is possible to make calendar hidden by default, but to provide a hotkey to open it? |
I think I just now realized what you meant with your first comment, moving around the actual text input (and not the calendar!) That makes a lot of sense and it is an use-case I hadn't considered before. Making the calendar work alongside text input (with these features), while providing a good UX with hotkeys would be very hard. I also enjoyed the idea of hiding/disabling the calendar, like two "modes" that could be swapped. Mode A:
Mode B
wdyt? |
Yes, that what I meant. But I used that type of edit field in GUI application. In TUI it may be harder to implement but should be feasible. The idea sounds good to me. If edit field always displays cursor (I think in mode B it shows the text cursor always), it is clear what part of the date is selected even without highlighting its background. So, to me changing background is an optional feature. Date edit fields is usable without it as well. |
@VladimirMarkelov what do you think of the following prompt and its API? It uses the newly-added placeholder feature. From the top of my head, we are missing:
use chrono::NaiveDate;
use inquire::{formatter::DEFAULT_DATE_FORMATTER, CustomType};
fn main() {
let amount = CustomType::<NaiveDate>::new("When are you going to visit the office?")
.with_placeholder("dd/mm/yyyy")
.with_parser(&|i| NaiveDate::parse_from_str(i, "%d/%m/%Y").map_err(|_| ()))
.with_formatter(DEFAULT_DATE_FORMATTER)
.with_error_message("Please type a valid date.")
.with_help_message("The necessary arrangements will be made")
.prompt();
match amount {
Ok(_) => println!("Thanks! We will be expecting you."),
Err(_) => println!("We could not process your reservation"),
}
} |
It looks great! Two questions:
|
Unfortunately nothing was done automatically, I believe I just typed the slashes really quicksly so I'll take that as a compliment ;) The greyed-out placeholder is just that, a placeholder. There are no masks implemented in the What would you think of an API that would allow you to customize the input state before/after a key was pressed? Like this for exmaple: https://stackoverflow.com/questions/12578507/implement-an-input-with-a-mask. This way, you could hook a couple callbacks that would receive the current This would allow you to autoamtically insert/remove slashes or implement any custom behavior you might want for your prompts. |
Closing this, I think the last example I showed provides very good building blocks for those that do want to pursue this kind of customization. Additionally, users can also use the Text prompt to parse+validate the input and do all sorts of things with free text input. |
Is your feature request related to a problem? Please describe.
The user might not want to manually navigate through several days/months/years when trying to input a date. Imagine a birthday for example.
We have shortcuts in place for this, in which ctrl+arrows quickly move by months or years, but it could be better
Describe the solution you'd like
Not sure yet...
Option 0
A new prompt type where instead of a calendar, we display the three date parts (month, date, year) in a customizable order with customizable separators.
The end user can then move around each one of them pressing left or right arrows, and then press up or down to update the values.
Option 1
The user can type a full date in a predefined format, e.g. dd/mm/yyyy and submit. The prompt handler should then try to parse this input and if successful, return the parsed value.
The submit button could be a new shortcut, e.g. Ctrl+Enter, or the same Enter.
Maybe we could do the following:
It would be nice if the expected input format was written in grey where the input would be, something like:
? Travel date: 12/0m/yyyy
Option 2
I tried to think of a "filter" approach, like typing a month or year and then the calendar would jump right on that, but didn't get to a reasonable solution.
The text was updated successfully, but these errors were encountered: