What Should the Console Do If You Type Too Fast During Startup?

So these days, stdio is an extension, it is loaded late in the boot. You can build the interpreter without stdio to use in a non-interactive library. Or you can replace it entirely, as the Web Repl does.

But for the moment let's talk about the standard-stdio...

One of the things it does is that if you're not redirecting input, it switches over from the so-called "cooked mode" of reading a line at a time to "raw mode", where you can manage each keystroke. So that's why you can process cursor keys, or tab, or if you wanted to make it so when people typed A they saw B, etc.

But for the duration of the time between when the program starts and when the extension gets run, it's still in cooked mode.

So if you type some stuff and it hasn't quite finished loading, it will be echoed. I didn't realize this because I was running a program that didn't print a boot banner, and it just had an empty line and I started typing into it.

$ r3 readline-test.r
aa   ; I only typed a

I'd type a and see it. Then after a small delay, it would print another one so that the line said "aa".

Took some time for me to realize what was happening. Shouldn't have taken that long but it did, because I was focusing on the wrong thing.

How To React to This?

It's tempting to try and build some kind of compensation for that, where you query the input buffer at the exact moment the switch is flipped from cooked to raw mode. You assume in that moment that if any input is in the buffer, it must have come during the cooked mode...and has already been printed...

But that's not a general solution. If your console has made it so when you type A you should get B then leaving the A there from the input buffer and saying "it was echoed already" isn't correct.

Not only that, you run into trouble if there's any printing before you read. The text would be above the output, so it wouldn't even be seen.

So I think you just throw out a message so people know what's going on, and kick over to a newline:

$ r3 readline-test.r
abc[you typed too fast!]
abc

Suggestions Welcome On What to Print

We can actually print the message in a different style in the smart terminal, with a weird background color or something.

  • [rebuffering] <- it was the first thing I thought of, which doesn't make it good

  • [catching up with queued typing] <- clear but lengthy

  • [catching up...] <- not as clear, shorter

  • ???

[Keyboard now ready]

Just for brainstorming...

"Not so fast Grasshopper"

Ready