1

I want to have a banner above my display. I use curses for my threaded display which looks like this:

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

Is it possible to add a banner at the top of Total Requests. I tried using pyfiglet but it's not working

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()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

2

Welcome to Stack Overflow!

I'm guessing that curses takes over the console and you won't be able to see anything you write to it via print.

Extrapolating from this other question, your code would look like so:

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

Clayton J Roberts
  • 347
  • 1
  • 5
  • 19