mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
Shell: Add builtin command to reset the internal state
The new builtin command "reset" now resets the entire internal state by virtually destructing the Shell state and re-constructing it. This helps for example when setting a new hostname and wanting to view it in the current Shell program.
This commit is contained in:
parent
489fce0ed2
commit
fb60db7b00
3 changed files with 27 additions and 3 deletions
|
@ -149,6 +149,17 @@ ErrorOr<int> Shell::builtin_where(Main::Arguments arguments)
|
||||||
return at_least_one_succeded ? 0 : 1;
|
return at_least_one_succeded ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<int> Shell::builtin_reset(Main::Arguments)
|
||||||
|
{
|
||||||
|
destroy();
|
||||||
|
initialize(m_is_interactive);
|
||||||
|
|
||||||
|
// NOTE: As the last step before returning, clear (flush) the shell text entirely.
|
||||||
|
fprintf(stderr, "\033[3J\033[H\033[2J");
|
||||||
|
fflush(stderr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<int> Shell::builtin_alias(Main::Arguments arguments)
|
ErrorOr<int> Shell::builtin_alias(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
Vector<DeprecatedString> aliases;
|
Vector<DeprecatedString> aliases;
|
||||||
|
|
|
@ -2258,9 +2258,7 @@ Shell::Shell()
|
||||||
cache_path();
|
cache_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
Shell::Shell(Line::Editor& editor, bool attempt_interactive, bool posix_mode)
|
void Shell::initialize(bool attempt_interactive)
|
||||||
: m_in_posix_mode(posix_mode)
|
|
||||||
, m_editor(editor)
|
|
||||||
{
|
{
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
tcsetpgrp(0, getpgrp());
|
tcsetpgrp(0, getpgrp());
|
||||||
|
@ -2305,11 +2303,22 @@ Shell::Shell(Line::Editor& editor, bool attempt_interactive, bool posix_mode)
|
||||||
m_editor->load_history(get_history_path());
|
m_editor->load_history(get_history_path());
|
||||||
cache_path();
|
cache_path();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Shell::Shell(Line::Editor& editor, bool attempt_interactive, bool posix_mode)
|
||||||
|
: m_in_posix_mode(posix_mode)
|
||||||
|
, m_editor(editor)
|
||||||
|
{
|
||||||
|
initialize(attempt_interactive);
|
||||||
start_timer(3000);
|
start_timer(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
Shell::~Shell()
|
Shell::~Shell()
|
||||||
|
{
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shell::destroy()
|
||||||
{
|
{
|
||||||
if (m_default_constructed)
|
if (m_default_constructed)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
__ENUMERATE_SHELL_BUILTIN(wait, InAllModes) \
|
__ENUMERATE_SHELL_BUILTIN(wait, InAllModes) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(dump, InAllModes) \
|
__ENUMERATE_SHELL_BUILTIN(dump, InAllModes) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(kill, InAllModes) \
|
__ENUMERATE_SHELL_BUILTIN(kill, InAllModes) \
|
||||||
|
__ENUMERATE_SHELL_BUILTIN(reset, InAllModes) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(noop, InAllModes) \
|
__ENUMERATE_SHELL_BUILTIN(noop, InAllModes) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(break, OnlyInPOSIXMode) \
|
__ENUMERATE_SHELL_BUILTIN(break, OnlyInPOSIXMode) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(continue, OnlyInPOSIXMode) \
|
__ENUMERATE_SHELL_BUILTIN(continue, OnlyInPOSIXMode) \
|
||||||
|
@ -414,6 +415,9 @@ private:
|
||||||
Shell();
|
Shell();
|
||||||
virtual ~Shell() override;
|
virtual ~Shell() override;
|
||||||
|
|
||||||
|
void destroy();
|
||||||
|
void initialize(bool attempt_interactive);
|
||||||
|
|
||||||
RefPtr<AST::Node> parse(StringView, bool interactive = false, bool as_command = true) const;
|
RefPtr<AST::Node> parse(StringView, bool interactive = false, bool as_command = true) const;
|
||||||
|
|
||||||
void timer_event(Core::TimerEvent&) override;
|
void timer_event(Core::TimerEvent&) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue