randy3k / Terminus

Bring a real terminal to Sublime Text

Home Page:https://packagecontrol.io/packages/Terminus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weird behaviour with default terminal size and ANSI escape codes

mataha opened this issue · comments

The following setting controls the default size in Terminus:

{
   "size": [null, null],
}

With the defaults, whenever I open a default shell (in my case Windows Command Prompt) in a panel, the second line of the header message gets eaten during preprocessing of my AutoRun scripts:

Microsoft Windows [Version 10.0.19044.2965]

>

Sure enough, with "debug": true I can see that Terminus receives ANSI CSI n A (Cursor Up) and moves the cursor one line up before erasing the contents to the end with CSI n K:

20:51:23 DEBUG Terminus:159 feed_data() receieved: <ESC>[?25l<CR><ESC>[1A<ESC>[0K<CR>

However, when both of the dimensions in the config are non-null, that doesn't happen!

{
   "size": [80, 80],
}
Microsoft Windows [Version 10.0.19044.2965]
(c) Microsoft Corporation. All rights reserved.

>

What is going on here? I don't even know where to start debugging this. I've tried looking into ensure_position() and view_size() hoping to stumble upon something, but to no avail.

For reference, here are the (relevant) contents of my AutoRun script:

for /f %%E in (
    '"echo(prompt $E| "%ComSpec%" /d 2>nul"'
) do (
    set/p="%%~E[?12l%%~E[1F%%~E[0J"
) <nul

What this does is turns off cursor blinking, then moves the cursor to the previous line in order to erase everything in display from the position of the cursor to the end of the screen (so that the rubbish left by escape sequences is cleared). It works fine when Terminus is opened in a view, defaults or not.

Fixed itself with a sprinkle of console magic.