Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F131853
prompt.lua
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
prompt.lua
View Options
-- The prefix that will be before the search text for the user
local
prompt_prefix
=
">> "
-- Gets the suffix to delete from some text biased on what happens in a bash
-- prompt. If the text dose not end in a letter then the last word and all of
-- the tailing special characters will be returned. If the text dose end in a
-- letter then only the last word will be returned leaving the special
-- characters that are before the last word. For example
--
-- `some word` -> `some `
-- `some word` -> `some `
-- `some word ` -> `some `
local
function
get_delete_suffix
(
text
)
if
text
:
match
"([A-Za-z]+)$"
==
nil
then
return
text
:
match
"([A-Za-z]+[^A-Za-z]+)$"
end
return
text
:
match
"([A-Za-z]+)$"
end
local
prompt
=
{}
prompt
.
suffix
=
""
prompt
.
value
=
""
prompt
.
text
=
function
()
return
prompt
.
value
..
prompt
.
suffix
end
prompt
.
update
=
function
()
vim
.
api
.
nvim_echo
({
{
prompt_prefix
,
"None"
},
{
prompt
.
value
:
sub
(
1
,
-
2
),
"None"
},
{
prompt
.
value
:
sub
(
-
1
,
-
1
),
"Underlined"
},
{
prompt
.
suffix
,
"None"
},
},
false
,
{})
end
prompt
.
input
=
function
(
char
)
if
char
==
"BACKSPACE"
then
prompt
.
value
=
string.sub
(
prompt
.
value
,
0
,
-
2
)
elseif
char
==
"LEFT"
then
if
#
prompt
.
value
>
0
then
prompt
.
suffix
=
prompt
.
value
:
sub
(
-
1
,
-
1
)
..
prompt
.
suffix
prompt
.
value
=
prompt
.
value
:
sub
(
1
,
-
2
)
end
elseif
char
==
"RIGHT"
then
if
#
prompt
.
suffix
>
0
then
prompt
.
value
=
prompt
.
value
..
prompt
.
suffix
:
sub
(
1
,
1
)
prompt
.
suffix
=
prompt
.
suffix
:
sub
(
2
,
-
1
)
end
elseif
char
==
"DELETE_WORD"
then
local
suffix
=
get_delete_suffix
(
prompt
.
value
)
if
suffix
==
nil
then
prompt
.
value
=
""
else
prompt
.
value
=
prompt
.
value
:
sub
(
1
,
#
prompt
.
value
-
#
suffix
)
end
elseif
char
==
"
\\\\
"
then
prompt
.
value
=
prompt
.
value
..
"
\\
"
else
prompt
.
value
=
prompt
.
value
..
char
end
prompt
.
update
()
end
prompt
.
set
=
function
(
value
)
prompt
.
value
=
value
prompt
.
suffix
=
""
prompt
.
update
()
end
prompt
.
destroy
=
function
()
prompt
.
value
=
""
prompt
.
suffix
=
""
vim
.
notify
""
end
return
prompt
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Apr 6 2026, 6:33 PM (5 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10559
Default Alt Text
prompt.lua (2 KB)
Attached To
Mode
R1 ivy.nvim
Attached
Detach File
Event Timeline
Log In to Comment