-1

I've read answers like in:

They explained how to look for a sentinel value, or how to catch OSError, but those are not what I'm looking for. I'd like to let users insert texts just like how they type messages in Telegram, Whatsapp and etc. but in terminal!

As long as they hit shift + enter, they should be able to continue writing on the next line and when they hit enter, the input should be sent.

I guess if I can somehow insert an arbitrary character(like "#\n") to the standard input when a user presses shift + enter, I would detect and break out of the below loop:

import sys

while True:
    line = sys.stdin.readline()
    if line[-2:] == "#\n":
        break
    print(bytes(line, encoding="ascii"))

I found this similar question but its answers don't work for me.

I want it for unix-like system's terminal.

S.B
  • 13,077
  • 10
  • 22
  • 49
  • Does this answer your question? [How to read multiple lines of raw input?](https://stackoverflow.com/questions/11664443/how-to-read-multiple-lines-of-raw-input) – Abdul Aziz Barkat Aug 16 '23 at 11:13
  • @AbdulAzizBarkat No. I explained why. – S.B Aug 16 '23 at 11:16
  • The solutions on the question I linked do work on Windows. They don't use "Shift + Enter" but have an even simpler way where an empty line with enter / return ends the input. – Abdul Aziz Barkat Aug 16 '23 at 11:34
  • @AbdulAzizBarkat Yes I already saw that solution. It's not what I'm looking for. I don't want the users to press "Enter" two times (later sends an empty line). I want the described behavior even if it's not simpler to you. – S.B Aug 16 '23 at 11:39
  • @AbdulAzizBarkat I want a consistent behavior as users see on social media apps like Telegram, Whatsapp and .etc where you have to use shift+enter if you want to go on the next ine. – S.B Aug 16 '23 at 11:40
  • Does this answer your question? [Shift + Return to insert linebreak in python](https://stackoverflow.com/questions/11343317/shift-return-to-insert-linebreak-in-python) – Dubious Denise Aug 16 '23 at 12:55

0 Answers0