Skip to content

Commit 7b67df5

Browse files
committed
feat(delay): 添加延时关闭shell窗口特性
1 parent c395bff commit 7b67df5

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

core/shell.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ def run_command(
3434
shell:bool=False,
3535
decode:str='utf-8',
3636
cwd=None,
37-
pause:bool=False) -> TRun_command:
37+
pause:Union[bool,int]=False) -> TRun_command:
3838
"""
3939
@Description {description}
4040
4141
- param command :{list} 通过列表将需要输入的shell命令传入
4242
- param strBuffer :{str} 需要传输的数据
4343
- param shell :{bool} 是否开启一个独立的shell执行指令
4444
- param decode :{str} 对返回的结果指定编码方式
45-
- param pause :{bool} 是否暂停
45+
- param pause :{bool} 是否暂停,如果输入数字,则是延时关闭
4646
- panam cwd :{str} 指定工作目录
4747
4848
@example
@@ -74,8 +74,16 @@ def run_command(
7474
try:
7575
# run with inside
7676
if shell:
77-
is_pause = ' & pause' if pause else ''
78-
_command = f'start {new_shell} /c \"{" ".join(command)}{is_pause}\"'
77+
command_head = f'start {new_shell} /c \"'
78+
command_body = " ".join(command)
79+
command_end = ""
80+
if isinstance(pause, bool):
81+
command_end = ' & pause\"' if pause else '\"'
82+
elif isinstance(pause, int):
83+
command_end = f' & timeout /t {pause}\"'
84+
85+
# _command = f'start {new_shell} /c \"{" ".join(command)}{command_end}\"'
86+
_command = command_head + command_body + command_end
7987
Popen(_command, shell=True)
8088
# return True
8189
return { "success":True }

main.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ class CpsRunCommandsCommand(sublime_plugin.TextCommand):
115115
# 简单的安装指令
116116
npm i -D @types/node12
117117
118-
# 需要交互的命令前面添加 "$" 或者 ":"
118+
# "$" 或者 ":" 前缀,调用新的shell窗口运行指令
119+
# 后续cmd窗口会等待15秒后自动关闭
119120
$npm init
121+
122+
# 后续cmd窗口需要用户按任意键才能关闭
120123
:npm init
121124
```
122125
"""
@@ -129,7 +132,7 @@ def run(self, edit: sublime.Edit):
129132
selection_with_index = [ f'{index + 1}. {HISTORY.data[index]}' for index in range(len(HISTORY.data))]
130133

131134
if panel_name:
132-
window.run_command('hide_panel', {'panel':panel_name})
135+
window.run_command('hide_panel', { 'panel':panel_name })
133136
else:
134137
self.show_selection([MSG_SELECTIONS_TITLE] + selection_with_index)
135138

@@ -166,8 +169,8 @@ def show_input_panel(self, placeholder:str=""):
166169
def on_select(self, user_select_index:int):
167170
# custom input
168171
if user_select_index == -1:
169-
# return
170-
self.show_input_panel()
172+
return
173+
# self.show_input_panel()
171174

172175
elif user_select_index == 0:
173176
self.show_input_panel()
@@ -196,9 +199,14 @@ def run_command(self, user_input:str, panel_name:str=None):
196199

197200
# run in new shell window
198201
if user_input[0][0] in RUN_IN_NEW_WINDOW_PREFIX:
202+
if user_input[0][0] == ':':
203+
pause = True
204+
205+
if user_input[0][0] == '$':
206+
pause = 5
199207

200208
commands = str(user_input[1:]).split(' ')
201-
shell.run_command(commands, shell=True, pause=True, cwd=cwd)
209+
shell.run_command(commands, shell=True, pause=pause, cwd=cwd)
202210

203211
return
204212

0 commit comments

Comments
 (0)