peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.61k stars 238 forks source link

DynamicRenderer always printing with transparent background #352

Closed vaibhav0320 closed 2 years ago

vaibhav0320 commented 2 years ago

Describe the bug

I'm implementing a box which contain text and if there are are more text line then the box height then text will scroll up. But the thing is when I print text with spaces it is ignoring the space

To Reproduce

    def __init__(self,height,width,text):
        super().__init__(height,width)
        self.text=text
        self.height=height
        self.width=width
        self.x = 0
        self.y = 0
        self.buf = [[' ' for _ in range(self.width)] for _ in range(self.height)]
        self.text_len=len(self.text)
        self.pos=0
    def _render_now(self):

        self._clear()

        if(self.pos>=self.text_len):
            while(self.x<self.width):
                self.buf[self.y][self.x]=' '
                self.x+=1
            return self._plain_image,self._colour_map
        c = self.text[self.pos]

        if(c=='\n'):
            while(self.x<self.width):
                self.buf[self.y][self.x]=' '
                self.x+=1
            self.pos+=1
            return self._plain_image,self._colour_map

        if(self.x>=self.width):
            self.x=0
            self.y+=1

        if(self.y>=self.height):
            self._clear()
            for i in range(self.height-1):
                    for j in range(self.width):
                        self._write(self.buf[i+1][j], j, i)
                        self.buf[i][j]=self.buf[i+1][j]
            self.y=self.height-1
            for i in range(self.width):
                self._write(' ', i, self.height-1)
                self.buf[self.height-1][i]=' '
            #self.y=self.height-1

        self.buf[self.y][self.x]=c
        self._write(c, self.x, self.y)
        self.x+=1
        self.pos+=1
        print(self.buf)
        return self._plain_image,self._colour_map

    def _write(self, text, x, y):
        self._canvas.print_at(text, x, y,colour=0,bg=7,**transparent=False**)

text='''line    1
line   2
line   3
LINE....4'''

Print(screen,textbox(3,10,tt),10,100,speed=2)

Expected behavior As you can see in the screen shot there are black gaps which are spaces but should be white

Screenshots image

System details (please complete the following information):

Additional context Add any other context about the problem here.

peterbrittain commented 2 years ago

That code is fine. I suspect your issue is actually what you're using to display the renderer is using the wrong style.

The logic is that the Renderer uses a Canvas to create its content, then some Effect prints the contents of your Canvas to the Screen. Assuming you're using the Print Effect, you need to pass in transparent=False to that effect.

If you're using a different Effect, check how it passes the transparent option to print_at().

vaibhav0320 commented 2 years ago

Thank you for reply. It worked after setting the transparent=False. Thanks a lot...