summaryrefslogtreecommitdiffstats
path: root/pyLoadCli.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-19 11:48:00 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-19 11:48:00 +0200
commit27f9513854f8a4f68cf039bb6db6ab46bb7dcdd9 (patch)
treea9b2bb5fe0f0aee1d07ff9b5da18aed7cd10ad70 /pyLoadCli.py
parentmethod for derotating letters, see #6 (diff)
downloadpyload-27f9513854f8a4f68cf039bb6db6ab46bb7dcdd9.tar.xz
new pyLoadCli input system
Diffstat (limited to 'pyLoadCli.py')
-rw-r--r--pyLoadCli.py88
1 files changed, 76 insertions, 12 deletions
diff --git a/pyLoadCli.py b/pyLoadCli.py
index 0a68cfc45..cc6963f23 100644
--- a/pyLoadCli.py
+++ b/pyLoadCli.py
@@ -17,21 +17,39 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
###
-import time
-import thread
import os
import sys
+import thread
+import time
+
from module.remote.ClientSocket import SocketThread
class pyLoadCli:
def __init__(self, adress, port, pw):
- thread = SocketThread(adress, int(port), pw, self)
+ os.system("clear")
+ self.println(1, "pyLoad Command Line Interface")
+ self.println(2, "")
+ self.thread = SocketThread(adress, int(port), pw, self)
+ self.getch = _Getch()
+ self.input = ""
+ self.inputline = 0
self.start()
def start(self):
while True:
- inp = raw_input()
- print inp[-1]
+ #inp = raw_input()
+ inp = self.getch.impl()
+ if ord(inp) == 3:
+ sys.exit() # ctrl + c
+ elif ord(inp) == 13:
+ self.input = "" #enter
+ self.println(self.inputline, self.input)
+ elif ord(inp) == 127:
+ self.input = self.input[:-1] #backspace
+ self.println(self.inputline, self.input)
+ else:
+ self.input += inp
+ self.println(self.inputline, self.input)
def format_time(self, seconds):
seconds = int(seconds)
@@ -41,25 +59,71 @@ class pyLoadCli:
return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
return _("%i seconds") % seconds
+ def println(self, line, content):
+ print "\033["+ str(line) +";0H" + str(content) + " " * 60
+
+
def data_arrived(self, obj):
"""Handle incoming data"""
if obj.command == "update":
#print obj.data
- print "\033[2;0H%s Downloads" % (len(obj.data))
- line = 2
+
+ self.println(3, "%s Downloads" % (len(obj.data)))
+ line = 4
for download in obj.data:
if download["status"] == "downloading":
percent = download["percent"]
- z = percent/2
- print "\033["+str(line)+";0H[" + z*"#" + (50-z)*" " + "] " + str(percent) + "% of " + download["name"]
+ z = percent / 2
+ print "\033[" + str(line) + ";0H[" + z * "#" + (50-z) * " " + "] " + str(percent) + "% of " + download["name"]
line += 1
line += 2
+ self.inputline = line + 2
print("\033[" + str(line) + ";0HMeldungen:")
for download in obj.data:
if download["status"] == "waiting":
- print "\033["+str(line)+";0HWarte %s auf Downlod Ticket für %s" % (self.format_time(download["wait_until"]), download["name"])
+ print "\033[" + str(line) + ";0HWarte %s auf Downlod Ticket für %s" % (self.format_time(download["wait_until"]), download["name"])
line += 1
+class _Getch:
+ """Gets a single character from standard input. Does not echo to the screen."""
+ def __init__(self):
+ try:
+ self.impl = _GetchWindows()
+ except ImportError:
+ self.impl = _GetchUnix()
+
+ def __call__(self): return self.impl()
+
+
+class _GetchUnix:
+ def __init__(self):
+ import tty
+ import sys
+
+ def __call__(self):
+ import sys
+ import tty
+ import termios
+
+ fd = sys.stdin.fileno()
+ old_settings = termios.tcgetattr(fd)
+ try:
+ tty.setraw(sys.stdin.fileno())
+ ch = sys.stdin.read(1)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+ return ch
+
+
+class _GetchWindows:
+ def __init__(self):
+ import msvcrt
+
+ def __call__(self):
+ import msvcrt
+ return msvcrt.getch()
+
+
if __name__ == "__main__":
if len(sys.argv) != 4:
address = raw_input("Adress:")
@@ -68,6 +132,6 @@ if __name__ == "__main__":
#address = "localhost"
#port = "7272"
#password = "pwhere"
- cli = pyLoadCli(address,port,password)
+ cli = pyLoadCli(address, port, password)
else:
- cli = pyLoadCli(*sys.argv[1:])
+ cli = pyLoadCli( * sys.argv[1:]) \ No newline at end of file