Skip to content

Commit

Permalink
add terminal::lines() #966
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Nov 21, 2024
1 parent 6d58346 commit dd33bb8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* add `id` option that allow to create same terminal using hot reload [#978](https://github.com/jcubic/jquery.terminal/issues/978)
* allow using Object URLs in links [#982](https://github.com/jcubic/jquery.terminal/issues/982)
* experimental `--cols` CSS variable [#956](https://github.com/jcubic/jquery.terminal/issues/956)
* add `terminal::lines()` [#966](https://github.com/jcubic/jquery.terminal/issues/966)
### Bugfix
* fix `terminal::login()` when user already authenticated [#980](https://github.com/jcubic/jquery.terminal/issues/980)
* improve mobile support
Expand Down
13 changes: 11 additions & 2 deletions js/jquery.terminal-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -8567,14 +8567,14 @@
// :: Function limit output lines based on outputLimit option
// ---------------------------------------------------------------------
function limit_lines() {
var $lines = output.find('> div > div');
if (settings.outputLimit >= 0) {
var limit;
if (settings.outputLimit === 0) {
limit = self.rows();
} else {
limit = settings.outputLimit;
}
var $lines = output.find('> div > div');
if ($lines.length + 1 > limit) {
var max = $lines.length - limit + 1;
var for_remove = $lines.slice(0, max);
Expand All @@ -8592,8 +8592,10 @@
}
});
lines.limit_snapshot(max);
return max;
}
}
return $lines.length;
}
// ---------------------------------------------------------------------
// :: Display user greetings or terminal signature
Expand Down Expand Up @@ -10540,6 +10542,12 @@
return '';
},
// -------------------------------------------------------------
// :: returns the number of rendered lines
// -------------------------------------------------------------
lines: function() {
return output_line_count;
},
// -------------------------------------------------------------
// :: Return the version number
// -------------------------------------------------------------
version: function() {
Expand Down Expand Up @@ -10884,7 +10892,7 @@
});
command_line.__set_prompt_margin(len);
}
limit_lines();
output_line_count = limit_lines();
fire_event('onFlush');
self.stopTime('flush').oneTime(10, 'flush', function() {
var cmd_cursor = self.find('.cmd-cursor');
Expand Down Expand Up @@ -11971,6 +11979,7 @@
var terminal_id = have_custom_id ? options.id : terminals.length();
var force_awake = false; // flag used to don't pause when user return read() call
var num_chars; // numer of chars in line
var output_line_count = 0;
var num_rows; // number of lines that fit without scrollbar
var command; // for tab completion
var logins = new Stack(); // stack of logins
Expand Down
17 changes: 13 additions & 4 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: Mon, 18 Nov 2024 23:03:37 +0000
* Date: Thu, 21 Nov 2024 14:01:23 +0000
*/
/* global define, Map, BigInt */
/* eslint-disable */
Expand Down Expand Up @@ -5345,7 +5345,7 @@
// -------------------------------------------------------------------------
$.terminal = {
version: 'DEV',
date: 'Mon, 18 Nov 2024 23:03:37 +0000',
date: 'Thu, 21 Nov 2024 14:01:23 +0000',
// colors from https://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -8567,14 +8567,14 @@
// :: Function limit output lines based on outputLimit option
// ---------------------------------------------------------------------
function limit_lines() {
var $lines = output.find('> div > div');
if (settings.outputLimit >= 0) {
var limit;
if (settings.outputLimit === 0) {
limit = self.rows();
} else {
limit = settings.outputLimit;
}
var $lines = output.find('> div > div');
if ($lines.length + 1 > limit) {
var max = $lines.length - limit + 1;
var for_remove = $lines.slice(0, max);
Expand All @@ -8592,8 +8592,10 @@
}
});
lines.limit_snapshot(max);
return max;
}
}
return $lines.length;
}
// ---------------------------------------------------------------------
// :: Display user greetings or terminal signature
Expand Down Expand Up @@ -10540,6 +10542,12 @@
return '';
},
// -------------------------------------------------------------
// :: returns the number of rendered lines
// -------------------------------------------------------------
lines: function() {
return output_line_count;
},
// -------------------------------------------------------------
// :: Return the version number
// -------------------------------------------------------------
version: function() {
Expand Down Expand Up @@ -10884,7 +10892,7 @@
});
command_line.__set_prompt_margin(len);
}
limit_lines();
output_line_count = limit_lines();
fire_event('onFlush');
self.stopTime('flush').oneTime(10, 'flush', function() {
var cmd_cursor = self.find('.cmd-cursor');
Expand Down Expand Up @@ -11971,6 +11979,7 @@
var terminal_id = have_custom_id ? options.id : terminals.length();
var force_awake = false; // flag used to don't pause when user return read() call
var num_chars; // numer of chars in line
var output_line_count = 0;
var num_rows; // number of lines that fit without scrollbar
var command; // for tab completion
var logins = new Stack(); // stack of logins
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 dd33bb8

Please sign in to comment.