mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
Shell: Allow the user to set the prompt using PROMPT()
This allows the prompt to be dynamically configurable, making it possible to display various bits of information in the prompt.
This commit is contained in:
committed by
Andrew Kaster
parent
71ddc33fbf
commit
84777fbe62
@@ -79,6 +79,9 @@ void Shell::print_path(StringView path)
|
||||
|
||||
DeprecatedString Shell::prompt() const
|
||||
{
|
||||
if (m_next_scheduled_prompt_text.has_value())
|
||||
return m_next_scheduled_prompt_text.release_value();
|
||||
|
||||
auto build_prompt = [&]() -> DeprecatedString {
|
||||
auto* ps1 = getenv("PROMPT");
|
||||
if (!ps1) {
|
||||
@@ -2086,9 +2089,22 @@ void Shell::setup_keybinds()
|
||||
});
|
||||
}
|
||||
|
||||
void Shell::set_user_prompt()
|
||||
{
|
||||
if (!has_function("PROMPT"sv))
|
||||
return;
|
||||
|
||||
if (!m_prompt_command_node)
|
||||
m_prompt_command_node = Parser { "shell_set_active_prompt -- ${join \"\\n\" $(PROMPT)}"sv }.parse();
|
||||
|
||||
(void)m_prompt_command_node->run(this);
|
||||
}
|
||||
|
||||
bool Shell::read_single_line()
|
||||
{
|
||||
while (true) {
|
||||
set_user_prompt();
|
||||
|
||||
restore_ios();
|
||||
bring_cursor_to_beginning_of_a_line();
|
||||
m_editor->initialize();
|
||||
|
||||
Reference in New Issue
Block a user