You are not logged in.
Pages: 1
is there a way to control printing to a terminal?
i want to write to the same line and also change the same line,
like pacman does it when it shows how much you have downloaded of a file,
arch + gentoo + initng + python = enlisy
Offline
Offline
that looks like what i was looking for,
couldn't you supply some code too
now i have to rtfm also 'before' i start to code,
arch + gentoo + initng + python = enlisy
Offline
Problem is, I've never used ncurses in any programming language. :-P I just knew that pacman used it to get that one lie output (from passing comment Xentac made once), and I remembered that Python had a curses module.
Its the best I could do on such short notice. Would you like to write my master's thesis? :-P
Dusty
Offline
give me a few weeks and i'll do it,
this curses stuff is not so easy to dig into, i just want to make oneliners, it shouldn't be like rocket science,
arch + gentoo + initng + python = enlisy
Offline
Is this what you need ?(sorry for writing an example in your favourite language xerces2)
public class JCurses {
public static void main(String[]args) throws Exception{
String[] pacman = new String[]{
"Pacmanr",
"pAcmanr",
"paCmanr",
"pacManr",
"pacmAnr",
"pacmaNr",
"pacmann"};
for(String p:pacman){
System.out.print(p);
Thread.sleep(1000);
}
}
}
all pacman does is a simple carriage return at the end.
if python doesnt have a built in carriage return, just print its ascii value 13 as a character.
(put the code in a file named JCurses.java
compile it with "javac JCurses.java
run it with "java JCurses")
Offline
in python please,
and i don't understand what you mean anyway,
arch + gentoo + initng + python = enlisy
Offline
Sorry for writing it in java (dont really know python).
anyway::
The curses part of pacmans "download printing" is printing the carriage return (ascii value 13) as a character to the end of each line until 100% download is reached.Then it prints linefeed (ascii 10) to change the line.
In other words : you should be able to overwrite your prints if you supply a carriage return at the end (like in my java prog and pacman) if python doesnt do anything strange behind your back when you do a print.
Offline
are you saying that i don't have to use curses?
arch + gentoo + initng + python = enlisy
Offline
yes that is exactly what I'm saying.
edit: Well atleast I didnt need anything to make it work in java... I dont know python so I cant really say if you need it or not.
Offline
Try this :
import curses
import time
stdscr = curses.initscr()
myStrings=["Pacman working ...","pAcman working ...","paCman working ...",
"pacMan working ...","pacmAn working ...","pacmaN working ...",
"pacman Working ...","pacman wOrking ...","pacman woRking ...",
"pacman worKing ...","pacman workIng ...","pacman workiNg ...",
"pacman workinG ..."]
for eachString in myStrings:
stdscr.addstr(0, 0, eachString,curses.A_REVERSE)
time.sleep(1)
stdscr.refresh()
curses.endwin()
Is this kinda what you are loooking for?
Offline
sonix stuff doesn't seem to work,
i will try tmaynards curses sollution also
my function is beeing fed by another function so how do i deal with that?
or should i have one curses function like tmaynards and use sleep()?
arch + gentoo + initng + python = enlisy
Offline
Non curses version:
import sys
import time
myStrings=["Pacman working ...","pAcman working ...","paCman working ...",
"pacMan working ...","pacmAn working ...","pacmaN working ...",
"pacman Working ...","pacman wOrking ...","pacman woRking ...",
"pacman worKing ...","pacman workIng ...","pacman workiNg ...",
"pacman workinG ..."]
for eachString in myStrings:
sys.stdout.write(eachString)
sys.stdout.flush()
sys.stdout.write("r")
time.sleep(1)
print("n")
Enjoy!
Offline
*xerxes hugs tmaynard very hard*
that last stuff works beutifully,
edit: if you feel lucky you can get the evidence on svn,
more info here: http://home.gna.org/libpypac/
arch + gentoo + initng + python = enlisy
Offline
I'd be curious to see your implementation of this. There are a few different ways to do this if you are trying to do a "progress bar" type thing depending on what you are actually doing.
Offline
just follow the subversion installation instructions at the link above,
you need lazy-pac-cli-devel too which follow the same steps as libpypac-devel, you'll get it by the same checkout,
arch + gentoo + initng + python = enlisy
Offline
Pages: 1