Giter Club home page Giter Club logo

Comments (10)

VladimirMarkelov avatar VladimirMarkelov commented on May 17, 2024 1

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.

from inquire.

VladimirMarkelov avatar VladimirMarkelov commented on May 17, 2024

Yes, it would be great. E.g, I prefer YYYY-MM-DD format.

We have shortcuts in place for this, in which ctrl+arrows quickly move by months or years, but it could be better

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.

from inquire.

mikaelmello avatar mikaelmello commented on May 17, 2024

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.

from inquire.

mikaelmello avatar mikaelmello commented on May 17, 2024

I prefer YYYY-MM-DD format.

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.

from inquire.

VladimirMarkelov avatar VladimirMarkelov commented on May 17, 2024

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 ;)

Yes, up and down arrows work to move around the candelar

Just a thought: it should be possible to disable automatic displaying calendar(if it is not implemented) when editing a date field.
Sometimes, I do not want calendar and just want to type a date in an edit field with optional special processing of arrows. Possible case: entering a date birth. If the default value is today, using a calendar maybe be tiresome, typing is much faster. Or another case: edit a date and move it two months ahead. I think Ctrl+right to select month part, and pressing arrow up 3 times sometimes is better than using through full-featured calendar.

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?

from inquire.

mikaelmello avatar mikaelmello commented on May 17, 2024

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:

  • full-featured calendar, same as it is now
  • normal arrows to move around by day/week
  • ctrl+arrows to move around by month/year
  • some hotkey to change to mode b

Mode B

  • no calendar, text input
  • date always pre-selected to keep things simple at first
    • today by default (customizable)
  • at least one data part "selected" (background in grey)
  • move around data parts by pressing right/left arrows (do we need ctrl?)
  • update a single data part (e.g. month) by pressing up or down. value overflows/underflows without modifying other data parts

wdyt?

from inquire.

mikaelmello avatar mikaelmello commented on May 17, 2024

@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:

  • Validators once the parsing is successfully executed. In this example, could need to check for holidays or weekends.
  • Dynamic error messages for parsing errors. Not sure why I went with a static one when building CustomType.
  • Enhanced processing of key events, such as moving between date fields. However I'm feeling like that's not strictly necessary for now, as CustomType can handle a lot of our needs.
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"),
    }
}

manual_date_input

from inquire.

VladimirMarkelov avatar VladimirMarkelov commented on May 17, 2024

It looks great!

Two questions:

  • does it insert date separators automatically? I mean, a user does not have to type / in the example
  • what happens if I type with separators? E.g, what if I type 12/2 - Does / turn a "silent" keypress?

from inquire.

mikaelmello avatar mikaelmello commented on May 17, 2024
  • does it insert date separators automatically? I mean, a user does not have to type / in the example
  • what happens if I type with separators? E.g, what if I type 12/2 - Does / turn a "silent" keypress?

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 CustomType input or on any prompts with text input for that matter.

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 InputState (the string, its pre-calculated length and the cursor position, basically) and the pressed key. This callback could then mutate the input state based on the key pressed.

This would allow you to autoamtically insert/remove slashes or implement any custom behavior you might want for your prompts.

from inquire.

mikaelmello avatar mikaelmello commented on May 17, 2024

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.

from inquire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.