more robust multilingual print

This commit is contained in:
minjaesong
2021-12-26 10:00:07 +09:00
parent 100690d501
commit 04d77b16dc
3 changed files with 16 additions and 16 deletions

View File

@@ -431,7 +431,10 @@ con.getch = function() {
return sys.readKey(); return sys.readKey();
}; };
con.move = function(y, x) { con.move = function(y, x) {
print("\x1B["+(y|0)+";"+(x|0)+"H"); //print("\x1B["+(y|0)+";"+(x|0)+"H");
// NOT using ANSI escape sequence as it conflicts with some multilingual drive which redefines PRINT function
// and obviously this method is faster albeit less genuine :p
graphics.setCursorYX(y|0, x|0);
}; };
con.addch = function(c) { con.addch = function(c) {
graphics.putSymbol(c|0); graphics.putSymbol(c|0);
@@ -446,20 +449,20 @@ con.getyx = function() {
return graphics.getCursorYX(); return graphics.getCursorYX();
}; };
con.curs_up = function() { con.curs_up = function() {
let c = graphics.getCursorYX(); let [y,x] = graphics.getCursorYX();
con.move(c[0]-1,c[1]); con.move(y-1,x);
}; };
con.curs_down = function() { con.curs_down = function() {
let c = graphics.getCursorYX(); let [y,x] = graphics.getCursorYX();
con.move(c[0]+1,c[1]); con.move(y+1,x);
}; };
con.curs_left = function() { con.curs_left = function() {
let c = graphics.getCursorYX(); let [y,x] = graphics.getCursorYX();
con.move(c[0],c[1]-1); con.move(y,x-1);
}; };
con.curs_right = function() { con.curs_right = function() {
let c = graphics.getCursorYX(); let [y,x] = graphics.getCursorYX();
con.move(c[0],c[1]+1); con.move(y,x+1);
}; };
con.hitterminate = function() { // ^C con.hitterminate = function() { // ^C
sys.poke(-40, 1); sys.poke(-40, 1);

View File

@@ -330,17 +330,14 @@ unicode.getUniprint = (c) => {
print = function(str) { print = function(str) {
if ((typeof str === 'string' || str instanceof String) && str.length > 0) { if ((typeof str === 'string' || str instanceof String) && str.length > 0) {
let cp = unicode.utf8toCodepoints(str) let cp = unicode.utf8toCodepoints(str)
let q = unicode.getUniprint(cp[0])
cp.forEach(c => { cp.forEach(c => {
if (q == undefined) { let q = unicode.getUniprint(c)
if (q == undefined || !q[0](c)) {
con.addch(4) con.addch(4)
con.curs_right() con.curs_right()
} }
else if (q[0](c)) {
q[1](c)
}
else { else {
q = unicode.getUniprint(c)
q[1](c) q[1](c)
} }
}) })

View File

@@ -97,7 +97,7 @@ class GraphicsJSR223Delegate(val vm: VM) {
fun setCursorYX(cy: Int, cx: Int) { fun setCursorYX(cy: Int, cx: Int) {
getFirstGPU()?.let { getFirstGPU()?.let {
it.setCursorPos(cy - 1, cx - 1) it.setCursorPos(cx - 1, cy - 1)
} }
} }