#!/usr/bin/python # The MIT License (MIT) # # Copyright (c) 2026 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from curses import ( cbreak, curs_set, endwin, initscr, noecho, resetty, savetty, set_escdelay, ) from itertools import islice from os import dup2 from sys import argv, exit, stderr info = ''' echoff [words...] Emit words using the command-line arguments given (like `echo` does) on an alternate screen (off the regular screen). You can quit by pressing (almost) any key on your keyboard, or even force-quit it via Control + C. ''' # leave default/original stdin alone, so this tool can be called with # the likes of `xargs` (for example), and still wait for keyboard input # dup2(0, 3) with open('/dev/tty', 'rb') as inp: dup2(inp.fileno(), 0) screen = initscr() savetty() noecho() cbreak() screen.keypad(True) curs_set(0) set_escdelay(10) err = None res = 0 try: try: pos = 0 for s in islice(argv, 1, None): if pos > 0: screen.addstr(0, pos, ' ') pos += 1 screen.addstr(0, pos, s) pos += len(s) except KeyboardInterrupt as e: # only handle Control + C, just in case loop is very slow raise e except Exception: # just quit the loop, ignoring any out-of-screen display errors pass screen.getkey() except KeyboardInterrupt: res = 1 except Exception as e: err = e res = 1 try: resetty() except: pass try: endwin() except: pass if err: print(str(e), file=stderr) exit(res)