MalachScript/repl/ResultWindow.hpp

59 lines
1.9 KiB
C++

#ifndef MALACHSCRIPT_RESULTWINDOW_HPP
#define MALACHSCRIPT_RESULTWINDOW_HPP
#include <ncurses.h>
#include <sstream>
#include "../src/Binder/BoundNamespaceStringifier.hpp"
#include "../src/Parser/Statements/ParsedStatementStringifier.hpp"
namespace MalachScriptRepl {
class ResultWindow {
public:
enum class View { ParseTree, TypeList };
ResultWindow(int height, int width, int y, int x) { _window = newwin(height, width, y, x); }
void SetResult(const MalachScript::Parser::ParsedStatement* statement,
const MalachScript::Binder::BoundNamespace* ns) {
std::stringstream parsedTreeStringStream;
MalachScript::Parser::ParsedStatementStringifier::Stringify(statement, parsedTreeStringStream, "", true);
_parseTree = parsedTreeStringStream.str();
std::stringstream boundNamespaceStringStream;
MalachScript::Binder::BoundNamespaceStringifier::Stringify(ns, boundNamespaceStringStream);
_boundNamespace = boundNamespaceStringStream.str();
switch (_view) {
case View::ParseTree: SetParseTree(); break;
case View::TypeList: SetTypeList(); break;
}
}
void SetView(View view) {
_view = view;
switch (view) {
case View::ParseTree: SetParseTree(); break;
case View::TypeList: SetTypeList(); break;
}
}
private:
WINDOW* _window;
std::string _parseTree;
std::string _boundNamespace;
View _view;
inline void SetParseTree() {
wclear(_window);
waddstr(_window, _parseTree.c_str());
wrefresh(_window);
}
inline void SetTypeList() {
wclear(_window);
waddstr(_window, _boundNamespace.c_str());
wrefresh(_window);
}
};
}
#endif // MALACHSCRIPT_RESULTWINDOW_HPP