[io::Stdin] Read more than 1024 characters at a time


#1

I’m using io::Stdin to read input interactively, but when I try to copy a relatively large input to my interactive program, only the first 1024 characters appear. If I don’t erase the last character, it won’t even append the EOF when I press enter.
What I’d like to do here is to paste the entire text, not just the first 1024 characters of it.

Specifically I’ve tried both Stdin.read_line() and explicitly acquiring a StdinLock, then reading from that. Both yield the same result described above.

I’m not sure if it’s relevant, but I’m using OS X.


#2

I think this is a limitation of the tty driver’s internal buffer - it’s capped at 1024 bytes. This buffer is to allow interactive editing of the text before writing it to the stdin pipe. OS X looks to cap this at 1024, linux at 4096. So you probably want to feed the input to your program via a pipe or file, rather than via a terminal.


#3

Oh wow, that’s an unexpected creak of Ye Olde TTY sub-system system popping up.
Perhaps it’s truly time to replace the whole TTY system then :slight_smile:

Just for fun, here’s a short, non-exhaustive list of reasons:

  • It’s old, and supports standards that don’t reflect 2017-usage
  • It’s slow
  • It has some cryptic and rather arbitrary limitations

#4

Indeed, legacy stuff :slight_smile:.

By the way, here’s one of the OSv/seastar devs explaining it and also mentioning that in OSv they did not implement it with a fixed size buffer.


#5

That immediately also points to an important pragmatic issue: even if I were to say “ok I’ll start writing a replacement”, I can’t fully undo this precisely because it is rooted in OS/kernel level functionality.
That is, I can write something that looks and acts like a terminal emulator in every desirable way (and not at all in others), but ultimately it wouldn’t be able to lift this limit.