-
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 c6e1272
Showing
26 changed files
with
1,344 additions
and
41 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
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/utility/argument_parser.hpp" | ||
|
||
namespace malbolge | ||
{ | ||
/** Namespace for all GUI types and functions. | ||
*/ | ||
namespace ui | ||
{ | ||
/** Namespace for an interactive terminal GUI, based on ncurses. | ||
*/ | ||
namespace terminal | ||
{ | ||
/** Core terminal functionality. | ||
* | ||
* This class can be moved, but not copied. | ||
*/ | ||
class core | ||
{ | ||
public: | ||
/** Constructor. | ||
* | ||
* @param program_data Program data | ||
*/ | ||
explicit core(argument_parser::program_data program_data); | ||
|
||
core(const core&) = delete; | ||
core& operator=(const core&) = delete; | ||
core(core&&) noexcept = default; | ||
core& operator=(core&&) 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: | ||
// We use PIMPL to minimise the amount of TUs that import the ncurses header | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* Cam Mannett 2021 | ||
* | ||
* See LICENSE file | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <optional> | ||
|
||
namespace malbolge | ||
{ | ||
namespace ui | ||
{ | ||
namespace terminal | ||
{ | ||
class pane; | ||
|
||
/** Manages the layout of panes inside the terminal. | ||
* | ||
* This class can be moved but not copied. | ||
*/ | ||
class layout | ||
{ | ||
public: | ||
/** Alias for an owning pointer. | ||
*/ | ||
using pane_ptr = std::shared_ptr<pane>; | ||
|
||
/** The direction to split a pane into two. | ||
*/ | ||
enum class split_direction { | ||
HORIZONTAL, | ||
VERTICAL | ||
}; | ||
|
||
/** Constructor. | ||
* | ||
* @param lines Number of lines in the whole terminal | ||
* @param cols Number of columns in the whole terminal | ||
*/ | ||
explicit layout(std::size_t lines, std::size_t cols); | ||
|
||
/** Replace the existing pane (or empty root) with @a new_pane. | ||
* | ||
* @param new_pane New pane | ||
* @param existing_pane An existing pane to replace, or null to replace the | ||
* root | ||
* @exception basic_exception Thrown if @a new_pane is null, or is | ||
* @a existing_pane is non-null but cannot be found in the layout | ||
*/ | ||
void replace(pane_ptr new_pane, pane_ptr existing_pane = {}); | ||
|
||
/** Split @a parent and add @a new_pane to the opened slot. | ||
* | ||
* The parent of a split is either the top or left pane depending on @a dir. | ||
* @param new_pane New pane | ||
* @param dir Direction to split @a parent | ||
* @param parent Pane to split | ||
* @exception basic_exception Thrown if @a new_pane or @a parent is null, or | ||
* if @a parent cannot be found in the layout | ||
* @exception basic_exception Thrown if @a parent cannot be split anymore | ||
*/ | ||
void split(pane_ptr new_pane, split_direction dir, pane_ptr parent); | ||
|
||
/** Inform the layout engine that the terminal has been resized. | ||
* | ||
* This will trigger a redraw of all child panes. | ||
* @param lines New line count | ||
* @param cols New column count | ||
*/ | ||
void terminal_resize(std::size_t lines, std::size_t cols); | ||
|
||
/** Trigger a redraw of all the panes in the layout. | ||
* | ||
* This should be called after the layout has been modified. | ||
*/ | ||
void refresh() noexcept | ||
{ | ||
refresh(root_); | ||
} | ||
|
||
layout(layout&&) = default; | ||
layout& operator=(layout&&) = default; | ||
layout(const layout&) = delete; | ||
layout& operator=(const layout&) = delete; | ||
|
||
private: | ||
struct node; | ||
using node_ptr = std::shared_ptr<node>; | ||
|
||
void recalculate_dimensions(node_ptr start_node); | ||
void refresh(node_ptr start_node) noexcept; | ||
|
||
[[nodiscard]] | ||
node_ptr find(std::shared_ptr<pane> target, node_ptr start_node) noexcept; | ||
|
||
[[nodiscard]] | ||
node_ptr find(std::shared_ptr<pane> target) noexcept | ||
{ | ||
return find(std::move(target), root_); | ||
} | ||
|
||
std::size_t lines_; | ||
std::size_t cols_; | ||
node_ptr root_; | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.