Skip to content

Commit

Permalink
add --char-width and --char-height CSS variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Nov 18, 2024
1 parent 473e835 commit 6d58346
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
8 changes: 7 additions & 1 deletion css/jquery.terminal-src.css
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ terminal .terminal-output > div {
height: calc((var(--terminal-line) * var(--rows)) + (var(--padding, 10) * 2px));
/*
* there is a bug in Chromium https://issues.chromium.org/issues/379430924
* it give wrong number of characters per line (off by one), it works fine in Firefox and Epiphany
* it give wrong number of characters per line (off by one),
* it works fine in Firefox and Epiphany
*/
width: calc((var(--cols) * 1ch) + (var(--padding, 10) * 2px) + (var(--terminal-scrollbar, 10) * 1px));
}
Expand Down Expand Up @@ -989,6 +990,11 @@ terminal .terminal-output > div {
inherits: true;
initial-value: auto;
}
@property --cols {
syntax: '<number> | auto';
inherits: true;
initial-value: auto;
}
@supports (-ms-ime-align:auto) {
.terminal h1::selection,
.terminal h2::selection,
Expand Down
10 changes: 8 additions & 2 deletions css/jquery.terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2011-2024 Jakub T. Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
*
* Date: Sun, 17 Nov 2024 13:13:41 +0000
* Date: Mon, 18 Nov 2024 23:03:38 +0000
*/
.terminal .terminal-output .format, .cmd .format,
.cmd-prompt, .cmd-prompt div {
Expand Down Expand Up @@ -845,7 +845,8 @@ terminal .terminal-output > div {
height: calc((var(--terminal-line) * var(--rows)) + (var(--padding, 10) * 2px));
/*
* there is a bug in Chromium https://issues.chromium.org/issues/379430924
* it give wrong number of characters per line (off by one), it works fine in Firefox and Epiphany
* it give wrong number of characters per line (off by one),
* it works fine in Firefox and Epiphany
*/
width: calc((var(--cols) * 1ch) + (var(--padding, 10) * 2px) + (var(--terminal-scrollbar, 10) * 1px));
}
Expand Down Expand Up @@ -989,6 +990,11 @@ terminal .terminal-output > div {
inherits: true;
initial-value: auto;
}
@property --cols {
syntax: '<number> | auto';
inherits: true;
initial-value: auto;
}
@supports (-ms-ime-align:auto) {
.terminal h1::selection,
.terminal h2::selection,
Expand Down
4 changes: 2 additions & 2 deletions css/jquery.terminal.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/jquery.terminal.min.css.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -12057,6 +12057,8 @@
var pixel_density = get_pixel_size();
var char_size = get_char_size(self);
css(self[0], {
'--char-width': char_size.width,
'--char-height': char_size.height,
'--terminal-scrollbar': get_scrollbar_width()
});
// this is needed when terminal have selector with --size that is not
Expand Down Expand Up @@ -12580,9 +12582,18 @@
});
function calculate_char_size() {
var width = char_size.width;
var height = char_size.height;
char_size = get_char_size(self);
var css_vars = {};
if (width !== char_size.width) {
command_line.option('charWidth', char_size.width).refresh();
css_vars['--char-width'] = char_size.width;
}
if (height !== char_size.height) {
css_vars['--char-height'] = char_size.height;
}
if (Object.keys(css_vars).length) {
css(self[0], css_vars);
}
}
resize();
Expand Down
15 changes: 13 additions & 2 deletions js/jquery.terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* broken image by Sophia Bai from the Noun Project (CC-BY)
*
* Date: Sun, 17 Nov 2024 13:32:31 +0000
* Date: Mon, 18 Nov 2024 23:03:37 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -5345,7 +5345,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Sun, 17 Nov 2024 13:32:31 +0000',
date: 'Mon, 18 Nov 2024 23:03:37 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -12057,6 +12057,8 @@
var pixel_density = get_pixel_size();
var char_size = get_char_size(self);
css(self[0], {
'--char-width': char_size.width,
'--char-height': char_size.height,
'--terminal-scrollbar': get_scrollbar_width()
});
// this is needed when terminal have selector with --size that is not
Expand Down Expand Up @@ -12580,9 +12582,18 @@
});
function calculate_char_size() {
var width = char_size.width;
var height = char_size.height;
char_size = get_char_size(self);
var css_vars = {};
if (width !== char_size.width) {
command_line.option('charWidth', char_size.width).refresh();
css_vars['--char-width'] = char_size.width;
}
if (height !== char_size.height) {
css_vars['--char-height'] = char_size.height;
}
if (Object.keys(css_vars).length) {
css(self[0], css_vars);
}
}
resize();
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jquery.terminal.min.js.map

Large diffs are not rendered by default.

0 comments on commit 6d58346

Please sign in to comment.