nedbat / cog

Small bits of Python computation for static files
MIT License
340 stars 26 forks source link

message line will not apear on a new line (on Windows 10?) #8

Open 42sol-eu opened 4 years ago

42sol-eu commented 4 years ago

if I use the cog.msg( ... ) the first call will be directly printed on the Cogging ... output line.

Every following message will be printed on a own separate line.

Suggestion: Add a new_line to the Cogging output

nedbat commented 4 years ago

I guess we need a little more management of the output line state? I don't use msg() myself any more, so I didn't notice it was working like this.

42sol-eu commented 4 years ago

I looked at the code on my fork. It is solvable by putting a state variable inside the CogGenerator like this:

    def start_on_new_line(self):
        """"check if to fill in a \n to start on a new line with the following output.
        """
        if self.inside_line:
            self.inside_line = False
            self.prout('', end='\n')

    def msg(self, s):
        self.start_on_new_line()
        self.prout("Message: "+s)

I am now looking at the test cases. Do you know if there is already one who is looking for the standard output?