Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unicode support for terminal #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion notebook_xterm/terminalclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ var MIN_POLL_INTERVAL = 100;
var BACKOFF_RATE = 1.8;
var PY_XTERM_INSTANCE = 'get_ipython().find_magic("xterm").__self__';
var PY_TERMINAL_SERVER = PY_XTERM_INSTANCE + '.getTerminalServer()';

function b64DecodeUnicode(str) {
// From https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
// Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}

function TerminalClient(elem) {
this.closed = false;
// require xterm.js
Expand Down Expand Up @@ -120,7 +129,7 @@ TerminalClient.prototype.receive_data_callback = function(data) {
}

try {
var decoded = atob(data.content.text);
var decoded = b64DecodeUnicode(data.content.text);
this.term.write(decoded);
}
catch(e) {
Expand Down