Skip to content

Commit 8d7f8e2

Browse files
committed
refactor: add specialized handling for displaying ndarrays
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 1ddeba9 commit 8d7f8e2

File tree

1 file changed

+8
-1
lines changed
  • lib/node_modules/@stdlib/repl/lib

1 file changed

+8
-1
lines changed

lib/node_modules/@stdlib/repl/lib/drain.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
var inspect = require( 'util' ).inspect;
2626
var logger = require( 'debug' );
27+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
2728
var replace = require( '@stdlib/string/replace' );
2829
var noop = require( '@stdlib/utils/noop' );
2930
var nextTick = require( '@stdlib/utils/next-tick' );
@@ -53,6 +54,7 @@ function drain( repl ) {
5354
var code;
5455
var res;
5556
var pre;
57+
var tmp;
5658

5759
if ( repl._busy ) {
5860
debug( 'Waiting on a command to finish...' );
@@ -127,7 +129,12 @@ function drain( repl ) {
127129
pre = replace( repl._outputPrompt, '%d', (repl._count+1).toString() );
128130

129131
// 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)
130-
repl._ostream.write( pre+inspect( repl._ans )+'\n' );
132+
if ( isndarrayLike( res ) ) {
133+
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.
134+
} else {
135+
tmp = repl._ans;
136+
}
137+
repl._ostream.write( pre+inspect( tmp )+'\n' );
131138
}
132139
// Finish processing:
133140
return beforeNextTick();

0 commit comments

Comments
 (0)