11#  TODO : Overload
2- function  _compat (ctx:: Context ; io =  nothing )
2+ function  _compat (ctx:: Context ; io =  nothing , input_io  =   stdin )
33    io =  something (io, ctx. io)
4-     can_fancyprint (io) ||  pkgerror (" Pkg.compat cannot be run interactively in this terminal"  )
4+     if  input_io isa  Base. TTY #  testing uses IOBuffer
5+         can_fancyprint (io) ||  pkgerror (" Pkg.compat cannot be run interactively in this terminal"  )
6+     end 
57    printpkgstyle (io, :Compat , pathrepr (ctx. env. project_file))
68    longest_dep_len =  max (5 , length .(collect (keys (ctx. env. project. deps)))... )
79    opt_strs =  String[]
@@ -16,7 +18,7 @@ function _compat(ctx::Context; io = nothing)
1618    end 
1719    menu =  TerminalMenus. RadioMenu (opt_strs, pagesize =  length (opt_strs))
1820    choice =  try 
19-         TerminalMenus. request ("   Select an entry to edit:"  , menu)
21+         TerminalMenus. request (TerminalMenus . default_terminal (in  =  input_io, out  =  io),  "   Select an entry to edit:"  , menu)
2022    catch  err
2123        if  err isa  InterruptException #  if ^C is entered
2224            println (io)
@@ -35,10 +37,12 @@ function _compat(ctx::Context; io = nothing)
3537        start_pos =  length (prompt) +  2 
3638        move_start =  " \e [$(start_pos) G" 
3739        clear_to_end =  " \e [0J" 
38-         ccall (:jl_tty_set_mode , Int32, (Ptr{Cvoid}, Int32), stdin . handle, true )
40+         if  input_io isa  Base. TTY
41+             ccall (:jl_tty_set_mode , Int32, (Ptr{Cvoid}, Int32), input_io. handle, true )
42+         end 
3943        while  true 
4044            print (io, move_start, clear_to_end, buffer, " \e [$(start_pos +  cursor) G"  )
41-             inp =  TerminalMenus. _readkey (stdin )
45+             inp =  TerminalMenus. _readkey (input_io )
4246            if  inp ==  ' \r '   #  Carriage return
4347                println (io)
4448                break 
@@ -85,9 +89,11 @@ function _compat(ctx::Context; io = nothing)
8589        end 
8690        buffer
8791    finally 
88-         ccall (:jl_tty_set_mode , Int32, (Ptr{Cvoid}, Int32), stdin . handle, false )
92+         if  input_io isa  Base. TTY
93+             ccall (:jl_tty_set_mode , Int32, (Ptr{Cvoid}, Int32), input_io. handle, false )
94+         end 
8995    end 
9096    new_entry =  strip (resp)
91-     compat (ctx, dep, string (new_entry))
97+     API . _compat (ctx, dep, string (new_entry))
9298    return 
9399end 
0 commit comments