Skip to content
Snippets Groups Projects
Commit d232116e authored by Timothee Besset's avatar Timothee Besset Committed by Timothee Besset
Browse files

Add support for custom windows terminals, pass --with-conemu=<path to conemu>...

Add support for custom windows terminals, pass --with-conemu=<path to conemu> or --with-cmder=<path to cmder>. Setting is persistent, set to empty string to reset.
parent 6a62af0e
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,7 @@ import appdirs ...@@ -61,6 +61,7 @@ import appdirs
import paramiko import paramiko
import devkit_client.zeroconf as zeroconf import devkit_client.zeroconf as zeroconf
import devkit_client.captured_popen as captured_popen import devkit_client.captured_popen as captured_popen
import devkit_client.custom_terminal as custom_terminal
try: try:
import devkit_client.version import devkit_client.version
...@@ -122,6 +123,7 @@ g_external_tools = None ...@@ -122,6 +123,7 @@ g_external_tools = None
g_lock = threading.Lock() g_lock = threading.Lock()
g_captured_popen_factory = captured_popen.CapturedPopenFactory() g_captured_popen_factory = captured_popen.CapturedPopenFactory()
g_custom_terminal = custom_terminal.CustomTerminal()
# This burned me twice now .. https://twitter.com/TTimo/status/1582509449838989313 # This burned me twice now .. https://twitter.com/TTimo/status/1582509449838989313
from os import getenv as os_getenv from os import getenv as os_getenv
...@@ -1286,6 +1288,10 @@ def run_in_terminal(commands): ...@@ -1286,6 +1288,10 @@ def run_in_terminal(commands):
cwd = os.getcwd() cwd = os.getcwd()
creationflags=0 creationflags=0
if platform.system() == 'Windows': if platform.system() == 'Windows':
p = g_custom_terminal.Popen(commands)
if p is not None:
return p
# After a bunch of iteration, writing a ps1 script and running it from the ssh.exe directory seems the most reliable # After a bunch of iteration, writing a ps1 script and running it from the ssh.exe directory seems the most reliable
# trying to pass all command line parameters with a direct powershell.exe invocation runs into a nightmare of path escaping business # trying to pass all command line parameters with a direct powershell.exe invocation runs into a nightmare of path escaping business
# this also enables us to provide better error handling and diagnostics # this also enables us to provide better error handling and diagnostics
......
import logging
import shutil
import subprocess
logger = logging.getLogger(__name__)
# Support the use of conemu or cmder on Windows
# glue between config settings and the low level run_in_terminal logic
class CustomTerminal:
TERM_KEY = 'CustomTerminal.Term'
STYLE_KEY = 'CustomTerminal.Style' # 0: disabled, 1: conemu, 2: cmder
def __init__(self):
self.conf = None
self.settings = None
def setup(self, conf, settings):
self.conf = conf
self.settings = settings
matched = False
for (term_attr, style) in (('with_conemu', 1), ('with_cmder', 2)):
term = vars(self.conf).get(term_attr)
if term is None:
continue
matched = True
if term == "":
# Explicit disable
style = 0
break
if len(term) > 0:
# Can pass a full path, or we will lookup here
term = shutil.which(term)
if term is not None:
break
if not matched:
# settings are unchanged, the command line options were not used
return
if style == 0 or term is None:
logger.info(f'Custom windows terminal is disabled')
self.settings[self.STYLE_KEY] = 0
return
logger.info(f'Using custom windows terminal: {term}')
self.settings[self.STYLE_KEY] = style
self.settings[self.TERM_KEY] = term
def Popen(self, commands):
if self.settings[self.STYLE_KEY] == 0:
return
if self.settings[self.STYLE_KEY] == 1:
commands = [self.settings[self.TERM_KEY], '-run'] + commands
elif self.settings[self.STYLE_KEY] == 2:
commands = [self.settings[self.TERM_KEY], '/x', '-run ' + ' '.join(commands)]
else:
raise Exception(f'Unexpected STYLE_KEY {self.settings[self.STYLE_KEY]} value in CustomTerminal')
logging.info(f'Run in terminal - custom terminal: {commands!r}')
p = subprocess.Popen(
commands,
)
return p
...@@ -3315,6 +3315,15 @@ def main(): ...@@ -3315,6 +3315,15 @@ def main():
'--disable-popen-capture', required=False, action='store_true', '--disable-popen-capture', required=False, action='store_true',
help='Disable capturing of launched external processes output to the status window.' help='Disable capturing of launched external processes output to the status window.'
) )
if platform.system() == 'Windows':
parser.add_argument(
'--with-conemu', required=False, action='store',
help='Configure run in terminal to use given exe with conemu syntax. Set to blank to clear.'
)
parser.add_argument(
'--with-cmder', required=False, action='store',
help='Configure run in terminal to use given exe with cmder syntax. Set to blank to clear.'
)
conf = parser.parse_args() conf = parser.parse_args()
...@@ -3349,6 +3358,8 @@ def main(): ...@@ -3349,6 +3358,8 @@ def main():
shutdown_signal.connect(settings.on_shutdown_signal) shutdown_signal.connect(settings.on_shutdown_signal)
atexit.register(settings.shutdown) # saves settings on abnormal termination atexit.register(settings.shutdown) # saves settings on abnormal termination
devkit_client.g_custom_terminal.setup(conf, settings)
devkit_commands = DevkitCommands(conf, shutdown_signal) devkit_commands = DevkitCommands(conf, shutdown_signal)
devkit_commands.setup() devkit_commands.setup()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment