Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jobs:
container: devkitpro/devkitarm:latest

steps:
- name: Uninstall system libnds, build and install my fork
run: |
sudo dkp-pacman -Rdd libnds --noconfirm
git clone https://github.com/trustytrojan/libnds -b ansi-colors
cd libnds
sudo -E make install -j$(nproc)

- name: Checkout code
uses: actions/checkout@v4

Expand Down
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ set(CURL_DISABLE_INSTALL ON)
set(CURL_DISABLE_BINDLOCAL ON)
set(CURL_DISABLE_SOCKETPAIR ON)

set(CURL_USE_MBEDTLS ON) # disables openssl by implication
set(MBEDTLS_LIBRARIES mbedx509 mbedcrypto mbedtls) # may not be necessary
set(CURL_USE_MBEDTLS ON)
set(MBEDTLS_LIBRARIES mbedx509 mbedcrypto mbedtls)

set(ENABLE_CURL_MANUAL OFF)
set(ENABLE_UNIX_SOCKETS OFF)
Expand Down Expand Up @@ -96,13 +96,26 @@ execute_process(

## sol2
set(SOL2_ENABLE_INSTALL OFF)
add_compile_definitions(SOL_EXCEPTIONS=0)
FetchContent_Declare(sol2 URL https://github.com/ThePhD/sol2/archive/develop.zip)
FetchContent_MakeAvailable(sol2)

## libssh2
set(CRYPTO_BACKEND mbedTLS)
set(ENABLE_ZLIB_COMPRESSION OFF)
set(CLEAR_MEMORY OFF)
set(BUILD_EXAMPLES OFF)
set(BUILD_TESTING OFF)
set(MBEDTLS_INCLUDE_DIR ${mbedtls_SOURCE_DIR}/include)
set(MBEDCRYPTO_LIBRARY mbedcrypto)
add_compile_definitions(LIBSSH2_MBEDTLS _3DS)
FetchContent_Declare(libssh2 URL https://github.com/trustytrojan/libssh2/archive/1.11.1-nds.zip)
FetchContent_MakeAvailable(libssh2)

## nds-shell
add_compile_options(-fno-rtti -fno-exceptions)
add_compile_definitions(SOL_EXCEPTIONS=0)
include_directories(include ${curl_SOURCE_DIR}/include)
link_libraries(dswifi9 fat lua_static sol2 libcurl)
include_directories(include)
link_libraries(dswifi9 fat lua_static sol2 libcurl libssh2)

file(GLOB_RECURSE SOURCES src/**)
add_executable(nds-shell ${SOURCES})
Expand Down
3 changes: 2 additions & 1 deletion include/Commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void wifi(const Context &);
void curl(const Context &);
void tcp(const Context &);
void lua(const Context &);
void source(const Context &);
void ssh(const Context &);
// void source(const Context &);

// the smaller commands are defined in Commands.cpp
using Fn = void (*)(const Context &);
Expand Down
2 changes: 1 addition & 1 deletion src/CliPrompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void CliPrompt::setLineHistory(const std::string &filename)
std::ifstream lineHistoryFile{filename};
if (!lineHistoryFile)
{
std::cerr << "\e[41mfailed to load line history\n\e[39m";
std::cerr << "\e[91mfailed to load line history\n\e[39m";
return;
}

Expand Down
25 changes: 13 additions & 12 deletions src/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ void ls(const Context &ctx)

if (!fs::exists(path))
{
ctx.err << "\e[41mpath does not exist\e[39m\n";
ctx.err << "\e[91mpath does not exist\e[39m\n";
return;
}

for (const auto &entry : fs::directory_iterator{path})
{
const auto filename = entry.path().filename().string();
if (entry.is_directory())
ctx.out << "\e[44m" << filename << "\e[39m ";
ctx.out << "\e[94m" << filename << "\e[39m ";
else
ctx.out << filename << ' ';
ctx.out << '\n';
Expand All @@ -64,7 +64,7 @@ void cd(const Context &ctx)

if (!fs::exists(path))
{
ctx.err << "\e[41mpath does not exist\e[39m\n";
ctx.err << "\e[91mpath does not exist\e[39m\n";
return;
}

Expand All @@ -80,7 +80,7 @@ void cat(const Context &ctx)
// this gets you stuck in the cat command,
// unless i make stdin nonblocking and use threads
// so you can "ctrl+c" by pressing the fold key
ctx.err << "\e[41mcat: not using stdin\e[39m\n";
ctx.err << "\e[91mcat: not using stdin\e[39m\n";
return;
}

Expand All @@ -91,20 +91,20 @@ void cat(const Context &ctx)
std::error_code ec;
if (!fs::exists(ctx.args[1], ec) && !ec)
{
ctx.err << "\e[41mcat: file does not exist: " << ctx.args[1] << "\e[39m\n";
ctx.err << "\e[91mcat: file does not exist: " << ctx.args[1] << "\e[39m\n";
return;
}
else if (ec)
{
ctx.err << "\e[41mcat: " << ec.message() << "\e[39m\n";
ctx.err << "\e[91mcat: " << ec.message() << "\e[39m\n";
return;
}

const std::ifstream file{ctx.args[1]};

if (!file)
{
ctx.err << "\e[41mcat: cannot open file: " << ctx.args[1] << "\e[39m\n";
ctx.err << "\e[91mcat: cannot open file: " << ctx.args[1] << "\e[39m\n";
return;
}

Expand All @@ -123,7 +123,7 @@ void rm(const Context &ctx)
{
std::error_code ec;
if (!fs::remove(ctx.args[1], ec))
ctx.err << "\e[41mrm: failed to remove: '" << ctx.args[1] << "': " << ec.message() << "\e[39m\n";
ctx.err << "\e[91mrm: failed to remove: '" << ctx.args[1] << "': " << ec.message() << "\e[39m\n";
}
}

Expand All @@ -145,7 +145,7 @@ void dns(const Context &ctx)
const auto host = gethostbyname(ctx.args[1].c_str());
if (!host)
{
ctx.err << "\e[41mdns: gethostbyname: " << strerror(errno) << "\e[39m";
ctx.err << "\e[91mdns: gethostbyname: " << strerror(errno) << "\e[39m";
return;
}

Expand Down Expand Up @@ -191,7 +191,7 @@ void rename(const Context &ctx)
std::error_code ec;
fs::rename(ctx.args[1], ctx.args[2], ec);
if (ec)
ctx.err << "\e[41mrename: " << ec.message() << "\e[39m\n";
ctx.err << "\e[91mrename: " << ec.message() << "\e[39m\n";
}

void pwd(const Context &ctx)
Expand Down Expand Up @@ -223,7 +223,7 @@ void history(const Context &ctx)
ctx.shell.ClearLineHistory();
std::error_code ec;
if (!fs::remove("/.ndsh_history", ec))
ctx.err << "\e[41mhistory: failed to remove '.ndsh_history': " << ec.message() << "\e[39m\n";
ctx.err << "\e[91mhistory: failed to remove '.ndsh_history': " << ec.message() << "\e[39m\n";
return;
}

Expand Down Expand Up @@ -283,7 +283,8 @@ const Map MAP{
{"exit", exit},
{"lua", lua},
{"source", source},
{"poweroff", poweroff}};
{"poweroff", poweroff},
{"ssh", ssh}};

void help(const Context &ctx)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Consoles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void InitMulti()
// Sanity check
if (dot != devoptab_list[STD_ERR])
{
std::cerr << "\e[41mmulticon: stdout & stderr devices are not the same!\e[39m\n";
std::cerr << "\e[91mmulticon: stdout & stderr devices are not the same!\e[39m\n";
return;
}
}
Expand All @@ -132,7 +132,7 @@ void InitMulti()
ostr.open(std::string{dot->name} + ':');
if (!ostr)
{
std::cerr << "\e[41mmulticon: failed to open " << dot->name << "!\e[39m\n";
std::cerr << "\e[91mmulticon: failed to open " << dot->name << "!\e[39m\n";
continue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool LexDoubleQuoteString(StrItr &itr, const StrItr &lineEnd, std::string &curre

if (itr == lineEnd)
{
std::cerr << "\e[41mshell: closing `\"` not found\e[39m\n";
std::cerr << "\e[91mshell: closing `\"` not found\e[39m\n";
return false;
}

Expand All @@ -95,7 +95,7 @@ bool LexSingleQuoteString(StrItr &itr, const StrItr &lineEnd, std::string &curre

if (itr == lineEnd)
{
std::cerr << "\e[41mshell: closing `'` not found\e[39m\n";
std::cerr << "\e[91mshell: closing `'` not found\e[39m\n";
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ bool ParseInputRedirect(

if (nextItr == tokensEnd || nextItr->type != Token::Type::STRING)
{
std::cerr << "\e[41mshell: filename expected after `<`\e[39m\n";
std::cerr << "\e[91mshell: filename expected after `<`\e[39m\n";
return false;
}

const auto &filename = nextItr->value;

if (!std::filesystem::exists(filename))
{
std::cerr << "\e[41mshell: file `" << filename << "` does not exist\e[39m\n";
std::cerr << "\e[91mshell: file `" << filename << "` does not exist\e[39m\n";
return false;
}

Expand All @@ -38,7 +38,7 @@ bool ParseInputRedirect(

if (prevItr->type != Token::Type::STRING || !std::ranges::all_of(fdStr, isdigit))
{
std::cerr << "\e[41mshell: integer expected before `<`\e[39m\n";
std::cerr << "\e[91mshell: integer expected before `<`\e[39m\n";
return false;
}

Expand All @@ -57,7 +57,7 @@ bool ParseOutputRedirect(

if (nextItr == tokensEnd || nextItr->type != Token::Type::STRING)
{
std::cerr << "\e[41mshell: filename expected after `>`\e[39m\n";
std::cerr << "\e[91mshell: filename expected after `>`\e[39m\n";
return false;
}

Expand All @@ -77,7 +77,7 @@ bool ParseOutputRedirect(

if (prevItr->type != Token::Type::STRING || !std::ranges::all_of(fdStr, isdigit))
{
std::cerr << "\e[41mshell: integer expected before `<`\e[39m\n";
std::cerr << "\e[91mshell: integer expected before `<`\e[39m\n";
return false;
}

Expand Down
20 changes: 10 additions & 10 deletions src/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Shell::SourceFile(const std::string &filepath)

if (!file)
{
ostr << "\e[41mshell: cannot open file: " << filepath << "\e[39m\n";
ostr << "\e[91mshell: cannot open file: " << filepath << "\e[39m\n";
return;
}

Expand Down Expand Up @@ -67,7 +67,7 @@ void Shell::ProcessLine(std::string_view line)

if (env.contains("SHELL_DEBUG"))
{ // debug tokens
ostr << "\e[40mtokens: ";
ostr << "\e[90mtokens: ";
auto itr = tokens.cbegin();
for (; itr < tokens.cend() - 1; ++itr)
ostr << *itr << ' ';
Expand All @@ -83,7 +83,7 @@ void Shell::ProcessLine(std::string_view line)

if (args.empty() && envAssigns.empty())
{
ostr << "\e[41mshell: no args or env assigns\e[39m\n";
ostr << "\e[91mshell: no args or env assigns\e[39m\n";
return;
}

Expand All @@ -97,7 +97,7 @@ void Shell::ProcessLine(std::string_view line)

if (env.contains("SHELL_DEBUG"))
{ // debug args
ostr << "\e[40margs: ";
ostr << "\e[90margs: ";
auto itr = args.cbegin();
for (; itr < args.cend() - 1; ++itr)
ostr << '\'' << *itr << "' ";
Expand All @@ -118,7 +118,7 @@ void Shell::ProcessLine(std::string_view line)

const auto &command = args[0];

// ostr << "\e[40mcommand: '" << command << "'\n";
// ostr << "\e[90mcommand: '" << command << "'\n";

if (const auto withExtension{command + ".ndsh"}; fs::exists(withExtension))
{ // Treat .ndsh files as commands!
Expand All @@ -129,7 +129,7 @@ void Shell::ProcessLine(std::string_view line)
if (const auto itr = Commands::MAP.find(command); itr != Commands::MAP.cend())
itr->second({*out, *err, *in, args, commandEnv, *this});
else
ostr << "\e[41mshell: unknown command\e[39m\n";
ostr << "\e[91mshell: unknown command\e[39m\n";
}

void Shell::ResetStreams()
Expand Down Expand Up @@ -160,7 +160,7 @@ void Shell::RedirectOutput(int fd, const std::string &filename)
outf.open(filename);
if (!outf)
{
ostr << "\e[41mshell: cannot open file for writing: " << filename << "\e[39m\n";
ostr << "\e[91mshell: cannot open file for writing: " << filename << "\e[39m\n";
return;
}
out = &outf;
Expand All @@ -170,7 +170,7 @@ void Shell::RedirectOutput(int fd, const std::string &filename)
errf.open(filename);
if (!errf)
{
ostr << "\e[41mshell: cannot open file for writing: " << filename << "\e[39m\n";
ostr << "\e[91mshell: cannot open file for writing: " << filename << "\e[39m\n";
return;
}
err = &errf;
Expand All @@ -182,7 +182,7 @@ void Shell::RedirectInput(int fd, const std::string &filename)
inf.open(filename);
if (!inf)
{
ostr << "\e[41mshell: cannot open file for reading: " << filename << "\e[39m\n";
ostr << "\e[91mshell: cannot open file for reading: " << filename << "\e[39m\n";
return;
}
if (fd == 0)
Expand All @@ -191,7 +191,7 @@ void Shell::RedirectInput(int fd, const std::string &filename)

void Shell::StartPrompt()
{
ostr << "\e[46mgithub.com/trustytrojan/nds-shell\e[39m\n\nrun 'help' for help\n\n";
ostr << "\e[96mgithub.com/trustytrojan/nds-shell\e[39m\n\nrun 'help' for help\n\n";

prompt.prepareForNextLine();
prompt.printFullPrompt(false);
Expand Down
Loading