Quantcast

Jump to content


Photo

Useful Commandline Output :)


  • Please log in to reply
4 replies to this topic

#1 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 03 November 2010 - 05:08 AM

So, after searching the net for a good way to clear the line (without doing stupid shit like os.system('clear')) i came across these 2 hexcodes ^^


clearLine = "\x1B\x5B\x32\x4B\x1B\x5B\x47"
clearAll = "\x1B\x5B\x48\x1B\x5B\x32\x4A"


Their variable names say it all, one will clear the line where your cursor is, and the other will clear the entire screen.

Heres a fun little "wait" function im using in one of my scripts...


import sys,time,random
def funPrint(x,f,t=0.1):
left = x
cl = "\x1B\x5B\x32\x4B\x1B\x5B\x47"
while left > 0:
if left-t < 0: t=left
sys.stdout.write(cl+"Wait [ %.1f ] seconds"%left)
sys.stdout.flush()
time.sleep(t)
left -= t
sys.stdout.write(cl+f)
sys.stdout.flush()

for x in range(5):
funPrint(random.uniform(1.3, 3.9), "Checking something...")
time.sleep(1)

print
print "Were done waiting :D"


Enjoy :D
~Cody

Edited by Pyro699, 03 November 2010 - 05:30 AM.


#2 Kway

Kway
  • Proud to be a Brony

  • 1242 posts


Users Awards

Posted 03 November 2010 - 08:17 AM

Wouldn't it be easier to use:

import sys

def clearLine(string='',end=None):
print("\x1B\x5B\x32\x4B\x1B\x5B\x47"+string,end=end)

def clear():
print("\x1B\x5B\x48\x1B\x5B\x32\x4A",end='')



#3 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 03 November 2010 - 08:26 AM

Wouldn't it be easier to use:

import sys

def clearLine(string='',end=None):
print("\x1B\x5B\x32\x4B\x1B\x5B\x47"+string,end=end)

def clear():
print("\x1B\x5B\x48\x1B\x5B\x32\x4A",end='')


Well yeah :p The point wasn't to show the most effective way of using it >> In my script i have a whole print class which has those 2 methods devoted to clear line and clear screen ^^

~Cody

#4 jaredennisclark

jaredennisclark
  • 838 posts

Posted 03 November 2010 - 10:32 AM

I'll definitely be using these code snippets. I'm just starting to learn, and before now the only way I knew how to clear the screen was the lame 'Import OS' example you gave. :p

How did you figure out/stumble upon this hex code? How would one go about deciphering commands to hex code like this?

#5 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 03 November 2010 - 10:34 AM

I'll definitely be using these code snippets. I'm just starting to learn, and before now the only way I knew how to clear the screen was the lame 'Import OS' example you gave. :p

How did you figure out/stumble upon this hex code? How would one go about deciphering commands to hex code like this?


Google and this xD


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users