Compare commits

...

16 Commits

Author SHA1 Message Date
Bananymous 264d1798dc Shell: Clenup code and fix some bugs
Don't list tab completion multiple times, allow `clear` to work even
when ANSI CSI 3K is not supported, reset buffer index when cancelling
command with ctrl+c
2024-10-07 04:10:25 +03:00
Bananymous 1824988b9a Shell: Add support for simple aliases
Aliases do not support chained commands with pipes, &&, ... but this is
a good start.
2024-10-07 04:09:38 +03:00
Bananymous c54d9b3f60 Shell: Implement simple tab completion for commands and files 2024-10-07 01:44:44 +03:00
Bananymous f432d3fcf8 BAN: Cleanup Optional casting for value getters 2024-10-07 01:44:44 +03:00
Bananymous 4f7828bab9 Shell: Allow escaping spaces in commands 2024-10-07 01:44:44 +03:00
Bananymous ae073a336d Shell: Move builtin commands to a hash map
This allows accessing builtin commands outside of `execute_builtin`
2024-10-07 01:44:44 +03:00
Bananymous 6f90974896 BAN: Fix StringView::starts_with
I have no idea what i had been thinking when writing this code :D
2024-10-06 06:23:25 +03:00
Bananymous 4f3c05851c Shell: Expand ~ to home if its at the start of non quoted argument 2024-10-06 01:38:43 +03:00
Bananymous 4b13055125 Shell: Make builtin exit command read exit value from argument
Shell used to unconditionally return with exit code of 0
2024-10-06 01:24:34 +03:00
Bananymous d542cd811d Shell: Add support for &&, || and ; 2024-10-06 01:24:24 +03:00
Bananymous f75cebac7e Shell: Mark all functions as static 2024-10-05 19:11:58 +03:00
Bananymous e302b6b635 Shell: Use sigaction instead of signal
This allows ctrl-c to work on linux :D
2024-10-05 19:07:59 +03:00
Bananymous f709e88994 Shell: Cleanup argument handling and exiting 2024-10-04 17:54:01 +03:00
Bananymous ab9a6d583b Userspace: Set SHELL environment variable in init instead of shell 2024-10-04 17:24:37 +03:00
Bananymous 26d6bf338e Shell: Ignore SIGTTOU and set pgroup from parent instead of child
This allows using the shell in linux!
2024-10-04 17:23:31 +03:00
Bananymous b6e040dfc2 Kernel/Shell: Fix backspace and delete key byte sequences 2024-10-04 04:14:47 +03:00
7 changed files with 949 additions and 404 deletions

View File

@ -167,14 +167,14 @@ namespace BAN
constexpr T& Optional<T>::value() constexpr T& Optional<T>::value()
{ {
ASSERT(has_value()); ASSERT(has_value());
return (T&)m_storage; return *reinterpret_cast<T*>(&m_storage);
} }
template<typename T> template<typename T>
constexpr const T& Optional<T>::value() const constexpr const T& Optional<T>::value() const
{ {
ASSERT(has_value()); ASSERT(has_value());
return (const T&)m_storage; return *reinterpret_cast<const T*>(&m_storage);
} }
template<typename T> template<typename T>
@ -182,7 +182,7 @@ namespace BAN
{ {
if (!has_value()) if (!has_value())
return empty; return empty;
return (T&)m_storage; return value();
} }
template<typename T> template<typename T>
@ -190,7 +190,7 @@ namespace BAN
{ {
if (!has_value()) if (!has_value())
return empty; return empty;
return (const T&)m_storage; return value();
} }
template<typename T> template<typename T>

View File

@ -186,15 +186,10 @@ namespace BAN
{ {
if (target.size() > m_size) if (target.size() > m_size)
return false; return false;
for (size_type i = 0; i < m_size - target.size(); i++) for (size_type i = 0; i < target.size(); i++)
{ if (m_data[i] != target[i])
bool valid = true; return false;
for (size_type j = 0; j < target.size() && valid; j++) return true;
valid = (m_data[i + j] == target[j]);
if (valid)
return true;
}
return false;
} }
constexpr bool contains(char ch) const constexpr bool contains(char ch) const

View File

@ -237,8 +237,6 @@ namespace Kernel
*ptr = m_input.front(); *ptr = m_input.front();
if (*ptr == '\r') if (*ptr == '\r')
*ptr = '\n'; *ptr = '\n';
if (*ptr == 127)
*ptr++ = '\b', *ptr++ = ' ', *ptr = '\b';
m_input.pop(); m_input.pop();
ptr++; ptr++;
} }

View File

@ -185,79 +185,10 @@ namespace Kernel
if (event.released()) if (event.released())
return; return;
const char* ansi_c_str = LibInput::key_to_utf8(event.key, event.modifier); const char* ansi_c_str = LibInput::key_to_utf8_ansi(event.key, event.modifier);
if (event.ctrl())
{
ansi_c_str = nullptr;
switch (event.key)
{
case LibInput::Key::A: ansi_c_str = "\x01"; break;
case LibInput::Key::B: ansi_c_str = "\x02"; break;
case LibInput::Key::C: ansi_c_str = "\x03"; break;
case LibInput::Key::D: ansi_c_str = "\x04"; break;
case LibInput::Key::E: ansi_c_str = "\x05"; break;
case LibInput::Key::F: ansi_c_str = "\x06"; break;
case LibInput::Key::G: ansi_c_str = "\x07"; break;
case LibInput::Key::H: ansi_c_str = "\x08"; break;
case LibInput::Key::I: ansi_c_str = "\x09"; break;
case LibInput::Key::J: ansi_c_str = "\x0A"; break;
case LibInput::Key::K: ansi_c_str = "\x0B"; break;
case LibInput::Key::L: ansi_c_str = "\x0C"; break;
case LibInput::Key::M: ansi_c_str = "\x0D"; break;
case LibInput::Key::N: ansi_c_str = "\x0E"; break;
case LibInput::Key::O: ansi_c_str = "\x0F"; break;
case LibInput::Key::P: ansi_c_str = "\x10"; break;
case LibInput::Key::Q: ansi_c_str = "\x11"; break;
case LibInput::Key::R: ansi_c_str = "\x12"; break;
case LibInput::Key::S: ansi_c_str = "\x13"; break;
case LibInput::Key::T: ansi_c_str = "\x14"; break;
case LibInput::Key::U: ansi_c_str = "\x15"; break;
case LibInput::Key::V: ansi_c_str = "\x16"; break;
case LibInput::Key::W: ansi_c_str = "\x17"; break;
case LibInput::Key::X: ansi_c_str = "\x18"; break;
case LibInput::Key::Y: ansi_c_str = "\x19"; break;
case LibInput::Key::Z: ansi_c_str = "\x1A"; break;
default: break;
}
}
else
{
switch (event.key)
{
case LibInput::Key::Enter:
case LibInput::Key::NumpadEnter:
ansi_c_str = "\n";
break;
case LibInput::Key::Backspace:
ansi_c_str = "\b";
break;
case LibInput::Key::Escape:
ansi_c_str = "\e";
break;
case LibInput::Key::Delete:
ansi_c_str = "\x7F";
break;
case LibInput::Key::ArrowUp:
ansi_c_str = "\e[A";
break;
case LibInput::Key::ArrowDown:
ansi_c_str = "\e[B";
break;
case LibInput::Key::ArrowRight:
ansi_c_str = "\e[C";
break;
case LibInput::Key::ArrowLeft:
ansi_c_str = "\e[D";
break;
default:
break;
}
}
if (ansi_c_str) if (ansi_c_str)
{ {
auto* ptr = (const uint8_t*)ansi_c_str; auto* ptr = reinterpret_cast<const uint8_t*>(ansi_c_str);
while (*ptr) while (*ptr)
handle_input_byte(*ptr++); handle_input_byte(*ptr++);
} }

View File

@ -58,10 +58,10 @@ namespace LibInput
"å", "ä", "ö", "å", "ä", "ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
/*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\x7F", nullptr, nullptr, nullptr, nullptr, "\n", " ", /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\e[3~", nullptr, nullptr, nullptr, nullptr, "\n", " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½", "!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}", "(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", "¸", "\b \b", "@", "£", "$", "", "=", "?", "+", "\\", "´", "`", "¨", "¸", "\x7F", "@", "£", "$", "",
"\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C", "'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C",
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦", ",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦",
@ -77,10 +77,10 @@ namespace LibInput
"Å", "Ä", "Ö", "Å", "Ä", "Ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
/*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\x7F", nullptr, nullptr, nullptr, nullptr, "\n", " ", /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\e[3~", nullptr, nullptr, nullptr, nullptr, "\n", " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½", "!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}", "(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", "¸", "\b \b", "@", "£", "$", "", "=", "?", "+", "\\", "´", "`", "¨", "¸", "\x7F", "@", "£", "$", "",
"\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C", "'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C",
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦", ",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦",
@ -96,10 +96,10 @@ namespace LibInput
"Å", "Ä", "Ö", "Å", "Ä", "Ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
/*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\x7F", nullptr, nullptr, nullptr, nullptr, "\n", " ", /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\e[3~", nullptr, nullptr, nullptr, nullptr, "\n", " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½", "!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}", "(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", "¸", "\b \b", "@", "£", "$", "", "=", "?", "+", "\\", "´", "`", "¨", "¸", "\x7F", "@", "£", "$", "",
"\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C", "'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C",
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦", ",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦",

File diff suppressed because it is too large Load Diff

View File

@ -114,6 +114,7 @@ int main()
setenv("HOME", pwd->pw_dir, 1); setenv("HOME", pwd->pw_dir, 1);
chdir(pwd->pw_dir); chdir(pwd->pw_dir);
setenv("SHELL", pwd->pw_shell, 1);
char shell_path[PATH_MAX]; char shell_path[PATH_MAX];
strcpy(shell_path, pwd->pw_shell); strcpy(shell_path, pwd->pw_shell);