Sublime Forum

Handling of backspace characters in output window

#1

Today I ran into an annoyance when showing the output of some unit tests in the output window.

In Haskell, the QuickCheck library shows progress by first backspacing the previous status and printing the new one. This works fine in a command prompt window where it produces the desired updating status. Unfortunately the ouput window prints the backspace characters literally, resulting in output like this:

[code](0 tests) (1 test) (2 tests) (3 tests) (4 tests) (5 tests) (6 tests) (7 tests) (8 tests) (9 tests) (10 tests) (11 tests) (12 tests) (13 tests) (14 tests) (15 tests) (16 tests) (17 tests) (18 tests) (19 tests) (20 tests) (21 tests) (22 tests) (23 tests) (24 tests) (25 tests) (26 tests) (27 tests) (28 tests) (29 tests) (30 tests) (31 tests) (32 tests) (33 tests) (34 tests) (35 tests) (36 tests) (37 tests) (38 tests) (39 tests) (40 tests) (41 tests) (42 tests) (43 tests) (44 tests) (45 tests) (46 tests) (47 tests) (48 tests) (49 tests) (50 tests) (51 tests) (52 tests) (53 tests) (54 tests) (55 tests) (56 tests) (57 tests) (58 tests) (59 tests) (60 tests) (61 tests) (62 tests) (63 tests) (64 tests) (65 tests) (66 tests) (67 tests) (68 tests) (69 tests) (70 tests) (71 tests) (72 tests) (73 tests) (74 tests) (75 tests) (76 tests) (77 tests) (78 tests) (79 tests) (80 tests) (81 tests) (82 tests) (83 tests) (84 tests) (85 tests) (86 tests) (87 tests) (88 tests) (89 tests) (90 tests) (91 tests) (92 tests) (93 tests) (94 tests) (95 tests) (96 tests) (97 tests) (98 tests) (99 tests) +++ OK, passed 100 tests.

Cases: 7 Tried: 0 Errors: 0 Failures: 0
Cases: 7 Tried: 1 Errors: 0 Failures: 0
Cases: 7 Tried: 2 Errors: 0 Failures: 0
Cases: 7 Tried: 3 Errors: 0 Failures: 0
Cases: 7 Tried: 4 Errors: 0 Failures: 0
Cases: 7 Tried: 5 Errors: 0 Failures: 0
Cases: 7 Tried: 6 Errors: 0 Failures: 0
Cases: 7 Tried: 7 Errors: 0 Failures: 0
Counts {cases = 7, tried = 7, errors = 0, failures = 0}
[/code]

which is obviously not that easy to read. And this is only one test with 100 cases. You can imagine that 10 tests with 10000 cases each will output a lot of garbage.

The bottom bit (Cases: 7…) has a similar problem in that the library in question (HUnit) prints the message at a specified position, again resulting in a continuously overwritten status display, as long as you’re in a command prompt window.

I don’t think the latter problem will be fixable but I was hoping you could make backspace characters behave like backspaces, or to provide an option to toggle between the two behaviors.

0 Likes

#2

I don’t know if this is an option in SublimeText, but putting 2>/dev/null at the end of it fixed this issue for me in TextMate. The 2> redirects stderr, the /dev/null just gets rid of it. Since these are *nix things (stderr, /dev/null) they probably will be different on Windows but there may be something in SublimeText for this purpose. I’m using Ruby to script Bash:

s = `"#{bin_path}" 2>/dev/null`

That works correctly, meaning afterwards s will contain only the output from my Haskell program and any (test n)\b\b\b\b BS.

For those not familiar with Ruby:
`` (backticks) - Run a shell command (it’s equivalent to system()) and return the output (stdout & stderr) as a string
#{} - String interpolation. bin_path is a variable that is the absolute path (inc. binary name) to my executable

Translate to your preferred languages. YMMV.

0 Likes