randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.39k stars 81 forks source link

Terminus Tab View steals cursor focus when running some npm scripts #238

Closed elzii closed 3 years ago

elzii commented 4 years ago

Sample package.json

{                                                                         
  "develop": "concurrently -r \"npm:type-check:watch\" \"npm:start\"",    
  "start": "parcel ./src/index.html",                                     
  "type-check:watch": "tsc --noEmit --watch"
} 

I have Terminus opened in a Tab View. If I make a change to my file when running the type-check:watch or develop commands, whenever I save the file, the cursor focus will switch to the Terminus tab.

It does not happen when running npm run start however.

Here is the log output with sublime.log_commands(True) enabled:

When running npm run type-check:watch and saving a file (PROBLEM):

command: lsp_save
command: save {"async": true}
command: unmark_undo_groups_for_gluing
command: terminus_render
command: terminus_show_cursor
command: terminus_reset
command: unmark_undo_groups_for_gluing
command: unmark_undo_groups_for_gluing
command: terminus_initialize
command: set_layout {"cells": [[0, 0, 1, 1], [1, 0, 2, 1]], "cols": [0.0, 0.521482180478, 1.0], "rows": [0.0, 1.0]}
command: terminus_render
command: terminus_show_cursor

When running npm run start and saving a file (NO PROBLEM)

command: lsp_save
command: save {"async": true}
command: unmark_undo_groups_for_gluing
command: terminus_render
command: terminus_show_cursor
command: terminus_render
command: terminus_show_cursor
command: terminus_render
command: terminus_show_cursor
command: terminus_render
command: terminus_show_cursor
command: terminus_render
command: terminus_show_cursor

The obvious difference is that terminus_reset is being called, which has some window.focus_view() calls in it.

elzii commented 4 years ago

Update 1: This also happens in a panel view, not just tab

Update 2: I've narrowed it down to what's causing it, independent of tsc/concurrent/etc.

You can reproduce by running a node file that calls process.stdout.write("\x1Bc")

Perhaps this is solvable by overriding the escape sequence?

mitranim commented 3 years ago

Installed Terminus, instantly ran into this problem. This escape sequence is used for clearing the scrollback, and is commonly used by file-watching tools. It's extremely useful for seeing a "clean" result after every rerun, avoiding confusion with previous results. The focus stealing makes Terminus' tabs incompatible with such tools, and it's a shame. Suggestions would be very much appreciated.

randy3k commented 3 years ago

Oh, I just realized I have been ignoring this thread. I am on it now. Basically we need to have a version of terminus_reset that doesn't change focus.

mitranim commented 3 years ago

Whoah that was quick. Thanks!

randy3k commented 3 years ago

Thank you for bumping it up by the way .