Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion stdlib/REPL/src/History/prompt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Initialize a custom REPL prompt tied to `events` using the existing `term`.
Returns a tuple `(term, prompt, istate, pstate)` ready for
input handling and display.
"""
function create_prompt(events::Channel{Symbol}, term, prefix::String = "\e[90m")
function create_prompt(events::Channel{Symbol}, term, prefix::String = "\e[90m", initial_query::String = "")
prompt = REPL.LineEdit.Prompt(
PROMPT_TEXT, # prompt
prefix, "\e[0m", # prompt_prefix, prompt_suffix
Expand All @@ -78,6 +78,9 @@ function create_prompt(events::Channel{Symbol}, term, prefix::String = "\e[90m")
interface = REPL.LineEdit.ModalInterface([prompt])
istate = REPL.LineEdit.init_state(term, interface)
pstate = istate.mode_state[prompt]
if !isempty(initial_query)
write(pstate.input_buffer, initial_query)
end
(; term, prompt, istate, pstate)
end

Expand Down
7 changes: 5 additions & 2 deletions stdlib/REPL/src/History/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ Launch the interactive REPL history search interface.
Spawns prompt and display tasks, waits for user confirm or abort,
and returns the final selection (if any).
"""
function runsearch(histfile::HistoryFile, term, prefix::String = "\e[90m")
function runsearch(histfile::HistoryFile, term, prefix::String = "\e[90m", initial_query::String = "")
update!(histfile)
events = Channel{Symbol}(Inf)
pspec = create_prompt(events, term, prefix)
pspec = create_prompt(events, term, prefix, initial_query)
ptask = @spawn runprompt!(pspec, events)
dtask = @spawn run_display!(pspec, events, histfile.records)
if !isempty(initial_query)
push!(events, :edit)
end
wait(ptask)
fullselection(fetch(dtask))
end
Expand Down
8 changes: 6 additions & 2 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2700,14 +2700,15 @@ function history_search(mistate::MIState)
mimode = mode(mistate)
mimode.hist.last_mode = mimode
mimode.hist.last_buffer = copy(buffer(mistate))
initial_query = input_string(state(mistate))
mistate.mode_state[mimode] =
deactivate(mimode, state(mistate), termbuf, term)
prefix = if mimode.prompt_prefix isa Function
mimode.prompt_prefix()
else
mimode.prompt_prefix
end
result = histsearch(mimode.hist.history, term, prefix)
result = histsearch(mimode.hist.history, term, prefix, initial_query)
mimode = if isnothing(result.mode)
mistate.current_mode
else
Expand All @@ -2720,7 +2721,10 @@ function history_search(mistate::MIState)
mistate.current_mode = mimode
activate(mimode, state(mistate, mimode), termbuf, term)
commit_changes(term, termbuf)
edit_insert(pstate, result.text)
if !isempty(result.text)
edit_clear(buffer(pstate))
edit_insert(pstate, result.text)
end
refresh_multi_line(mistate)
nothing
end
Expand Down