question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reading from stdin

See original GitHub issue

Hi.

I’m trying to make a textual app that deals with data from stdin. However, if I pipe something to a textual app, it gets consumed as keystrokes. When I consume stdin first (via sys.stdin.read(), for example), the app does not process keystrokes (rather, the typed keys get superimposed onto it).

Is there a solution for this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
ohlecommented, Sep 24, 2022

Trying to reconstruct what I did back then (I don’t really use textual anymore, sorry), it was something like

content = sys.stdin.read()
sys.stdin = open('/dev/tty', 'r')

Then you have the originally piped content in content, and re-opening makes it available for keystrokes to textual.

0reactions
AdrianoKFcommented, Sep 25, 2022
content = sys.stdin.read()
sys.stdin = open('/dev/tty', 'r')

That did the trick, thanks for the reply! 🙏🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading from stdin - Stack Overflow
What are the possible ways for reading user input using read() system call in Unix. How can we read from stdin byte by...
Read more >
How to Read from stdin in Python - DigitalOcean
1. Using sys.stdin to read from standard input ... Python sys module stdin is used by the interpreter for standard input. Internally, it...
Read more >
C - Input and Output - Tutorialspoint
C programming provides a set of built-in functions to read the given input and ... The char *gets(char *s) function reads a line...
Read more >
Reading from stdin | Linux System Programming Techniques
Reading from stdin. In this recipe, we'll learn how to write a program in C that reads from standard input. Doing so enables...
Read more >
StdIn - Introduction to Programming in Java
Overview. The StdIn class provides static methods for reading strings and numbers from standard input. These functions fall into one of four categories:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found