gpt4 book ai didi

python - 如何在Python中使用curses和pyfiglet

转载 作者:太空宇宙 更新时间:2023-11-03 20:53:52 24 4
gpt4 key购买 nike

我想在我的显示器上方有一个横幅。我对我的线程显示使用诅咒,如下所示:

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 写入的任何内容。

this other question 推断,您的代码将如下所示:

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()

关于python - 如何在Python中使用curses和pyfiglet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56141333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com