Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding term.forceUpdate() function. #344

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions api/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Terminal {

// The following fields are available in API version 10.1 and later.
bool frozen = false; // Whether the terminal should stop rendering
bool forcedUpdate = false; // Ignores `frozen` to render the terminal once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be placed at the end of the class - the current position would break ABI.


// The following fields are available in API version 10.2 and later.
std::list<uint8_t> mouseButtonOrder; // An ordered list of mouse buttons that have been pressed
Expand Down
10 changes: 10 additions & 0 deletions src/apis/term.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ static int term_getFrozen(lua_State *L) {
return 1;
}

static int term_forceUpdate(lua_State *L) {
lastCFunction = __func__;
Terminal * term = get_comp(L)->term;
if (term == NULL) return 0;
std::lock_guard<std::mutex> lock(term->locked);
term->forcedUpdate = true;
return 0;
}

/* export */ int term_benchmark(lua_State *L) {
lastCFunction = __func__;
if (get_comp(L)->term == NULL) return 0;
Expand Down Expand Up @@ -695,6 +704,7 @@ static luaL_Reg term_reg[] = {
{"relativeMouse", term_relativeMouse},
{"setFrozen", term_setFrozen},
{"getFrozen", term_getFrozen},
{"forceUpdate", term_forceUpdate},
{NULL, NULL}
};

Expand Down
8 changes: 8 additions & 0 deletions src/peripheral/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ int monitor::setBlockSize(lua_State *L) {
return 0;
}

int monitor::forceUpdate(lua_State *L) {
lastCFunction = __func__;
if (term == NULL) return 0;
std::lock_guard<std::mutex> lock(term->locked);
term->forcedUpdate = true;
return 0;
}

int monitor::call(lua_State *L, const char * method) {
std::string m(method);
if (m == "write") return write(L);
Expand Down
1 change: 1 addition & 0 deletions src/peripheral/monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class monitor : public peripheral {
int getFrozen(lua_State *L);
int setSize(lua_State *L);
int setBlockSize(lua_State *L);
int forceUpdate(lua_State *L);
public:
Terminal * term;
static library_t methods;
Expand Down
3 changes: 2 additions & 1 deletion src/termsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,9 @@ static bool renderTerminal(Terminal * term, bool& pushEvent) {
term->last_blink = std::chrono::high_resolution_clock::now();
term->changed = true;
}
if (term->frozen) return false;
if (term->frozen && !term->forcedUpdate) return false;
changed = term->changed;
term->forcedUpdate = false;
}
try {
term->render();
Expand Down
Loading