skip to Main Content

I’m trying to display big ascii text with curses, but it only works in the Visual Studio Code terminal for some reason.

Visual Studio Code terminal displays the text correctly

But when I try to run the program in powershell it cuts off the start of the text for some reason, and when I run it in cmd, it just displays a square of question marks.

The windows powershell terminal has the letters cut off at the start, replaced by empty space, and the cmd terminal just displays a box of question marks

What’s going on and how do I fix it?

main.py:

import os, curses, time
os.system('cls' if os.name == 'nt' else 'clear')

def main(stdscr):
    stdscr.clear()
    HEIGHT = curses.LINES
    WIDTH = curses.COLS

    logo = []
    with open("logo.txt", mode="r", encoding="utf-8") as dataFile:
        logo = dataFile.readlines()
    
    for i in range(len(logo)):
        stdscr.addstr(logo[i])

    stdscr.refresh()
    stdscr.getkey()


curses.wrapper(main)

logo.txt:

                       #                              
                  #   ##                              
  #  ##########   ##  #########     #####       ####  
   # #  # ## ##    #  #            ##   ##     #   ## 
     #  # ##         #            ##     ##   ##      
       ## ##  #  #  ##########   ##       #   ##      
 ##   ##   ####  ##   #  #   #   ##       ##  ###     
   # ##  #         #  #  #   #   ##       ##   ####   
         #          ###########  ##       ##     #### 
     ##########    #  #  #  ##   ##       ##       ## 
   #     ##        #  #  #  ##   ##       #         ##
   #    ####      ## ##  #  ##    ##     ##         ##
  ##   # #  #     #  ##########    ##   ##    ##   ## 
 ##  ##  #   ##  ##  #      #       #####      #####  
 #   #   #       #       ####                         

I tried debugging by addstr-inging different variations of "A" and "AAAAAAAAAAAAAAAAAAAAAAAA" instead the ascii font, which worked normally.

I also tried changing the text to become smaller, in case the text got looped or something in the powershell terminal, but the same problem persisted.

Lastly I tried removing the first character for the same reason. The cut-off point seemed to be the same place on the screen, with less text meaning less of the text could peek past the blacked out area.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed the powershell issue where half the text got cropped by addstr-inging each separately with coordinates, although this caused a new issue of powershell forgetting how it displays and instead showing question marks. This also meant that the empty space characters got removed, which means that cmd can display only the question marks for the s.

    Both cmd and powershell now display the letters in question marks

    Since it seems neither powershell or cmd are able to display the s, I will have to generate text that uses another symbol instead.


  2. One way to BYPASS the problem is to convert the text info characters that are generally printable: this is fairly simple as UTF-8 has most (all?) of the ISO-8859-1 characters in the first 256 codepoints.

    $ sed < logo.txt -re 's/xe3x80x80/./g' -e 's/xefxbcx83/#/g' ; echo 
    .......................#..............................
    ..................#...##..............................
    ..#..##########...##..#########.....#####.......####..
    ...#.#..#.##.##....#..#............##...##.....#...##.
    .....#..#.##.........#............##.....##...##......
    .......##.##..#..#..##########...##.......#...##......
    .##...##...####..##...#..#...#...##.......##..###.....
    ...#.##..#.........#..#..#...#...##.......##...####...
    .........#..........###########..##.......##.....####.
    .....##########....#..#..#..##...##.......##.......##.
    ...#.....##........#..#..#..##...##.......#.........##
    ...#....####......##.##..#..##....##.....##.........##
    ..##...#.#..#.....#..##########....##...##....##...##.
    .##..##..#...##..##..#......#.......#####......#####..
    .#...#...#.......#.......####.........................
    

    … here at S.O. it looks a bit squished (condensed) as the characters in the monospace font are narrower.
    It might need some adaptation to be as nice.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search