-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#144 Add interactive command line debugger support
WIP
- Loading branch information
1 parent
a3216af
commit 1300a04
Showing
13 changed files
with
300 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Cam Mannett 2021 | ||
* | ||
* See LICENSE file | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "malbolge/virtual_memory.hpp" | ||
|
||
namespace malbolge | ||
{ | ||
class argument_parser; | ||
|
||
/** Namespace for all GUI types and functions. | ||
*/ | ||
namespace ui | ||
{ | ||
/** Represents an interactive terminal GUI, based on ncurses. | ||
* | ||
* This class can be moved, but not copied. | ||
*/ | ||
class terminal | ||
{ | ||
public: | ||
/** Constructor. | ||
* | ||
* @param arg_parser Arguments from the command line to influence initial | ||
* behaviour | ||
* @param vmem Preloaded virtual memory, if it has been specified on the | ||
* commandline | ||
*/ | ||
explicit terminal(const argument_parser& arg_parser, | ||
std::optional<virtual_memory> vmem = {}); | ||
|
||
terminal(const terminal&) = delete; | ||
terminal& operator=(const terminal&) = delete; | ||
terminal(terminal&&) noexcept = default; | ||
terminal& operator=(terminal&&) noexcept = delete; | ||
|
||
/** Runs the interactive terminal UI. | ||
* | ||
* This function blocks until the UI is exited, which should signal the | ||
* application to exit. | ||
* @exception basic_exception Thrown if called on a moved-from instance | ||
*/ | ||
void run(); | ||
|
||
private: | ||
struct impl_t; | ||
std::shared_ptr<impl_t> impl_; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Cam Mannett 2021 | ||
* | ||
* See LICENSE file | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <istream> | ||
|
||
namespace malbolge | ||
{ | ||
namespace utility | ||
{ | ||
/** Returns true if there is data available to read on @a stream. | ||
* | ||
* As expected, this will not change the current read position of stream. | ||
* | ||
* @note This will return false if <TT>!stream</TT> is true. | ||
* @tparam CharT Character type of stream | ||
* @tparam Traits Character trait type | ||
* @param stream Input stream to test | ||
* @return True if there is buffered data | ||
*/ | ||
template <typename CharT, typename Traits = std::char_traits<CharT>> | ||
bool data_available(std::basic_istream<CharT, Traits>& stream) | ||
{ | ||
const auto orig_pos = stream.tellg(); | ||
stream.seekg(0, stream.end); | ||
|
||
const auto buf_size = stream.tellg() - orig_pos; | ||
stream.seekg(orig_pos, stream.beg); | ||
|
||
return buf_size > 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Cam Mannett 2021 | ||
* | ||
* See LICENSE file | ||
*/ | ||
|
||
#include "malbolge/ui/terminal.hpp" | ||
#include "malbolge/utility/argument_parser.hpp" | ||
#include "malbolge/log.hpp" | ||
|
||
#include <boost/asio/io_context.hpp> | ||
#include <boost/asio/executor_work_guard.hpp> | ||
|
||
#include <ncurses.h> | ||
|
||
using namespace malbolge; | ||
|
||
struct ui::terminal::impl_t | ||
{ | ||
explicit impl_t(const argument_parser& arg_parser, | ||
std::optional<virtual_memory> vmem) : | ||
pdata{arg_parser.program()}, | ||
force_nn{arg_parser.force_non_normalised()}, | ||
vmem(std::move(vmem)) | ||
{} | ||
|
||
argument_parser::program_data pdata; | ||
bool force_nn; | ||
boost::asio::io_context ctx; | ||
|
||
std::optional<virtual_memory> vmem; | ||
}; | ||
|
||
ui::terminal::terminal(const argument_parser& arg_parser, | ||
std::optional<virtual_memory> vmem) : | ||
impl_{std::make_shared<impl_t>(arg_parser, std::move(vmem))} | ||
{} | ||
|
||
void ui::terminal::run() | ||
{ | ||
log::print(log::INFO, "Here"); | ||
|
||
initscr(); | ||
printw("Hello world"); | ||
refresh(); | ||
endwin(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.