@@ -657,26 +657,51 @@ find_infil_hist_file() = get(ENV, "INFILTRATOR_HISTORY", !isempty(DEPOT_PATH) ?
657657Load the history from the history file found by `find_infil_hist_file()`, i.e. under `ENV["INFILTRATOR_HISTORY"]` or next to the main REPL history (typically `.julia/logs/infil_history.jl`).
658658Most of the code comes from the REPL stdlib (inlined in `setup_interface`).
659659"""
660- function load_history! (hp:: REPL.REPLHistoryProvider , repl, cp:: REPL.CompletionProvider )
661- if repl. history_file
662- try
663- hist_path = find_infil_hist_file ()
664- mkpath (dirname (hist_path))
665- hp. file_path = hist_path
666- REPL. hist_open_file (hp)
667- finalizer (cp) do cp
668- close (hp. history_file)
660+ function load_history! end
661+
662+ @static if VERSION >= v " 1.13-"
663+ function load_history! (hp:: REPL.REPLHistoryProvider , repl, cp:: REPL.CompletionProvider )
664+ if repl. history_file
665+ try
666+ path = find_infil_hist_file ()
667+ mkpath (dirname (path))
668+ hp. history = REPL. History. HistoryFile (path)
669+ errormonitor (@async REPL. history_do_initialize (hp))
670+ finalizer (cp) do cp
671+ close (hp. history)
672+ end
673+ catch
674+ # use REPL.hascolor to avoid using the local variable with the same name
675+ print_response (repl, Pair {Any, Bool} (current_exceptions (), true ), true , REPL. hascolor (repl))
676+ println (REPL. outstream (repl))
677+ @info " Disabling history file for this session"
678+ repl. history_file = false
669679 end
670- REPL. hist_from_file (hp, hist_path)
671- catch
672- # use REPL.hascolor to avoid using the local variable with the same name
673- print_response (repl, Pair {Any, Bool} (current_exceptions (), true ), true , REPL. hascolor (repl))
674- println (REPL. outstream (repl))
675- @info " Disabling history file for this session"
676- repl. history_file = false
677680 end
681+ return
682+ end
683+ else
684+ function load_history! (hp:: REPL.REPLHistoryProvider , repl, cp:: REPL.CompletionProvider )
685+ if repl. history_file
686+ try
687+ hist_path = find_infil_hist_file ()
688+ mkpath (dirname (hist_path))
689+ hp. file_path = hist_path
690+ REPL. hist_open_file (hp)
691+ finalizer (cp) do cp
692+ close (hp. history_file)
693+ end
694+ REPL. hist_from_file (hp, hist_path)
695+ catch
696+ # use REPL.hascolor to avoid using the local variable with the same name
697+ print_response (repl, Pair {Any, Bool} (current_exceptions (), true ), true , REPL. hascolor (repl))
698+ println (REPL. outstream (repl))
699+ @info " Disabling history file for this session"
700+ repl. history_file = false
701+ end
702+ end
703+ return
678704 end
679- return
680705end
681706
682707function debugprompt (mod, locals, trace, terminal, repl, ex, bt; nostack = false , file, fileline)
@@ -686,25 +711,32 @@ function debugprompt(mod, locals, trace, terminal, repl, ex, bt; nostack = false
686711
687712 try
688713 if isassigned (PROMPT)
689- panel = PROMPT[]
690- panel . complete = InfiltratorCompletionProvider (mod, evalmod)
714+ prompt = PROMPT[]
715+ prompt . complete = InfiltratorCompletionProvider (mod, evalmod)
691716 else
692717 cp = InfiltratorCompletionProvider (mod, evalmod)
693- panel = PROMPT[] = REPL. LineEdit. Prompt (
718+ prompt = PROMPT[] = REPL. LineEdit. Prompt (
694719 " infil> " ;
695720 prompt_prefix = prompt_color,
696721 prompt_suffix = Base. text_colors[:normal ],
697722 complete = cp,
698- on_enter = is_complete
723+ on_enter = is_complete,
724+ repl = repl
699725 )
700- panel. hist = REPL. REPLHistoryProvider (Dict {Symbol, Any} (:Infiltrator => panel))
701- load_history! (panel. hist, repl, cp)
702- REPL. history_reset_state (panel. hist)
726+
727+ prompt. hist = REPL. REPLHistoryProvider (Dict {Symbol, Any} (:infil => prompt))
728+ if VERSION >= v " 1.10-"
729+ load_history! (prompt. hist, repl, cp)
730+ end
731+ REPL. history_reset_state (prompt. hist)
703732 end
704- search_prompt, skeymap = LineEdit. setup_search_keymap (panel. hist)
705- search_prompt. complete = REPL. LatexCompletions ()
706733
707- panel. on_done = (s, buf, ok) -> begin
734+ if VERSION < v " 1.13-"
735+ search_prompt, skeymap = LineEdit. setup_search_keymap (prompt. hist)
736+ search_prompt. complete = REPL. LatexCompletions ()
737+ end
738+
739+ prompt. on_done = (s, buf, ok) -> begin
708740 if ! ok
709741 LineEdit. transition (s, :abort )
710742 REPL. LineEdit. reset_state (s)
@@ -906,11 +938,27 @@ function debugprompt(mod, locals, trace, terminal, repl, ex, bt; nostack = false
906938 return true
907939 end
908940
909- prefix_prompt, prefix_keymap = LineEdit. setup_prefix_keymap (panel. hist, panel)
941+ prefix_prompt, prefix_keymap = LineEdit. setup_prefix_keymap (prompt. hist, prompt)
942+
943+ keymaps = Dict{Any, Any}[prefix_keymap, LineEdit. history_keymap, LineEdit. default_keymap, LineEdit. escape_defaults]
944+
945+ if VERSION < v " 1.13-"
946+ pushfirst! (keymaps, skeymap)
947+ end
948+
949+ prompt. keymap_dict = LineEdit. keymap (keymaps)
950+
951+ prompts = [prompt, prefix_prompt]
952+
953+ if VERSION < v " 1.13-"
954+ push! (prompts, search_prompt)
955+ end
910956
911- panel. keymap_dict = LineEdit. keymap (Dict{Any, Any}[skeymap, prefix_keymap, LineEdit. history_keymap, LineEdit. default_keymap, LineEdit. escape_defaults])
957+ mi = REPL. LineEdit. ModalInterface (prompts)
958+ mistate = REPL. LineEdit. init_state (terminal, mi)
959+ repl. mistate = mistate
912960
913- REPL. run_interface (terminal, REPL . LineEdit . ModalInterface ([panel, prefix_prompt, search_prompt]) )
961+ REPL. run_interface (terminal, mi, mistate )
914962 catch e
915963 e isa InterruptException || rethrow (e)
916964 end
0 commit comments