The check I was suggesting on whether Ctrl+C has been pressed on an empty line seems harder to implement, because get_interactive() just calls readline() or fgets(), which block to return when a whole line is ready. AFAICS psql can't know what was the edit-in-progress when these functions are interrupted by a signal instead of returning normally. But I don't think this check is essential, it could be left to another patch.
Glad I wasn't missing something obvious. I suppose we could base the behavior on whether there's at least one full line already buffered. However, I agree that it can be left to another patch.
v6 patch. highlights:
- error messages are now a bit more terse, following suggestions
- help text is more terse and Conditionals section was moved below Input Output
- leverage IFSTATE_NONE a bit to fold some not-in-a-branch cases into existing switch statements, giving flatter, slightly cleaner code and that addresses expected cases before exceptional ones
- comments highlight which messages are printed in both interactive and script mode. - put Fabien's tap test in place verbatim
- No mention of Ctrl-C or PROMPT. Those can be addressed in separate patches.
There's probably some more consensus building to do over the interactive messages and comments, and if interactive-ish tests are possible with TAP, we should add those too.