Skip to content

feat: add pager to allow scrolling of long outputs in the REPL #2162

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

Merged
merged 44 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e4c1a43
feat: add pager to allow scrolling of long outputs
Snehil-Shah Apr 14, 2024
28a9304
refactor: remove setting and default
kgryte Apr 20, 2024
11a3b70
refactor: support programmatic disabling and enabling
kgryte Apr 20, 2024
1fa14b6
fix: add missing types
kgryte Apr 21, 2024
8c588ba
fix: avoid clashing with existing TAB completion behavior
kgryte Apr 21, 2024
fd3e109
refactor: rename parameter and internal variable
kgryte Apr 21, 2024
45e0660
refactor: add methods for programmatically toggling behavior
kgryte Apr 21, 2024
18bedb7
fix: ensure booleans are always returned
kgryte Apr 21, 2024
c672f48
refactor: implement paging as a transform stream
kgryte Apr 21, 2024
262131d
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte Apr 21, 2024
5e02a44
fix: update API calls
kgryte Apr 21, 2024
08f25c7
refactor: close output stream on REPL close and address failing tests
kgryte Apr 21, 2024
a7446a3
refactor: move logic to private methods
kgryte Apr 21, 2024
b059a94
refactor: reintroduce setting
kgryte Apr 21, 2024
919db02
docs: document setting
kgryte Apr 21, 2024
44a8e87
refactor: add `pager` command and fix settings handling
kgryte Apr 21, 2024
c18cd25
fix: update paging check and allow paging bypass
kgryte Apr 21, 2024
4e3f5d9
fix: update conditionals
kgryte Apr 21, 2024
04f6291
refactor: apply De Morgan's law
kgryte Apr 21, 2024
556690e
refactor: batch write the pager content
kgryte Apr 21, 2024
cffb6ce
refactor: replace loops with calls to `substring`
kgryte Apr 21, 2024
530f0f8
refactor: guard against index increment errors
kgryte Apr 21, 2024
da40034
refactor: minimize the number of ops between clearing screen and disp…
kgryte Apr 21, 2024
3915bd8
fix: disable auto-paging during tests
kgryte Apr 21, 2024
ee971ca
refactor: add support for detecting terminal resize events
kgryte Apr 21, 2024
5be95e3
style: use consistent spacing
kgryte Apr 21, 2024
b19355b
fix: directly write msg to output to avoid triggering pager
Snehil-Shah Apr 22, 2024
e4914e6
fix: avoid suppressing SIGINT interrupts
Snehil-Shah Apr 22, 2024
2bea814
fix: avoid paging if viewport height too low
Snehil-Shah Apr 22, 2024
6a422fa
fix: exit pager if viewport is resized to smaller than minimum
Snehil-Shah Apr 22, 2024
4b4430f
docs: add TODO concerning implementation robustness
kgryte Apr 22, 2024
ee0be20
fix: pager not displaying the last line
Snehil-Shah Apr 22, 2024
3ab38a3
test: add tests for pager
Snehil-Shah Apr 22, 2024
7ee0b92
style: change variable case
Snehil-Shah Apr 23, 2024
1acac0c
docs: add comment
kgryte Apr 24, 2024
ebfbe26
docs: update comments
kgryte Apr 24, 2024
978190c
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte Apr 24, 2024
eb9cdff
test: refactor test fixture option handling and update test fixture l…
kgryte Apr 24, 2024
849bb48
style: re-add line to be consistent with other functions
kgryte Apr 24, 2024
683d390
docs: indicate that options are optional
kgryte Apr 25, 2024
95c544f
refactor: avoid repetition
kgryte Apr 25, 2024
78a7e34
style: group operands to visually reinforce operator precedence
kgryte Apr 25, 2024
b69c99a
refactor: simplify height determination
kgryte Apr 25, 2024
6b14914
test: update descriptions
kgryte Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: add support for detecting terminal resize events
  • Loading branch information
kgryte committed Apr 21, 2024
commit ee971cac480e0bbbe5df73f748a283e4509f10a3
13 changes: 13 additions & 0 deletions lib/node_modules/@stdlib/repl/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

var EventEmitter = require( 'events' ).EventEmitter;
var readline = require( 'readline' );
var proc = require( 'process' );
var resolve = require( 'path' ).resolve;
var logger = require( 'debug' );
var inherit = require( '@stdlib/utils/inherit' );
Expand Down Expand Up @@ -279,6 +280,7 @@ function REPL( options ) {
this._rli.on( 'close', onClose );
this._rli.on( 'line', onLine );
this._rli.on( 'SIGINT', onSIGINT );
proc.on( 'SIGWINCH', onSIGWINCH ); // terminal resize

// Add listener for "command" events:
this.on( 'command', onCommand );
Expand Down Expand Up @@ -373,6 +375,17 @@ function REPL( options ) {
self.emit( 'exit' );
}

/**
* Callback invoked upon receiving a "SIGWINCH" event (i.e., a terminal/console resize event).
*
* @private
* @returns {void}
*/
function onSIGWINCH() {
debug( 'Received a SIGWINCH event. Terminal was resized.' );
self._ostream.onResize();
}

/**
* Callback invoked upon receiving a "SIGINT" event (e.g., Ctrl-C).
*
Expand Down
29 changes: 21 additions & 8 deletions lib/node_modules/@stdlib/repl/lib/output_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ function OutputStream( repl, autoPage ) {
this._buffer = '';

// Initialize a buffer for storing line breaks:
this._lines = [];
this._indices = [];

// Initialize a variable for tracking the current scroll position:
Expand Down Expand Up @@ -361,7 +360,7 @@ setNonEnumerableReadOnly( OutputStream.prototype, '_scrollUp', function scrollUp
return;
}
this._idx -= 1;
this._scroll();
this._redraw();
});

/**
Expand All @@ -378,18 +377,18 @@ setNonEnumerableReadOnly( OutputStream.prototype, '_scrollDown', function scroll
return;
}
this._idx += 1;
return this._scroll();
return this._redraw();
});

/**
* Scrolls the current page based on the updated index.
* Redraws the page content.
*
* @private
* @name _scroll
* @name _redraw
* @memberof OutputStream.prototype
* @returns {void}
*/
setNonEnumerableReadOnly( OutputStream.prototype, '_scroll', function scroll() {
setNonEnumerableReadOnly( OutputStream.prototype, '_redraw', function redraw() {
var height;
var width;
var str;
Expand All @@ -405,7 +404,7 @@ setNonEnumerableReadOnly( OutputStream.prototype, '_scroll', function scroll() {

// If we're not showing the first line of content, display a seperator to convey that one can scroll up to see additional content...
str = '';
if ( idx > 0 ) { // FIXME: what happens when a user resizes the terminal window?
if ( idx > 0 ) {
str += '\n' + repeat( '_', width ) + '\n';
} else {
str += '\n\n';
Expand All @@ -414,7 +413,7 @@ setNonEnumerableReadOnly( OutputStream.prototype, '_scroll', function scroll() {
str += this._buffer.substring( this._indices[ idx ], this._indices[ height+idx ] - 1 ) + '\n';

// If we're not showing the last line of content, display a seperator to convey that one can scroll down to see additional content...
if ( height + idx < this._indices.length - 1 ) { // FIXME: what happens when a user resizes the terminal window?
if ( height + idx < this._indices.length - 1 ) {
str += repeat( '_', width ) + '\n';
} else {
str += '\n';
Expand Down Expand Up @@ -497,6 +496,20 @@ setNonEnumerableReadOnly( OutputStream.prototype, 'beforeKeypress', function bef
}
});

/**
* Callback which should be invoked upon a "resize" event.
*
* @name onResize
* @memberof OutputStream.prototype
* @returns {void}
*/
setNonEnumerableReadOnly( OutputStream.prototype, 'onResize', function onResize() {
if ( !this._isPaging ) {
return;
}
this._redraw();
});


// EXPORTS //

Expand Down
5 changes: 4 additions & 1 deletion lib/node_modules/@stdlib/repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"stdlib-repl": "./bin/cli"
},
"main": "./lib",
"browser": "./lib/browser/index.js",
"browser": {
"./lib": "./lib/browser/index.js",
"process": "process/"
},
"directories": {
"benchmark": "./benchmark",
"data": "./data",
Expand Down