Sublime Forum

Carriage returns in stdout window

#1

I’m running a build in a package I’m developing. It is launched via something similar to the example provided on the website:

self.proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=working_dir, env=my_env)

self.killed = False

thread = threading.Thread(target=self.read_handle, args=(self.proc.stdout,))
thread.start()

and the output of the build gets pushed up so that only [Finished] is visible at the end even if the output is only one line high. I’ve tried with the command ran being a simple echo to make sure it wasn’t my stuff printing incorrectly.

Am I doing something wrong in how this is launched or how stdout it piped out?

Additional note: The behavior is inconsistent. If I re-execute the build action sometimes the output is correctly displaying all the lines without moving some of them off the top of the window.

Another Additional note: Using an output panel other than ‘exec’ works correctly but of course doesn’t work with the build result commands in the Tools menu.

0 Likes

#2

Adding a self._panel.run_command('goto_line', {"line": 0}) after EVERY self._panel.run_command('append', {'characters': text}) does seem to do the trick but if I do it just once after the text is printed it doesn’t work.

Build runs in a process started by a subprocess.Popen(). Output acquisition runs in a thread calling a read_handle() routine. This is basically the same example given in the Build Systems documentation.

To detect then end of the text I added a sublime.set_timeout(lambda: self.writing_done(), 1) at the end of read_handle() to make sure it gets executed after all the captured text is output.

In writing_done() I’ve tried self._panel.run_command('goto_line', {"line": 0}), self._panel.run_command('move_to', {"to": "bof" }) and:

sel = self._panel.sel()
sel.clear()
sel.add(sublime.Region(0, 0))

all within a with self._panel_lock block. Nothing works the panel still only displays the last line of captured text at the top, forcing to scroll up to see the rest.

Puzzling… There’s something I’m not understanding here :slight_smile:

0 Likes