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

Working fix for #108 #173

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

FelixSelter
Copy link

@FelixSelter FelixSelter commented May 27, 2023

Currently console only reads input from stdin. However a ReadWritePair option has already been added. Unfortunately only writing works for ReadWritePair. This PR adds functionality for a custom input source.
See issue #108
See other (I think incomplete) pr addressing this issue: #123
This would complete the work of #93

Therefore the following lines have been changed:

ReadWritePair was also modified. Previously it required an input source of type Read (enables reading of bytes)
This has been changed to an iterator over Keys because Keys are a cross platform solution. Else we would need to parse the input differently depending on the os of the user. Now the user has a nice interface for defining his own input source.

Functionality may be expanded in the future to support more keys, or to automatically convert something like Key::Char('\n') to Key::Enter or at least warn the user.
This pr should be a good start adding an essential feature.
Please take a look at the commits from last to newest. They contain a description of what has been changed.

I enabled ReadWritePair for other platforms that are not unix by removing any `#[cfg(unix)]`. I also updated TermRead to be an Iterator over Keys and not bytes. This gurantees a cross platform read of keys because they differ between wasm, unix and windows.
Its better to have only one place that checks if the TermTarget is a ReadWritePair instead of having them everywhere in the code. As the way input is read is determined by the TermTarget it made sense to move it there. I still need to implement the functionality for a ReadWritePairSource though
… Keys into utf8

Renamed fields to clarify their new purpose.
The utility function keys_to_utf8 will handle converting BackSpaces and Enter keys. Other functionality like arrow keys and delete may be implemented in the future
Maybe the errors need to be changed?
io::ErrorKind::ResourceBusy requires to add the: #![feature(io_error_more)] attribute
…capacity and dropping long unicode chars

This is required by the Read trait implementation
@mitsuhiko
Copy link
Collaborator

This PR looks generally promising but has significant conflicts against master.

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

2 participants