CodeLazy
CodeLazy

Reputation: 7

The curses screen isnt looking as expected

So I was working on my Ubuntu a week ago and made this simple Python curses window that shows all of the files. The end result is expected to be a console file manager. The problem began when I booted up and entered my arch, as the Ubuntu was temporary. Once I booted up my arch, I configured it, and I was ready to start with the coding. Once I started to code I first wanted to run the code to see if everything runs smoothly, but to my shock, it all was weird. The whole screen, aka terminal, was white, the curses window, the text, and everything else was super weird (all grey without any of the text or anything else), and I don't understand why.

I have tried to change the background

here is the code:


from curses import wrapper
import os

class func:
    def __init__(self):
        self.path = os.getcwd()
        
    def colors(self):
        curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) # folder color
        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) # basic file color
        curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) # executable file color
        self.CYAN = curses.color_pair(1)
        self.WHITE = curses.color_pair(2)
        self.GREEN = curses.color_pair(3)


    def show(self, stdscr):
        # start functions
        stdscr.clear()
        files = os.listdir(self.path)

        # dimensions for the window
        height = len(files) + 2
        width = 40
        start_y = 1
        start_x = 1 
        
        # creating the window and border 
        show_win = curses.newwin(height, width, start_y, start_x)
        show_win.border(0)

        # showing process
        for idx, filename in enumerate(files):
            show_win.addstr(idx + 1, 2, filename)

        # end commands
        show_win.refresh()
        show_win.getkey()
        

    def refresh(self, stdscr):
        stdscr.clear()
        stdscr.refresh()

    def main(self, stdscr):
        self.colors()
        self.refresh(stdscr)
        stdscr.clear()
        self.show(stdscr)
        stdscr.refresh()

    def running(self):
        wrapper(self.main)

if __name__ == "__main__":
    system = func()
    system.running()       
    

Also update I tried it in my i3 terminal, and it worked. It was an all white terminal, while the one I was using is custom color shemed, so maybe that can help you all answer this.

Upvotes: 0

Views: 55

Answers (0)

Related Questions