3
3
module LineEdit
4
4
5
5
import .. REPL
6
- using .. Terminals
6
+ using REPL : AbstractREPL
7
7
8
+ using .. Terminals
8
9
import .. Terminals: raw!, width, height, cmove, getX,
9
10
getY, clear_line, beep
10
11
@@ -13,6 +14,8 @@ using Base: something
13
14
14
15
abstract type TextInterface end
15
16
abstract type ModeState end
17
+ abstract type HistoryProvider end
18
+ abstract type CompletionProvider end
16
19
17
20
export run_interface, Prompt, ModalInterface, transition, reset_state, edit_insert, keymap
18
21
@@ -31,11 +34,11 @@ mutable struct Prompt <: TextInterface
31
34
# Same as prefix except after the prompt
32
35
prompt_suffix:: Union{String,Function}
33
36
keymap_dict:: Dict{Char}
34
- repl # :: AbstractREPL
35
- complete # ::REPLCompletionProvider
37
+ repl:: Union{ AbstractREPL,Nothing}
38
+ complete:: CompletionProvider
36
39
on_enter:: Function
37
40
on_done:: Function
38
- hist # ::REPLHistoryProvider
41
+ hist:: HistoryProvider
39
42
sticky:: Bool
40
43
end
41
44
@@ -141,9 +144,6 @@ function input_string_newlines_aftercursor(s::PromptState)
141
144
return count (c-> (c == ' \n ' ), rest)
142
145
end
143
146
144
- abstract type HistoryProvider end
145
- abstract type CompletionProvider end
146
-
147
147
struct EmptyCompletionProvider <: CompletionProvider end
148
148
struct EmptyHistoryProvider <: HistoryProvider end
149
149
@@ -1602,9 +1602,16 @@ const escape_defaults = merge!(
1602
1602
AnyDict (" \e [$(c) l" => nothing for c in 1 : 20 )
1603
1603
)
1604
1604
1605
+ mutable struct HistoryPrompt <: TextInterface
1606
+ hp:: HistoryProvider
1607
+ complete:: CompletionProvider
1608
+ keymap_dict:: Dict{Char,Any}
1609
+ HistoryPrompt (hp) = new (hp, EmptyCompletionProvider ())
1610
+ end
1611
+
1605
1612
mutable struct SearchState <: ModeState
1606
1613
terminal:: AbstractTerminal
1607
- histprompt # ::HistoryPrompt
1614
+ histprompt:: HistoryPrompt
1608
1615
# rsearch (true) or ssearch (false)
1609
1616
backward:: Bool
1610
1617
query_buffer:: IOBuffer
@@ -1617,6 +1624,8 @@ mutable struct SearchState <: ModeState
1617
1624
new (terminal, histprompt, backward, query_buffer, response_buffer, false , InputAreaState (0 ,0 ))
1618
1625
end
1619
1626
1627
+ init_state (terminal, p:: HistoryPrompt ) = SearchState (terminal, p, true , IOBuffer (), IOBuffer ())
1628
+
1620
1629
terminal (s:: SearchState ) = s. terminal
1621
1630
1622
1631
function update_display_buffer (s:: SearchState , data)
@@ -1654,18 +1663,20 @@ function reset_state(s::SearchState)
1654
1663
nothing
1655
1664
end
1656
1665
1657
- mutable struct HistoryPrompt <: TextInterface
1658
- hp # ::HistoryProvider
1659
- complete # ::CompletionProvider
1666
+ # a meta-prompt that presents itself as parent_prompt, but which has an independent keymap
1667
+ # for prefix searching
1668
+ mutable struct PrefixHistoryPrompt <: TextInterface
1669
+ hp:: HistoryProvider
1670
+ parent_prompt:: Prompt
1671
+ complete:: CompletionProvider
1660
1672
keymap_dict:: Dict{Char,Any}
1661
- HistoryPrompt (hp) = new (hp, EmptyCompletionProvider ())
1673
+ PrefixHistoryPrompt (hp, parent_prompt) =
1674
+ new (hp, parent_prompt, EmptyCompletionProvider ())
1662
1675
end
1663
1676
1664
- init_state (terminal, p:: HistoryPrompt ) = SearchState (terminal, p, true , IOBuffer (), IOBuffer ())
1665
-
1666
1677
mutable struct PrefixSearchState <: ModeState
1667
1678
terminal:: AbstractTerminal
1668
- histprompt # ::HistoryPrompt
1679
+ histprompt:: PrefixHistoryPrompt
1669
1680
prefix:: String
1670
1681
response_buffer:: IOBuffer
1671
1682
ias:: InputAreaState
@@ -1678,6 +1689,8 @@ mutable struct PrefixSearchState <: ModeState
1678
1689
new (terminal, histprompt, prefix, response_buffer, InputAreaState (0 ,0 ), 0 )
1679
1690
end
1680
1691
1692
+ init_state (terminal, p:: PrefixHistoryPrompt ) = PrefixSearchState (terminal, p, " " , IOBuffer ())
1693
+
1681
1694
function show (io:: IO , s:: PrefixSearchState )
1682
1695
print (io, " PrefixSearchState " , isdefined (s,:parent ) ?
1683
1696
string (" (" , s. parent, " active)" ) : " (no parent)" , " for " ,
@@ -1696,19 +1709,6 @@ end
1696
1709
1697
1710
input_string (s:: PrefixSearchState ) = String (take! (copy (s. response_buffer)))
1698
1711
1699
- # a meta-prompt that presents itself as parent_prompt, but which has an independent keymap
1700
- # for prefix searching
1701
- mutable struct PrefixHistoryPrompt <: TextInterface
1702
- hp # ::HistoryProvider
1703
- parent_prompt:: Prompt
1704
- complete # ::CompletionProvider
1705
- keymap_dict:: Dict{Char,Any}
1706
- PrefixHistoryPrompt (hp, parent_prompt) =
1707
- new (hp, parent_prompt, EmptyCompletionProvider ())
1708
- end
1709
-
1710
- init_state (terminal, p:: PrefixHistoryPrompt ) = PrefixSearchState (terminal, p, " " , IOBuffer ())
1711
-
1712
1712
write_prompt (terminal, s:: PrefixSearchState ) = write_prompt (terminal, s. histprompt. parent_prompt)
1713
1713
prompt_string (s:: PrefixSearchState ) = prompt_string (s. histprompt. parent_prompt. prompt)
1714
1714
0 commit comments