Created
December 26, 2014 10:12
-
-
Save ethercrow/4193eb394bc3a89a04f6 to your computer and use it in GitHub Desktop.
tailless
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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