diff --git a/front-end b/front-end index a5a157a..cee23ca 160000 --- a/front-end +++ b/front-end @@ -1 +1 @@ -Subproject commit a5a157ad561879fdb801b81d37a3490d05fd89e3 +Subproject commit cee23ca951bd1c07b9c1d1d1334f18c0894cc028 diff --git a/user/apars_utf8.c b/user/apars_utf8.c index 17b7387..832cde8 100644 --- a/user/apars_utf8.c +++ b/user/apars_utf8.c @@ -87,12 +87,15 @@ apars_handle_plainchar(char c) else { bytes[utf_j++] = c; if (utf_j >= utf_len) { - // check for bad sequences + // check for bad sequences - overlong or some other problem if (bytes[0] == 0xF4 && bytes[1] > 0x8F) goto fail; if (bytes[0] == 0xF0 && bytes[1] < 0x90) goto fail; if (bytes[0] == 0xED && bytes[1] > 0x9F) goto fail; if (bytes[0] == 0xE0 && bytes[1] < 0xA0) goto fail; + // trap for surrogates - those break javascript + if (bytes[0] == 0xED && bytes[1] >= 0xA0 && bytes[1] <= 0xBF) goto fail; + screen_putchar((const char *) bytes); apars_reset_utf8buffer(); } @@ -113,5 +116,5 @@ fail: apars_show_context(); apars_reset_utf8buffer(); ansi_dbg("Temporarily inhibiting parser..."); - TIMER_START(&timerResumeRx, resumeRxCb, 1000, 0); + TIMER_START(&timerResumeRx, resumeRxCb, 500, 0); } diff --git a/user/cgi_sockets.c b/user/cgi_sockets.c index 4824615..c91bb2b 100644 --- a/user/cgi_sockets.c +++ b/user/cgi_sockets.c @@ -21,6 +21,7 @@ volatile ScreenNotifyTopics pendingBroadcastTopics = 0; // flags for screen update timeouts volatile bool notify_available = true; volatile bool notify_cooldown = false; +volatile bool notify_scheduled = false; /** True if we sent XOFF to browser to stop uploading, * and we have to tell it we're ready again */ @@ -109,6 +110,7 @@ updateNotifyCb(void *arg) updateNotify_do(arg, 0); + notify_scheduled = false; notify_cooldown = true; TIMER_START(¬ifyCooldownTim, notifyCooldownTimCb, termconf->display_cooldown_ms, 0); @@ -146,17 +148,16 @@ void ICACHE_FLASH_ATTR screen_notifyChange(ScreenNotifyTopics topics) { if (term_active_clients == 0) return; - // this is probably not needed here - ensure timeout is not 0 - if (termconf->display_tout_ms == 0) { - termconf->display_tout_ms = SCR_DEF_DISPLAY_TOUT_MS; - } - inp_dbg("Notify +%02Xh", topics); pendingBroadcastTopics |= topics; + int time = termconf->display_tout_ms; + if (time == 0 && notify_scheduled) return; // do not reset the timer if already scheduled + + notify_scheduled = true; // NOTE: the timer is restarted if already running - TIMER_START(&updateNotifyTim, updateNotifyCb, termconf->display_tout_ms, 0); // note - this adds latency to beep + TIMER_START(&updateNotifyTim, updateNotifyCb, time, 0); // note - this adds latency to beep } /** diff --git a/user/cgi_term_cfg.c b/user/cgi_term_cfg.c index 85f810e..2f5275a 100644 --- a/user/cgi_term_cfg.c +++ b/user/cgi_term_cfg.c @@ -148,7 +148,7 @@ cgiTermCfgSetParams(HttpdConnData *connData) if (GET_ARG("display_tout_ms")) { cgi_dbg("Display update idle timeout: %s ms", buff); n = atoi(buff); - if (n > 0) { + if (n >= 0) { termconf->display_tout_ms = n; } else { cgi_warn("Bad update timeout %s", buff); diff --git a/user/screen.c b/user/screen.c index 8a6796a..eba8b88 100644 --- a/user/screen.c +++ b/user/screen.c @@ -239,12 +239,8 @@ terminal_apply_settings_noclear(void) termconf->config_version = TERMCONF_VERSION; // Validation... - if (termconf->display_tout_ms == 0) { - termconf->display_tout_ms = SCR_DEF_DISPLAY_TOUT_MS; - changed = 1; - } if (termconf->display_cooldown_ms == 0) { - termconf->display_cooldown_ms = SCR_DEF_DISPLAY_COOLDOWN_MS; + termconf->display_cooldown_ms = 1; changed = 1; } @@ -1781,7 +1777,7 @@ utf8_remap(char *out, char g, char charset) break; } - utf8_encode(out, utf); + utf8_encode(out, utf, false); } //endregion @@ -1841,7 +1837,7 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, ScreenNotifyTopics topics, } while(0) #define bufput_utf8(num) do { \ - nbytes = utf8_encode(bb, (num)+1); \ + nbytes = utf8_encode(bb, (num)+1, true); \ bb += nbytes; \ remain -= nbytes; \ } while(0) @@ -1957,11 +1953,15 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, ScreenNotifyTopics topics, bufput_utf8(W); bufput_utf8(termconf_live.theme); - bufput_utf8(termconf_live.default_fg & 0xFFF); - bufput_utf8((u32)(termconf_live.default_fg >> 16) & 0xFFFF); + bufput_utf8(termconf_live.default_fg & 0xFFFF); + bufput_utf8((termconf_live.default_fg >> 16) & 0xFFFF); + + dbg("Fg %04X,%04X", termconf_live.default_fg & 0xFFFF, (termconf_live.default_fg >> 16) & 0xFFFF); + + bufput_utf8(termconf_live.default_bg & 0xFFFF); + bufput_utf8((termconf_live.default_bg >> 16) & 0xFFFF); - bufput_utf8(termconf_live.default_bg & 0xFFF); - bufput_utf8((u32)(termconf_live.default_bg >> 16) & 0xFFFF); + dbg("Bg %04X,%04X", termconf_live.default_bg & 0xFFFF, (termconf_live.default_bg >> 16) & 0xFFFF); bufput_utf8( (scr.cursor_visible << 0) | diff --git a/user/utf8.c b/user/utf8.c index 3d4c693..b615279 100644 --- a/user/utf8.c +++ b/user/utf8.c @@ -160,8 +160,13 @@ unicode_cache_remove(UnicodeCacheRef ref) * @return number of bytes on success, 0 on failure (also produces U+FFFD, which uses 3 bytes) */ int ICACHE_FLASH_ATTR -utf8_encode(char *out, uint32_t utf) +utf8_encode(char *out, uint32_t utf, bool surrogateFix) { + // Skip the surrogate block (wtf, unicode???) + if (surrogateFix && utf >= 0xD800) { + utf += 0x800; + } + if (utf <= 0x7F) { // Plain ASCII out[0] = (char) utf; diff --git a/user/utf8.h b/user/utf8.h index c24bf07..675545a 100644 --- a/user/utf8.h +++ b/user/utf8.h @@ -63,9 +63,10 @@ bool unicode_cache_remove(UnicodeCacheRef ref); * * @param out - output buffer (min 4 characters), will be 0-terminated if shorten than 4 * @param utf - code point 0-0x10FFFF + * @param surrogateFix - add 0x800 to 0xD800-0xDFFF to avoid invalid code points * @return number of bytes on success, 0 on failure (also produces U+FFFD, which uses 3 bytes) */ -int utf8_encode(char *out, uint32_t utf); +int utf8_encode(char *out, uint32_t utf, bool surrogateFix); #if DEBUG_UTFCACHE #define utfc_warn warn