繁体   English   中英

如何在python中使用curses和pyfiglet

[英]How to use curses and pyfiglet in python

我想在显示器上方放一个横幅。 我在线程显示中使用curses,如下所示:

Total Requests :      $
Successful Requests : $
Failed Requests :     $
Current Threads :     $

是否可以在总请求的顶部添加横幅。 我尝试使用pyfiglet但无法正常工作

def outputSpot():
        global threads,counter,rcounter,logfile
        curses.start_color()
        curses.use_default_colors()
        banner = Figlet(font='slant')
        print(banner.renderText('Log Replay'))

        for i in range(0, curses.COLORS):
                curses.init_pair(i + 1, i, -1)
        while True:
#               stdscr.addstr(5,10, "Traffic Replay",curses.color_pair(51))

                stdscr.addstr(6,0, "File Streaming:\t{0}".format(logfile),curses.color_pair(185))
                stdscr.addstr(7,0, "Total Requests:\t\t{0}".format(counter),curses.color_pair(124))
                stdscr.addstr(8,0, "Successful Requests:\t{0}".format(rcounter),curses.color_pair(76))
                stdscr.addstr(9,0, "Failed Requests:\t{0}".format(fcounter),curses.color_pair(161))
                stdscr.addstr(10,0, "Current Threads:\t{0}  ".format(len(threads)),curses.color_pair(124))
                stdscr.refresh()

欢迎使用Stack Overflow!

我猜测curses会接管控制台,而您将看不到通过print向控制台写入的任何内容。

另一个问题推断,您的代码如下所示:

import curses
from pyfiglet import Figlet

stdscr = curses.initscr()

def outputSpot():
    global threads, counter, rcounter, logfile, stdscr

    curses.start_color()
    curses.use_default_colors()

    banner = Figlet(font="slant").renderText("Log Replay")

    for i in range(0, curses.COLORS):
        curses.init_pair(i + 1, i, -1)

    while True:
        # Iterate through the lines of the Figlet
        y = 0
        for line in banner.split("\n"):
            stdscr.addstr(y, 0, line)
            y += 1

        # You can also print the rest without repeating yourself so often ->

        # WARNING: Unless you can safely assume that the number of lines 
        # in your Figlet is 6 or less, I would leave the following line commented
        # y = 6
        for line, color in [
            ("File Streaming:\t{0}".format(logfile), curses.color_pair(185)),
            ("Total Requests:\t\t{0}".format(counter), curses.color_pair(124)),
            ("Successful Requests:\t{0}".format(rcounter), curses.color_pair(76)),
            ("Failed Requests:\t{0}".format(fcounter), curses.color_pair(161)),
            ("Current Threads:\t{0}".format(len(threads)), curses.color_pair(124)),
        ]:
            stdscr.addstr(y, 0, line, color)
            y += 1

        stdscr.refresh()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM