ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.87k stars 413 forks source link

"input" example allows line breaks in phone number #908

Open psychon opened 2 months ago

psychon commented 2 months ago

Hi there,

I was looking around how to have a number-only input field in ftxui 5.0.0 and came across the input example: https://github.com/ArthurSonzogni/FTXUI/blob/5a9ef876a14b91a3cc5b0313cfdaf6b5527eccf4/examples/component/input.cpp#L34-L41

While playing around with this example, I noticed that the "Return" key is allowed to add line breaks to the telephone number. That does not feel like it is intended.

(For my own use I got rid of this by having multiline = false in the options of the input component, see https://github.com/ArthurSonzogni/FTXUI/blob/5a9ef876a14b91a3cc5b0313cfdaf6b5527eccf4/src/ftxui/component/input.cpp#L346-L349

HiperDoo commented 2 months ago

I also noticed this problem, by default it is in multiline mode (in my case it is totally inconvenient since I have many cells where parameters are filled with keywords).

But there is a simple solution without the need to edit the source code:

ftxui::InputOption input_option() {
      ftxui::InputOption option{ftxui::InputOption::Default()};
      option.multiline = false;
      return option;
  }

std::string name = "Name Example";
ftxui::Component input_field{ftxui::Input(&name, name, input_option())};