Update index.js

This commit is contained in:
BLUELOVETH 2023-04-04 21:10:02 +08:00 committed by GitHub
parent 2fd9879eec
commit f884351c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,18 +143,14 @@ function term_init() {
term.write(need_more_lines ? "... " : ">>> "); term.write(need_more_lines ? "... " : ">>> ");
break; break;
case '\u007F': // Backspace (DEL) case '\u007F': // Backspace (DEL)
// Do not delete the prompt var cnt = term._core.buffer.x-4;
if (term._core.buffer.x > 4) { // '>>> ' or '... ' if(cnt<=0 || command.length==0) break;
var re=/[^\u4E00-\u9FA5]/; // delete the last unicode char
if (re.test(command.charAt(command.length-1))){//判断前一个字符是否为中文 command = command.replace(/.$/u, "");
term.write('\b \b');//false // clear the whole line
}else{ term.write('\b \b'.repeat(cnt));
term.write('\b\b \b');//中文占两个字节ascii字符占一个字节 // re-write the command
} term.write(command);
if (command.length > 0) {
command = command.substr(0, command.length - 1);
}
}
break; break;
default: // Print all other characters for demo default: // Print all other characters for demo
if (e >= String.fromCharCode(0x20) && e <= String.fromCharCode(0x7E) || e >= '\u00a0') { if (e >= String.fromCharCode(0x20) && e <= String.fromCharCode(0x7E) || e >= '\u00a0') {