ArthurSonzogni / FTXUI

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

blinking cursor in text inputs #267

Closed kritzikratzi closed 2 years ago

kritzikratzi commented 2 years ago

as far as i understand there is currently no way to have a blinking cursor when a text input is in focus.

if i would add such a feature, what would be the way to go about it? i'm a bit lost tbh... i'm wondering if it would be possible to let the host terminal handle it, or it's necessary to draw it "by hand".

ArthurSonzogni commented 2 years ago

In src/ftxui/component/screen_interactive.cpp

If we remove the line: https://github.com/ArthurSonzogni/FTXUI/blob/cecd54df42dd66fdf8386ed461e16b725bffc827/src/ftxui/component/screen_interactive.cpp#L396

This should make the cursor to blink again.

I believe we should make the cursor to blink only when event.cursor_{x,y}() isn't (0,0) here: https://github.com/ArthurSonzogni/FTXUI/blob/master/src/ftxui/component/screen_interactive.cpp#L514

I don't fully remember why I decided not to do it. I remember I tried, but I convinced myself this wasn't good enough. I don't remember exactly why.

Here is what I get on two terminal:

https://user-images.githubusercontent.com/4759106/143498783-6b4efbbe-8b2b-43b6-808a-56111c0b2842.mp4

You can see the blinking cursor doesn't show on the right location depending on the terminal. Maybe this was the reason why I abandoned?

I accept PR of course if you want to take a look.

kritzikratzi commented 2 years ago

hi!

thx, i just tested. while it did activate the cursor it seems stuck in the bottom right cursor.

image

i'm going have to make a copy of input.cpp/input.hpp anyways because i want different background-color behavior, and i'm gonna "hand-draw" the cursor directly there (i do ~8 refreshes per second anyways, so i will survive without the terminal blinky cursor).

thx for taking the time to look into it. gonna close the report.

ps. here is what i'm working on: https://www.youtube.com/watch?v=CQUlMqh2YTc