Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress console flash on Windows #59

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions elm_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

class ElmFormatCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Hide the console window on Windows
shell = False
path_separator = ':'
if os.name == "nt":
shell = True
path_separator = ';'

binary = self.get_setting('elm_format_binary') or 'elm-format'
Expand All @@ -28,7 +25,13 @@ def run(self, edit):

working_dir = self.working_dir()
command = binary.split() + [self.view.file_name(), '--yes'] + options.split()
p = subprocess.Popen(command, cwd=working_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell)
p = subprocess.Popen(
command,
cwd=working_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
startupinfo=get_popen_startupinfo()
)

if path:
os.environ['PATH'] = old_path
Expand Down
3 changes: 2 additions & 1 deletion elm_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def run(self, cmd=[], kill=False):
self.format_cmd(cmd),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=working_dir
cwd=working_dir,
startupinfo=get_popen_startupinfo()
)
self.killed = False

Expand Down
18 changes: 18 additions & 0 deletions elm_plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sublime
import sublime_plugin
import os
import os.path as fs
import subprocess

def is_ST2():
return sublime.version().startswith('2')
Expand Down Expand Up @@ -66,3 +68,19 @@ def new(cls, *args, **kwargs):
return target_cls

return decorator

# Construct STARTUPINFO value that can be passed to Popen constructor on
# Windows to suppress the console window that otherwise gets flashed when
# elm.exe or elm-format.exe is run; this is more secure than passing
# 'shell=True'.
#
# https://stackoverflow.com/questions/1765078/how-to-avoid-console-window-with-pyw-file-containing-os-system-call/12964900#12964900
# https://docs.python.org/3.3/library/subprocess.html#subprocess.STARTUPINFO
def get_popen_startupinfo():
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
return startupinfo
else:
return None