-1

problem

When I run a curses program via windows cmd.exe that outputs colored text I get an unselectable line on the bottom of the window. How can I remove it?

example

import curses

def main(stdscr):
    curses.init_pair(1, 200, 100)
    stdscr.addstr("test ", curses.color_pair(1))
    stdscr.refresh()
    stdscr.getch()

curses.wrapper(main)

image of the line

cause

The problem is that curses thinks that the terminal is smaller and resizes the window resulting in this line at the bottom.

If I do

curses.resize_term(10, 10)

a second line appears on the side and becomes way bigger; I guess this is the way cmd handle smaller terms

solution

to fix that bug I should use another terminal or say to the user that if he is on Windows he should not go on the cmd but use something like PowerShell or Windows Terminal

rafalou38
  • 576
  • 1
  • 5
  • 16
  • There's not enough information. Running in `cmd.exe`, that **might** be PDCurses. The legal range for the foreground/background colors is likely 16. – Thomas Dickey Jan 21 '21 at 23:31
  • Try [restoring the terminal to its previous graphics mode](https://docs.python.org/3/howto/curses.html) using `curses.endwin()` after text output. You may also want to check the color pairs used are valid – T3RR0R Jan 22 '21 at 11:27

1 Answers1

1

I would start with a stdscr.clear() (if you need to clear the screen)

But you should add a stdscr.refresh() between your addstr() and the getch()

And as said by T3ERR0R, don't forget the curses.endwin() before the end of your script.

darokin
  • 21
  • 4
  • Thanks, `stdscr.refresh()` does sometimes make the line smaller (when terminal size is changed during run) – rafalou38 Mar 27 '21 at 21:07