2009-11-13 13 views
5

मुझे पता है कि कमांड लाइन पर प्रगति पट्टी की तरह कुछ अपडेट करने के लिए, कोई '\ r' का उपयोग करता है। क्या एकाधिक लाइनों को अपडेट करने का कोई तरीका है?मल्टीलाइन प्रगति सलाखों

उत्तर

4

कुछ मौजूदा पुस्तकालय जैसे ncurses का उपयोग करना सबसे अच्छा तरीका है। लेकिन आप सिस्टम कॉल के साथ कंसोल समाशोधन करके गंदे कामकाज का प्रयास कर सकते हैं: system("cls");

+0

है प्रणाली ("cls"): यह चलाने की कोशिश करें? – yodie

+0

लिनक्स पर "स्पष्ट" – doc

+1

ओएस एक्स के बारे में क्या है? – yodie

2

आप कर्सर को उच्च लाइन पर पुनर्स्थापित करने के लिए VT100 codes का उपयोग कर सकते हैं, फिर इसे अपनी अपडेट की गई स्थिति से ओवरड्रा कर सकते हैं।

1

Curses लाइब्रेरी कंसोल यूआई के लिए शक्तिशाली नियंत्रण प्रदान करता है।

3

यदि आप पाइथन का उपयोग कर रहे हैं तो blessings का उपयोग करने का प्रयास करें। यह शाप के चारों ओर वास्तव में सहज ज्ञान युक्त रैपर है।

सरल उदाहरण:

from blessings import Terminal 

term = Terminal() 

with term.location(0, 10): 
    print("Text on line 10") 
with term.location(0, 11): 
    print("Text on line 11") 

आप वास्तव में एक प्रगति बार लागू करने के लिए कोशिश कर रहे हैं, तो progressbar उपयोग करने पर विचार। यह आपको \r क्रुफ्ट बचाएगा।

आप वास्तव में आशीर्वाद और प्रगति पट्टी को एक साथ जोड़ सकते हैं। विंडोज केवल

import time 

from blessings import Terminal 
from progressbar import ProgressBar 

term = Terminal() 

class Writer(object): 
    """Create an object with a write method that writes to a 
    specific place on the screen, defined at instantiation. 

    This is the glue between blessings and progressbar. 
    """ 
    def __init__(self, location): 
     """ 
     Input: location - tuple of ints (x, y), the position 
         of the bar in the terminal 
     """ 
     self.location = location 

    def write(self, string): 
     with term.location(*self.location): 
      print(string) 


writer1 = Writer((0, 10)) 
writer2 = Writer((0, 20)) 

pbar1 = ProgressBar(fd=writer1) 
pbar2 = ProgressBar(fd=writer2) 

pbar1.start() 
pbar2.start() 

for i in range(100): 
    pbar1.update(i) 
    pbar2.update(i) 
    time.sleep(0.02) 

pbar1.finish() 
pbar2.finish() 

multiline-progress

संबंधित मुद्दे