You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I'm trying to use your cli which is very nice tool but I'm having a problem. When I'm pasting a text, it is being reduced. For example if I paste CSLAD00000334, the cli return CSLAD0000033. The weird thing is that if I press space, the last character appears. Can anyone help me with this issue?
Where exactly are you pasting the text ? Is it in an input ? If so, which one ?
Are you experiencing the same issue if you try pasting something shorter ?
hey @ptykamikaze sorry for the very late reply. This is an interesting problem and I'm not sure what the solution should be. I never considered pasting in to the field when building this. I think the best way to solve this might be to PR a failing test case highlighting the issue and then we can discuss and figure out a solution.
While your solution does work for your use case, any pasted string over 30 chars would still result in trimming.
I've run into the same problem with the current 4.3.0 release. It looks like the issue is that NonCanonicalReader consumes input in 4 character chunks. If you paste a line that is not divisible by 4, it waits for further input. For some reason that doesn't happen while typing, though. In fact, typing a regular non-control character (like space or a letter) will cause the remainder letters to appear followed by the regular non-control character. If you type a control character, like enter, after pasting a string that is not divisible by four the control character is ignored and the remainder characters are lost. Pressing enter a second time will then close the input and process the truncated value.
I've experimented a little further with this, and this is interesting, the processing bug only appears on the second or later block of pasted text, according to the length specified in the NonCanonicalReader.php file in the terminal library. If you paste a three character string, it always works, but if you paste 5 or longer and it's not divisible by 4, you get one of the buggy interactions. If you increase the size of the read call in NonCanonicalReader.php the string now has to be divisible by the new value to work.
I think the issue is with the fread call in ResourceInputStream.php. It looks like fread is blocking on the final call because not enough data is ready to continue. If there are between 1 and 3 leftover characters, it blocks until new input triggers it to run again.
Yeah I am not sure how to solve this, we need to read more than 1 char because from what I remember some control sequences come through as more than one char.
I've been poking around the stream reading documentation for PHP, and it seems like there are three possible solutions:
Boost the read size to a very large number (8192, for example) so that any legitimately sized input should be read in the first fread.
Use fgets to get input one line at a time for inputs.
Turn off blocking on stdin when data is read, and turn it back on when no more data is left.
The third option seems simplest, most scalable, and in testing fixes the problem. It requires a small change to ResourceInputStream.php in the terminal library.
After using the patched code for a bit, I discovered that I had unintentionally created a side effect where the blocking status of the input stream could be changed. I've submitted an new pull request with a new commit that saves the initial blocking status and restores that status when the stream object is destroyed.
Activity
Lynesth commentedon Aug 3, 2018
Hey there,
Where exactly are you pasting the text ? Is it in an input ? If so, which one ?
Are you experiencing the same issue if you try pasting something shorter ?
ptykamikaze commentedon Aug 3, 2018
Hello. I'm using this method to generate an input
Temporally, I have modified this file "NonCanonicalReader.php", line 64, to allow up to 30 characters and for the moment it is working...
$char = $this->terminal->read(30);Thanks for your quick response...
AydinHassan commentedon Sep 4, 2018
hey @ptykamikaze sorry for the very late reply. This is an interesting problem and I'm not sure what the solution should be. I never considered pasting in to the field when building this. I think the best way to solve this might be to PR a failing test case highlighting the issue and then we can discuss and figure out a solution.
While your solution does work for your use case, any pasted string over 30 chars would still result in trimming.
tbannister commentedon Jan 6, 2023
I've run into the same problem with the current 4.3.0 release. It looks like the issue is that NonCanonicalReader consumes input in 4 character chunks. If you paste a line that is not divisible by 4, it waits for further input. For some reason that doesn't happen while typing, though. In fact, typing a regular non-control character (like space or a letter) will cause the remainder letters to appear followed by the regular non-control character. If you type a control character, like enter, after pasting a string that is not divisible by four the control character is ignored and the remainder characters are lost. Pressing enter a second time will then close the input and process the truncated value.
Examples:
tbannister commentedon Jan 6, 2023
I've experimented a little further with this, and this is interesting, the processing bug only appears on the second or later block of pasted text, according to the length specified in the NonCanonicalReader.php file in the terminal library. If you paste a three character string, it always works, but if you paste 5 or longer and it's not divisible by 4, you get one of the buggy interactions. If you increase the size of the read call in NonCanonicalReader.php the string now has to be divisible by the new value to work.
tbannister commentedon Jan 6, 2023
I think the issue is with the fread call in ResourceInputStream.php. It looks like fread is blocking on the final call because not enough data is ready to continue. If there are between 1 and 3 leftover characters, it blocks until new input triggers it to run again.
AydinHassan commentedon Jan 7, 2023
Yeah I am not sure how to solve this, we need to read more than 1 char because from what I remember some control sequences come through as more than one char.
tbannister commentedon Jan 9, 2023
I've been poking around the stream reading documentation for PHP, and it seems like there are three possible solutions:
The third option seems simplest, most scalable, and in testing fixes the problem. It requires a small change to ResourceInputStream.php in the terminal library.
AydinHassan commentedon Jan 9, 2023
@tbannister nice investigation, go for it, hopefully the test suite should highlight any issues :)
tbannister commentedon Jan 9, 2023
A pull request has been submitted to terminal.
tbannister commentedon Jan 11, 2023
After using the patched code for a bit, I discovered that I had unintentionally created a side effect where the blocking status of the input stream could be changed. I've submitted an new pull request with a new commit that saves the initial blocking status and restores that status when the stream object is destroyed.
AydinHassan commentedon Jan 11, 2023
I've merged it 🙂