term.js
term.js copied to clipboard
CJK support, Copy and Paste support
The patch support CJK languages(Japanese for me) for both input(IME) and output. Also, copy and paste (Command-C,Command-V on Mac, or context menu on Windows) works. I tested on Safari, Chrome, Firefox on Mac OS X, and IE, Edge, Chrome, Safari on Windows.

To test with tty.js, following patch need to be applied.
/usr/local/lib/node_modules/tty.js/static (master)$ diff -u tty.js-orig tty.js
--- tty.js-orig 2015-11-04 17:03:14.000000000 +0900
+++ tty.js 2015-11-04 17:06:53.000000000 +0900
@@ -302,7 +302,10 @@
Window.prototype.focus = function() {
// Restack
var parent = this.element.parentNode;
- if (parent) {
+ if (parent && this.element != parent.lastChild) {
+ if (Terminal.focus) {
+ Terminal.focus.blur();
+ }
parent.removeChild(this.element);
parent.appendChild(this.element);
}
@@ -637,7 +640,9 @@
Tab.prototype._focus = Tab.prototype.focus;
Tab.prototype.focus = function() {
- if (Terminal.focus === this) return;
+ var prevFocus = Terminal.focus;
+ this._focus();
+ if (prevFocus === this) return;
var win = this.window;
@@ -661,7 +666,7 @@
this.handleTitle(this.title);
- this._focus();
+ // this._focus();
win.focus();
@chjj Is there any chance of taking a look at this PR? I'd really love for #87 to be addressed, and this seems to do it. I can't claim to understand how the CJK support in this PR works, though.
+1
Hi yoshiokatsuneo, Thanks for your contributing. It will be helpful to me. But I encounter bugs when using yoshiokatsuneo/term.js repository.
- The console will become wide after I paste (ctrl + v) a long enough CJK string.
- I keep pressing Backspace to delete CJK string , the first character '$' in the console will be deleted. My OS: Win10 and my browser: Chrome ver 48. Best regards.
@e1ee1e11 I'm sorry but I cannot reproduce the issue. I think it is nice to have a capture image...
I'm read and test his code, it's works for me and the code seems fine.
Typing CJK character's problems have not been fully resolved, when pressing the backspace key, you can not delete characters correctly.

@codehz This can't be happen... Please give a short code to reconstruct it. I am very curious about it
@liuzheng712 你用的是什么版本的term.js,我用的是Rancher的,还有我用的是前面提到的TTY.js修改方式对tty.js打了补丁
Which term.js version are you using? I am using rancher/term.js . And I use the patch by yoshiokatsuneo for tty.js.
@codehz I'm only using yoshiokatsuneo's verstion, if it possible , Please create a git repository. Maybe this bug comes from your back-end code? which technical you use for the back-end? My is tornado .
@liuzheng712 I use tty.js, I will create a repo tomorrow(GMT+8)...
@codehz ok, BTW I'm Chinese~ I know you are Chinese too ... I'm in Shanghai~
@liuzheng712 I have create a repo for this. latest commit is https://github.com/codehz/tty.js/commit/d45942b7c1a348e2dd52439e43e7a818efa42fc4
And I found this problem does not occur when I use bash shell, but other program will.
It seem this problem will occur when program direct read text from stdin.

@codehz
I cloned your code and run it, no bug....
I'm use OS X Yosemite 10.10.5, Chrome 49.0.2623.87 (64-bit)
@liuzheng712 I'm use win 10, Chrome 49, (tty.js run on Linux vm) it may be the reason.
@liuzheng712 Can you try to use some program to get text direct from stdin, I mean do not use readline library, just use scanf function or std::cin. Some shell can handle backspace in their own way. You can just copy that ,compile it, and run it.
#include <iostream>
int main() {
char test[32];
std::cin >> test;
std::cout << test << std::endl;
return 0;
}
I do not believe this issue depends on OS.
@yoshiokatsuneo your cjk branch code works perfect, thanks! :+1: