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) {
console.log("CONNECTED");
heartbeat();
doSend("i");
}

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

@ -128,12 +128,12 @@ function Chr(n) {
}
/** Decode number from 2B encoding */
function parse2B(s, i) {
function parse2B(s, i=0) {
return (s.charCodeAt(i++) - 1) + (s.charCodeAt(i) - 1) * 127;
}
/** 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;
}

@ -43,7 +43,12 @@ body.term {
background: none;
border: 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 {

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

Loading…
Cancel
Save