Fixed the stupid unicode bug

http-comm
Ondřej Hruška 7 years ago
parent 3b7cd0a42e
commit 3926776adc
  1. 1
      html_orig/jssrc/term_conn.js
  2. 89
      html_orig/jssrc/term_screen.js
  3. 4
      html_orig/jssrc/utils.js
  4. 7
      html_orig/sass/pages/_term.scss
  5. 6
      user/screen.c

@ -11,6 +11,7 @@ var Conn = (function () {
function onOpen(evt) { function onOpen(evt) {
console.log("CONNECTED"); console.log("CONNECTED");
heartbeat();
doSend("i"); doSend("i");
} }

@ -160,9 +160,9 @@ class TermScreen {
let getTouchPositionOffset = touch => { let getTouchPositionOffset = touch => {
let rect = this.canvas.getBoundingClientRect(); let rect = this.canvas.getBoundingClientRect();
return [touch.clientX - rect.left, touch.clientY - rect.top]; return [touch.clientX - rect.left, touch.clientY - rect.top];
} };
this.canvas.addEventListener('touchstart', e => { this.canvas.addEventListener('touchstart', e => {
touchPosition = getTouchPositionOffset(e.touches[0]) touchPosition = getTouchPositionOffset(e.touches[0]);
touchDidMove = false; touchDidMove = false;
touchDownTime = Date.now(); touchDownTime = Date.now();
}); });
@ -651,7 +651,7 @@ class TermScreen {
let bg = 0; let bg = 0;
let attrs = 0; let attrs = 0;
let cell = 0; // cell index let cell = 0; // cell index
let text = ' '; let lastChar = ' ';
let screenLength = this.window.width * this.window.height; let screenLength = this.window.width * this.window.height;
this.screen = new Array(screenLength).fill(' '); this.screen = new Array(screenLength).fill(' ');
@ -659,47 +659,56 @@ class TermScreen {
this.screenBG = new Array(screenLength).fill(' '); this.screenBG = new Array(screenLength).fill(' ');
this.screenAttrs = new Array(screenLength).fill(' '); this.screenAttrs = new Array(screenLength).fill(' ');
while (i < str.length && cell < screenLength) { let strArr = (typeof Array.from !== 'undefined' ? Array.from(str) : str.split(''));
let character = str[i++]; while (i < strArr.length && cell < screenLength) {
let charCode = character.charCodeAt(0); let character = strArr[i++];
let charCode = character.codePointAt(0);
let data, count;
switch (charCode) {
case SEQ_SET_COLOR_ATTR:
data = parse3B(strArr[i]+strArr[i+1]+strArr[i+2]);
i += 3;
fg = data & 0xF;
bg = data >> 4 & 0xF;
attrs = data >> 8 & 0xFF;
break;
if (charCode === SEQ_SET_COLOR_ATTR) { case SEQ_SET_COLOR:
let data = parse3B(str, i); data = parse2B(strArr[i]+strArr[i+1]);
i += 3; i += 2;
fg = data & 0xF; fg = data & 0xF;
bg = data >> 4 & 0xF; bg = data >> 4 & 0xF;
attrs = data >> 8 & 0xFF break;
}
else if (charCode == SEQ_SET_COLOR) { case SEQ_SET_ATTR:
let data = parse2B(str, i); data = parse2B(strArr[i]+strArr[i+1]);
i += 2; i += 2;
fg = data & 0xF; attrs = data & 0xFF;
bg = data >> 4 & 0xF break;
}
else if (charCode === SEQ_SET_ATTR) { case SEQ_REPEAT:
let data = parse2B(str, i); count = parse2B(strArr[i]+strArr[i+1]);
i += 2; i += 2;
attrs = data & 0xFF for (let j = 0; j < count; j++) {
} this.screen[cell] = lastChar;
else if (charCode === SEQ_REPEAT) { this.screenFG[cell] = fg;
let count = parse2B(str, i); this.screenBG[cell] = bg;
i += 2; this.screenAttrs[cell] = attrs;
for (let j = 0; j < count; j++) {
this.screen[cell] = text; if (++cell > screenLength) break;
}
break;
default:
// safety replacement
if (charCode < 32) character = '\ufffd';
// unique cell character
this.screen[cell] = lastChar = character;
this.screenFG[cell] = fg; this.screenFG[cell] = fg;
this.screenBG[cell] = bg; this.screenBG[cell] = bg;
this.screenAttrs[cell] = attrs; this.screenAttrs[cell] = attrs;
cell++;
if (++cell > screenLength) break
}
}
else {
// unique cell character
this.screen[cell] = text = character;
this.screenFG[cell] = fg;
this.screenBG[cell] = bg;
this.screenAttrs[cell] = attrs;
cell++
} }
} }

@ -128,12 +128,12 @@ function Chr(n) {
} }
/** Decode number from 2B encoding */ /** Decode number from 2B encoding */
function parse2B(s, i) { function parse2B(s, i=0) {
return (s.charCodeAt(i++) - 1) + (s.charCodeAt(i) - 1) * 127; return (s.charCodeAt(i++) - 1) + (s.charCodeAt(i) - 1) * 127;
} }
/** Decode number from 3B encoding */ /** Decode number from 3B encoding */
function parse3B(s, i) { function parse3B(s, i=0) {
return (s.charCodeAt(i) - 1) + (s.charCodeAt(i+1) - 1) * 127 + (s.charCodeAt(i+2) - 1) * 127 * 127; return (s.charCodeAt(i) - 1) + (s.charCodeAt(i+1) - 1) * 127 + (s.charCodeAt(i+2) - 1) * 127 * 127;
} }

@ -43,7 +43,12 @@ body.term {
background: none; background: none;
border: none; border: none;
resize: none; resize: none;
// visible for debugging. do opacity 0 later on overflow: hidden;
opacity: 0;
outline: 0 none !important;
caret-color: transparent;
color: transparent;
@include click-through;
} }
#touch-select-menu { #touch-select-menu {

@ -1396,10 +1396,10 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
// copy the symbol, until first 0 or reached 4 bytes // copy the symbol, until first 0 or reached 4 bytes
char c; char c;
int j = 0; for(int j=0; j<4; j++) {
while ((c = cell->c[j]) != 0 && j < 4) { c = cell->c[j];
if(!c) break;
bufput_c(c); bufput_c(c);
j++;
} }
ss->lastFg = cell0->fg; ss->lastFg = cell0->fg;

Loading…
Cancel
Save