From ae29319a29df330392abe51f20881f790b24a814 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 31 Dec 2024 07:08:48 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 3 ++- lib/drain.js | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dd2985b..b45a0af5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-12-30) +## Unreleased (2024-12-31)
@@ -180,6 +180,7 @@ A total of 4 people contributed to this release. Thank you to the following cont
+- [`8d7f8e2`](https://github.com/stdlib-js/stdlib/commit/8d7f8e26975ffa5ca2ff11a24eac5f3bba589104) - **refactor:** add specialized handling for displaying ndarrays _(by Athan Reines)_ - [`109c303`](https://github.com/stdlib-js/stdlib/commit/109c3034461f70d36339206cf05237230aba0902) - **docs:** update REPL namespace documentation [(#4364)](https://github.com/stdlib-js/stdlib/pull/4364) _(by stdlib-bot)_ - [`7d8aba0`](https://github.com/stdlib-js/stdlib/commit/7d8aba04d7513814f09d725b81c0f953ad4c3b7f) - **feat:** add ndarray APIs and float32 constants to namespace _(by Athan Reines)_ - [`800e80b`](https://github.com/stdlib-js/stdlib/commit/800e80b8550012d379d57c8ac7e14909a96cbc60) - **docs:** update REPL namespace documentation [(#4336)](https://github.com/stdlib-js/stdlib/pull/4336) _(by stdlib-bot, Philipp Burckhardt)_ diff --git a/lib/drain.js b/lib/drain.js index ea74100a..84187842 100644 --- a/lib/drain.js +++ b/lib/drain.js @@ -24,6 +24,7 @@ var inspect = require( 'util' ).inspect; var logger = require( 'debug' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var replace = require( '@stdlib/string/replace' ); var noop = require( '@stdlib/utils/noop' ); var nextTick = require( '@stdlib/utils/next-tick' ); @@ -53,6 +54,7 @@ function drain( repl ) { var code; var res; var pre; + var tmp; if ( repl._busy ) { debug( 'Waiting on a command to finish...' ); @@ -127,7 +129,12 @@ function drain( repl ) { pre = replace( repl._outputPrompt, '%d', (repl._count+1).toString() ); // TODO: pretty printing (can defer to `util.inspect` for now, but will invariably want more control over this later, possibly including default configuration, etc, either at startup, during runtime, or according to an external configuration file) - repl._ostream.write( pre+inspect( repl._ans )+'\n' ); + if ( isndarrayLike( res ) ) { + tmp = res.toString(); // FIXME: this is a hack in order to avoid printing private ndarray properties in the REPL, as done by the built-in `util.inspect`. Ideally, we'd roll our own inspector which specifically accommodates stdlib's ndarray and other specialized classes. + } else { + tmp = repl._ans; + } + repl._ostream.write( pre+inspect( tmp )+'\n' ); } // Finish processing: return beforeNextTick();