mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-05-26 07:08:08 +00:00
Add a --force-unicode-width option to constrain all characters to the monospaced font char width. Fix #77. Thanks @prinzdezibel
This commit is contained in:
@@ -43,6 +43,10 @@ tornado.options.define("unsecure", default=False,
|
||||
tornado.options.define("allow_html_escapes", default=False,
|
||||
help="Allow use of HTML escapes. "
|
||||
"Really unsafe as it is now.")
|
||||
tornado.options.define("force_unicode_width",
|
||||
default=False,
|
||||
help="Force all unicode characters to the same width."
|
||||
"Useful for avoiding layout mess.")
|
||||
tornado.options.define("login", default=True,
|
||||
help="Use login screen at start")
|
||||
tornado.options.define("ssl_version", default=None,
|
||||
|
||||
2
butterfly/static/ext.min.js
vendored
2
butterfly/static/ext.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -149,6 +149,7 @@
|
||||
this.document = this.parent.ownerDocument;
|
||||
this.body = this.document.getElementsByTagName('body')[0];
|
||||
this.html_escapes_enabled = this.body.getAttribute('data-allow-html') === 'yes';
|
||||
this.force_width = this.body.getAttribute('data-force-unicode-width') === 'yes';
|
||||
this.element = this.document.createElement('div');
|
||||
this.element.className = 'terminal focus';
|
||||
this.element.style.outline = 'none';
|
||||
@@ -474,7 +475,7 @@
|
||||
};
|
||||
|
||||
Terminal.prototype.refresh = function(force) {
|
||||
var attr, ch, classes, cursor, data, dirty, fg, group, i, j, k, len, len1, len2, len3, line, lines, m, new_out, o, out, q, ref, ref1, ref2, ref3, ref4, ref5, styles, u, x;
|
||||
var attr, ch, classes, cursor, data, dirty, fg, group, i, j, k, len, len1, len2, len3, line, lines, m, new_out, o, out, q, ref, ref1, ref2, ref3, ref4, ref5, skipnext, styles, u, x;
|
||||
if (force == null) {
|
||||
force = false;
|
||||
}
|
||||
@@ -497,12 +498,17 @@
|
||||
x = -Infinity;
|
||||
}
|
||||
attr = this.cloneAttr(this.defAttr);
|
||||
skipnext = false;
|
||||
for (i = o = 0, ref3 = this.cols - 1; 0 <= ref3 ? o <= ref3 : o >= ref3; i = 0 <= ref3 ? ++o : --o) {
|
||||
data = line[i];
|
||||
if (data.html) {
|
||||
out += data.html;
|
||||
continue;
|
||||
}
|
||||
if (skipnext) {
|
||||
skipnext = false;
|
||||
continue;
|
||||
}
|
||||
ch = data.ch;
|
||||
if (!this.equalAttr(data, attr)) {
|
||||
if (!this.equalAttr(attr, this.defAttr)) {
|
||||
@@ -573,11 +579,13 @@
|
||||
out += '<span class="nbsp">\u2007</span>';
|
||||
} else if (ch <= " ") {
|
||||
out += " ";
|
||||
} else {
|
||||
if (("\uff00" < ch && ch < "\uffef")) {
|
||||
i++;
|
||||
}
|
||||
} else if (!this.force_width || ch <= "~") {
|
||||
out += ch;
|
||||
} else if (("\uff00" < ch && ch < "\uffef")) {
|
||||
skipnext = true;
|
||||
out += "<span style=\"display: inline-block; width: " + (2 * this.char_size.width) + "px\">" + ch + "</span>";
|
||||
} else {
|
||||
out += "<span style=\"display: inline-block; width: " + this.char_size.width + "px\">" + ch + "</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -769,7 +777,7 @@
|
||||
this.screen[this.y + this.shift][0][this.x] = this.cloneAttr(this.curAttr, ch);
|
||||
this.screen[this.y + this.shift][1] = true;
|
||||
this.x++;
|
||||
if (("\uff00" < ch && ch < "\uffef")) {
|
||||
if (this.force_width && ("\uff00" < ch && ch < "\uffef")) {
|
||||
if (this.cols < 2 || this.x >= this.cols) {
|
||||
this.screen[this.y + this.shift][0][this.x - 1] = this.cloneAttr(this.curAttr, " ");
|
||||
this.screen[this.y + this.shift][1] = true;
|
||||
|
||||
6
butterfly/static/main.min.js
vendored
6
butterfly/static/main.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -14,7 +14,8 @@
|
||||
</head>
|
||||
|
||||
<body spellcheck="false"
|
||||
data-allow-html="{{ 'yes' if options.allow_html_escapes else 'no' }}">
|
||||
data-allow-html="{{ 'yes' if options.allow_html_escapes else 'no' }}"
|
||||
data-force-unicode-width="{{ 'yes' if options.force_unicode_width else 'no' }}">
|
||||
<script src="{{ static_url('main.%sjs' % (
|
||||
'' if options.unminified else 'min.')) }}"></script>
|
||||
<script src="{{ static_url('ext.%sjs' % (
|
||||
|
||||
@@ -52,6 +52,8 @@ class Terminal
|
||||
@document = @parent.ownerDocument
|
||||
@body = @document.getElementsByTagName('body')[0]
|
||||
@html_escapes_enabled = @body.getAttribute('data-allow-html') is 'yes'
|
||||
@force_width = @body.getAttribute(
|
||||
'data-force-unicode-width') is 'yes'
|
||||
|
||||
# Main terminal element
|
||||
@element = @document.createElement('div')
|
||||
@@ -390,11 +392,15 @@ class Terminal
|
||||
x = -Infinity
|
||||
|
||||
attr = @cloneAttr @defAttr
|
||||
skipnext = false
|
||||
for i in [0..@cols - 1]
|
||||
data = line[i]
|
||||
if data.html
|
||||
out += data.html
|
||||
continue
|
||||
if skipnext
|
||||
skipnext = false
|
||||
continue
|
||||
|
||||
ch = data.ch
|
||||
unless @equalAttr data, attr
|
||||
@@ -457,9 +463,16 @@ class Terminal
|
||||
out += '<span class="nbsp">\u2007</span>'
|
||||
else if ch <= " "
|
||||
out += " "
|
||||
else
|
||||
i++ if "\uff00" < ch < "\uffef"
|
||||
else if not @force_width or ch <= "~" # Ascii chars
|
||||
out += ch
|
||||
else if "\uff00" < ch < "\uffef"
|
||||
skipnext = true
|
||||
out += "<span style=\"display: inline-block;
|
||||
width: #{2 * @char_size.width}px\">#{ch}</span>"
|
||||
else
|
||||
out += "<span style=\"display: inline-block;
|
||||
width: #{@char_size.width}px\">#{ch}</span>"
|
||||
|
||||
out += "</span>" if i is x
|
||||
attr = data
|
||||
out += "</span>" unless @equalAttr attr, @defAttr
|
||||
@@ -613,7 +626,7 @@ class Terminal
|
||||
@screen[@y + @shift][0][@x] = @cloneAttr @curAttr, ch
|
||||
@screen[@y + @shift][1] = true
|
||||
@x++
|
||||
if "\uff00" < ch < "\uffef"
|
||||
if @force_width and "\uff00" < ch < "\uffef"
|
||||
if @cols < 2 or @x >= @cols
|
||||
@screen[@y + @shift][0][@x - 1] = @cloneAttr @curAttr, " "
|
||||
@screen[@y + @shift][1] = true
|
||||
|
||||
Reference in New Issue
Block a user