Skip to content
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

Add support for limit_chars argument for ReadlineEdit. #18

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

zee-bit
Copy link
Contributor

@zee-bit zee-bit commented Apr 8, 2021

There may be several use-cases, where you want to restrict the user input into a ReadlineEdit widget to not go beyond a particular limit, this PR makes it possible for clients to specify a max_char argument when initializing a ReadlineEdit widget so that the user can't input text beyond that limit.
In particular zulip-terminal has such a use-case, where it needs ReadlineEdit widgets for stream and topic to only accept input up to 60 characters.

Relevant discussion:

This commit:
- Adds a new parameter argument 'max_char' to ReadlineEdit
that restricts adding character beyond the limit in the Edit
widget.
- Prevents initializing of Edit widget with an edit_text longer
than provided limit_char, by slicing the extra part.
- Allow pasting text only upto the limit specified in the above
parameter.
- Adds test for _insert_char_at_cursor.

Tests amended.
@rr- rr- merged commit d311ab5 into rr-:master Apr 8, 2021
@rr-
Copy link
Owner

rr- commented Apr 8, 2021

Thanks, released as 0.13

@neiljp
Copy link
Collaborator

neiljp commented Apr 8, 2021

@rr- Thanks for the merge - I also think this could be good upstream depending on the activity there, though would still need integration here in terms of the other commands like paste?

@rr-
Copy link
Owner

rr- commented Apr 9, 2021

Unfortunately I don't understand the question.
BTW @neiljp I invited you as a collaborator. Later on we can think of a way to let you publish new versions through GitHub actions.

@neiljp
Copy link
Collaborator

neiljp commented Apr 10, 2021

@rr- I meant whether this feature belongs in urwid.Edit or similar, as a max-length could be a more fundamental property. However, I'm not sure how active upstream urwid is, or if they'd accept it - and urwid-readline would still need to handle situations like the paste case that is specific to this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants