I'm struggling to write a function that asks the user to input a string, but cuts it off after they've inputted a specific amount of characters (three, for example) and moves on with the rest of the function logic.
An example use-case would be a grep function, where it asks for a pattern, but then automatically begins the grep after three characters and the remaining characters typed act as a filter.
See below for an example of the rough functionality I'm aiming for. After typing "1", "2", "3" the search is automatically executed:
I am familiar with
getchar() as a way to "fake" it by monitoring raw keypresses and echoing them back, then after three keypresses executing the function. That solution seems imperfect for a number of reasons, the biggest one being that I would have to manually handle several non-ASCII keypresses (backspace, for example) that getchar() captures.
Thank you in advance for the help!