{
  "id": 2029031,
  "title": "Reclaim the terminal",
  "url": "https://urgent.news/2026/08/19/reclaim-the-terminal",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-19T22:10:12.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://nishantjosh.dev/blogs/reclaim-the-terminal/"
  },
  "original_language": "en",
  "account": "The article explains how an interactive program, like less or fzf, can still accept keyboard input even though its standard input (stdin) is reading from a file or pipe. The key to this is how the processes in the pipeline are arranged and how the terminal is involved.\n\nEach stage of the pipeline is a separate process that waits for its turn, reads one line from the terminal, and then passes the accumulated lines downstream. The final stage prints all four lines along with the process ID that read each one. The shell doesn't launch stage 2 when stage 1 finishes; it launches the whole pipeline at once, with the final stage already waiting before you've pressed a single key.\n\nTo understand how each stage knows its position in the pipeline, we need to look at how stdin and stdout are connected to processes. Every process has its own file descriptors (fd 0 for stdin, fd 1 for stdout). For the first process in the pipeline, fd 0 points to the terminal. For every later process, fd 0 points to the previous stage's pipe. The terminal sets up this connection for each process in the pipeline.\n\nWhen a downstream stage starts reading from its stdin, the read doesn't return just because the pipe is empty. It returns only when it receives an EOF (end-of-file) signal, indicating that no more data will arrive. The terminal plays a role here by providing a way for each stage to know when there's no more input to read.\n\nHowever, when a stage finally reads from stdin and fd 0 becomes an exhausted pipe, it still needs a way to get back to the keyboard. The terminal provides this by creating a new file descriptor that refers to the same terminal. This new descriptor allows the stage to read from the keyboard directly, regardless of what fd 0 currently points to.\n\nThe program's source code shows how it handles these issues without needing a separate coordination channel between stages. The terminal's role in all of this is crucial, as it's the interface through which the processes receive keyboard input. The terminal is the common denominator that allows all the processes to interact with the keyboard, even though their stdin is otherwise occupied.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}