Skip to content

Instantly share code, notes, and snippets.

@eruvanos
Created July 18, 2017 06:50
Show Gist options
  • Save eruvanos/8617e6f8f9fa139b1533faa69ec3f10d to your computer and use it in GitHub Desktop.
Save eruvanos/8617e6f8f9fa139b1533faa69ec3f10d to your computer and use it in GitHub Desktop.
Virtual Pipe - Tool to show what was piped through
#!/usr/bin/env python
import time
from sys import stdin, stdout, argv
try:
from tkinter import *
except ImportError:
from Tkinter import *
# parse args
keep_history = False
if "-h" in argv:
keep_history = True
delay = 0
if "-t" in argv:
delay = float(argv[argv.index("-t") + 1])
stay_alive = False
if "-a" in argv:
stay_alive = True
if "--help" in argv:
print("-h: show history")
print("-t x: delays between each row")
print("-a: keeps window open (you have to cancel the command)")
exit()
# setup window
tk = Tk()
tk.overrideredirect(1)
v = StringVar(value="")
lable = Label(tk, textvariable=v, justify=LEFT, borderwidth=2, relief="groove", font='TkFixedFont')
lable.pack(side=LEFT,padx=2, pady=2)
tk.lift()
tk.attributes("-topmost", True)
# process
history = ""
for x in stdin:
stdout.write(x)
stdout.flush()
time.sleep(delay)
if keep_history:
history += x
v.set(history)
else:
v.set(x.rstrip())
tk.update()
if stay_alive:
Button(tk, text="x", command=sys.exit).pack(side=LEFT)
stdout.close()
tk.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment