add new OSC and configurable button count
This commit is contained in:
+60
-2
@@ -16,6 +16,41 @@
|
||||
#include "ansi_parser.h"
|
||||
#include "cgi_sockets.h"
|
||||
|
||||
/**
|
||||
* Handle ESPTerm-specific command
|
||||
*
|
||||
* @param n0 - top-level, 20-39
|
||||
* @param n1 - sub-command
|
||||
* @param buffer - buffer past the second command and its semicolon
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
handle_espterm_osc(int n0, int n1, char *buffer)
|
||||
{
|
||||
if (n0 == 27) {
|
||||
// Miscellaneous
|
||||
if (n1 == 1) {
|
||||
screen_set_backdrop(buffer);
|
||||
}
|
||||
else if (n1 == 2) {
|
||||
screen_set_button_count(atoi(buffer));
|
||||
}
|
||||
else goto bad;
|
||||
}
|
||||
else if (n0 == 28) {
|
||||
// Button label
|
||||
screen_set_button_text(n1, buffer);
|
||||
}
|
||||
else if (n0 == 29) {
|
||||
// Button message
|
||||
screen_set_button_message(n1, buffer);
|
||||
}
|
||||
else goto bad;
|
||||
return;
|
||||
|
||||
bad:
|
||||
ansi_warn("No ESPTerm option at %d.%d", n0, n1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to parse incoming OSC (Operating System Control)
|
||||
* @param buffer - the OSC body (after OSC and before ST)
|
||||
@@ -23,8 +58,9 @@
|
||||
void ICACHE_FLASH_ATTR
|
||||
apars_handle_osc(char *buffer)
|
||||
{
|
||||
const char *origbuf = buffer;
|
||||
int n = 0;
|
||||
char c = 0;
|
||||
char c;
|
||||
while ((c = *buffer++) != 0) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
n = (n * 10 + (c - '0'));
|
||||
@@ -49,16 +85,38 @@ apars_handle_osc(char *buffer)
|
||||
buffer[0] = 'G';
|
||||
notify_growl(buffer);
|
||||
}
|
||||
else if (n >= 20 && n < 40) {
|
||||
// New-style ESPTerm OSC
|
||||
int n0 = n;
|
||||
|
||||
// Find sub-command
|
||||
n = 0;
|
||||
while ((c = *buffer++) != 0) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
n = (n * 10 + (c - '0'));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c == ';') {
|
||||
handle_espterm_osc(n0, n, buffer);
|
||||
} else {
|
||||
ansi_warn("BAD OSC: %s", origbuf);
|
||||
}
|
||||
}
|
||||
else if (n == 70) {
|
||||
// ESPTerm: backdrop
|
||||
ansi_warn("OSC 70 is deprecated, use 27;1");
|
||||
screen_set_backdrop(buffer);
|
||||
}
|
||||
else if (n >= 81 && n <= 85) {
|
||||
// ESPTerm: action button label
|
||||
ansi_warn("OSC 8x is deprecated, use 28;x");
|
||||
screen_set_button_text(n - 80, buffer);
|
||||
}
|
||||
else if (n >= 91 && n <= 95) {
|
||||
// ESPTerm: action button message
|
||||
ansi_warn("OSC 9x is deprecated, use 29;x");
|
||||
screen_set_button_message(n - 90, buffer);
|
||||
}
|
||||
else {
|
||||
@@ -66,7 +124,7 @@ apars_handle_osc(char *buffer)
|
||||
}
|
||||
}
|
||||
else {
|
||||
ansi_warn("BAD OSC: %s", buffer);
|
||||
ansi_warn("BAD OSC: %s", origbuf);
|
||||
apars_show_context();
|
||||
}
|
||||
}
|
||||
|
||||
+30
-7
@@ -416,25 +416,30 @@ terminal_apply_settings_noclear(void)
|
||||
|
||||
// Migrate
|
||||
if (termconf->config_version < 1) {
|
||||
persist_dbg("termconf: Updating to version %d", 1);
|
||||
persist_dbg("termconf: Updating to version 1");
|
||||
termconf->debugbar = SCR_DEF_DEBUGBAR;
|
||||
changed = 1;
|
||||
}
|
||||
if (termconf->config_version < 2) {
|
||||
persist_dbg("termconf: Updating to version %d", 1);
|
||||
persist_dbg("termconf: Updating to version 2");
|
||||
termconf->allow_decopt_12 = SCR_DEF_DECOPT12;
|
||||
changed = 1;
|
||||
}
|
||||
if (termconf->config_version < 3) {
|
||||
persist_dbg("termconf: Updating to version %d", 1);
|
||||
persist_dbg("termconf: Updating to version 3");
|
||||
termconf->ascii_debug = SCR_DEF_ASCIIDEBUG;
|
||||
changed = 1;
|
||||
}
|
||||
if (termconf->config_version < 4) {
|
||||
persist_dbg("termconf: Updating to version %d", 1);
|
||||
persist_dbg("termconf: Updating to version 4");
|
||||
termconf->backdrop[0] = 0;
|
||||
changed = 1;
|
||||
}
|
||||
if (termconf->config_version < 5) {
|
||||
persist_dbg("termconf: Updating to version 5");
|
||||
termconf->button_count = SCR_DEF_BUTTON_COUNT;
|
||||
changed = 1;
|
||||
}
|
||||
|
||||
termconf->config_version = TERMCONF_VERSION;
|
||||
|
||||
@@ -1206,6 +1211,7 @@ screen_set_button_text(int num, const char *text)
|
||||
else if (num == 3) strncpy(termconf_live.btn3, text, TERM_BTN_LEN);
|
||||
else if (num == 4) strncpy(termconf_live.btn4, text, TERM_BTN_LEN);
|
||||
else if (num == 5) strncpy(termconf_live.btn5, text, TERM_BTN_LEN);
|
||||
else ansi_warn("Bad button num: %d", num);
|
||||
NOTIFY_DONE(TOPIC_CHANGE_BUTTONS);
|
||||
}
|
||||
|
||||
@@ -1223,6 +1229,23 @@ screen_set_button_message(int num, const char *msg)
|
||||
else if (num == 3) strncpy(termconf_live.bm3, msg, TERM_BTN_MSG_LEN);
|
||||
else if (num == 4) strncpy(termconf_live.bm4, msg, TERM_BTN_MSG_LEN);
|
||||
else if (num == 5) strncpy(termconf_live.bm5, msg, TERM_BTN_MSG_LEN);
|
||||
else ansi_warn("Bad button num: %d", num);
|
||||
NOTIFY_DONE(TOPIC_CHANGE_BUTTONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button count
|
||||
* @param count - count 1-5
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
screen_set_button_count(int count)
|
||||
{
|
||||
NOTIFY_LOCK();
|
||||
if (count >= 0 && count <= 5) {
|
||||
dbg("%d ", count);
|
||||
termconf_live.button_count = (u8) count;
|
||||
}
|
||||
else ansi_warn("Bad button count: %d", count);
|
||||
NOTIFY_DONE(TOPIC_CHANGE_BUTTONS);
|
||||
}
|
||||
|
||||
@@ -2263,12 +2286,12 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, ScreenNotifyTopics topics,
|
||||
bufput_c('\x01');
|
||||
END_TOPIC
|
||||
|
||||
BEGIN_TOPIC(TOPIC_CHANGE_BUTTONS, (TERM_BTN_LEN+4)*TERM_BTN_COUNT+1+4)
|
||||
BEGIN_TOPIC(TOPIC_CHANGE_BUTTONS, (TERM_BTN_LEN+4)*termconf_live.button_count+1+4)
|
||||
bufput_c(TOPICMARK_BUTTONS);
|
||||
|
||||
bufput_utf8(TERM_BTN_COUNT);
|
||||
bufput_utf8(termconf_live.button_count);
|
||||
|
||||
for (int i = 0; i < TERM_BTN_COUNT; i++) {
|
||||
for (int i = 0; i < termconf_live.button_count; i++) {
|
||||
size_t len = strlen(TERM_BTN_N(&termconf_live, i));
|
||||
if (len > 0) {
|
||||
memcpy(bb, TERM_BTN_N(&termconf_live, i), len);
|
||||
|
||||
+6
-3
@@ -70,6 +70,7 @@ enum CursorShape {
|
||||
#define SCR_DEF_DEBUGBAR 0
|
||||
#define SCR_DEF_DECOPT12 0
|
||||
#define SCR_DEF_ASCIIDEBUG 0
|
||||
#define SCR_DEF_BUTTON_COUNT 5
|
||||
|
||||
// --- Persistent Settings ---
|
||||
#define CURSOR_BLINKS(shape) ((shape)==CURSOR_BLOCK_BL||(shape)==CURSOR_UNDERLINE_BL||(shape)==CURSOR_BAR_BL)
|
||||
@@ -77,9 +78,9 @@ enum CursorShape {
|
||||
// Size designed for the terminal config structure
|
||||
// Must be constant to avoid corrupting user config after upgrade
|
||||
#define TERMCONF_SIZE 400
|
||||
#define TERMCONF_VERSION 4
|
||||
#define TERMCONF_VERSION 5
|
||||
|
||||
//....Type................Name..Suffix...............Deref..XGET.........Cast..XSET.........................NOTIFY................Allow
|
||||
//....Type................Name..Suffix...............Deref..XGET.........Cast..XSET...........NOTIFY..Allow
|
||||
// Deref is used to pass the field to xget. Cast is used to convert the &'d field to what xset wants (needed for static arrays)
|
||||
#define XTABLE_TERMCONF \
|
||||
X(u32, width, /**/, /**/, xget_dec, xset_u32, NULL, /**/, 1) \
|
||||
@@ -112,7 +113,8 @@ enum CursorShape {
|
||||
X(bool, debugbar, /**/, /**/, xget_bool, xset_bool, NULL, /**/, 1) \
|
||||
X(bool, allow_decopt_12, /**/, /**/, xget_bool, xset_bool, NULL, /**/, 1) \
|
||||
X(bool, ascii_debug, /**/, /**/, xget_bool, xset_bool, NULL, /**/, 1) \
|
||||
X(char, backdrop, [TERM_BACKDROP_LEN], /**/, xget_string, xset_string, TERM_BACKDROP_LEN, /**/, 1)
|
||||
X(char, backdrop, [TERM_BACKDROP_LEN], /**/, xget_string, xset_string, TERM_BACKDROP_LEN, /**/, 1) \
|
||||
X(u8, button_count, /**/, /**/, xget_dec, xset_u8, NULL, /**/, 1)
|
||||
|
||||
#define TERM_BM_N(tc, n) ((tc)->bm1+(TERM_BTN_MSG_LEN*n))
|
||||
#define TERM_BTN_N(tc, n) ((tc)->btn1+(TERM_BTN_LEN*n))
|
||||
@@ -181,6 +183,7 @@ void screen_set_title(const char *title);
|
||||
/** Set a button text */
|
||||
void screen_set_button_text(int num, const char *text);
|
||||
void screen_set_button_message(int num, const char *msg);
|
||||
void screen_set_button_count(int count);
|
||||
/** Change backdrop */
|
||||
void screen_set_backdrop(const char *url);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user