Skip to content

Commit ff0b20a

Browse files
committed
make conhost.rb console startup waiting method the same way as terminal.rb
1 parent f97a642 commit ff0b20a

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lib/yamatanooroti/windows/conhost.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ def initialize(height, width, wait, timeout, name)
1515

1616
@console_process_id = DL.create_console(CONSOLE_KEEPING_COMMAND.sub("NAME", name), show_console_param())
1717

18+
sleep 0.1 if Yamatanooroti.options.windows == :"legacy-conhost" # ad-hoc
19+
1820
# wait for console startup complete
19-
8.times do |n|
20-
break if attach_terminal(open: false, exception: false) { true }
21-
sleep 0.01 * 2**n
21+
with_timeout("Console process startup timed out.") do
22+
attach_terminal(open: false, exception: false) { true }
2223
end
2324

2425
attach_terminal do |conin, conout|

lib/yamatanooroti/windows/terminal.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ def pid_from_windowtitle(name)
5151
do_tasklist("WINDOWTITLE eq #{name}")
5252
end
5353

54-
private def with_timeout(timeout_message, timeout = @timeout, &block)
55-
wait_until = Time.now + timeout
56-
loop do
57-
result = block.call
58-
break result if result
59-
raise timeout_message if wait_until < Time.now
60-
sleep @wait
61-
end
62-
end
63-
6454
private def invoke_wt_process(command, marker, keeper_name)
6555
DL.create_console(command, show_console_param())
6656
# default timeout seems to be too short

lib/yamatanooroti/windows/windows.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ module Yamatanooroti::WindowsTermMixin
212212
map.fetch(Yamatanooroti.options.show_console ? :show : :hide)
213213
end
214214

215+
private def with_timeout(timeout_message, timeout = @timeout, &block)
216+
wait_until = Time.now + timeout
217+
loop do
218+
result = block.call
219+
break result if result
220+
raise timeout_message if wait_until < Time.now
221+
sleep @wait
222+
end
223+
end
224+
215225
private def attach_terminal(open: true, exception: true)
216226
stderr = $stderr
217227
$stderr = StringIO.new

0 commit comments

Comments
 (0)