Skip to content

Instantly share code, notes, and snippets.

@ethercrow
Created December 26, 2014 10:12
Show Gist options
  • Save ethercrow/4193eb394bc3a89a04f6 to your computer and use it in GitHub Desktop.
Save ethercrow/4193eb394bc3a89a04f6 to your computer and use it in GitHub Desktop.
tailless
#!/usr/bin/env python
# reading from file is left out as an exercise
# as is quitting with 'q'
# and wrapping
# and possibly something else
import curses
import sys
VISIBLE_LINE_COUNT = 3
def main():
visible_lines = []
screen = curses.initscr()
try:
while True:
next_line = sys.stdin.readline()
visible_lines = visible_lines[-VISIBLE_LINE_COUNT+1:]
visible_lines.append(next_line.rstrip())
screen.clear()
for i, text in enumerate(visible_lines):
screen.addstr(i, 0, text)
screen.refresh()
except:
pass
finally:
curses.endwin()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment