Skip to content

Commit fe08ab7

Browse files
committed
Auto-generated commit
1 parent 5e82ba3 commit fe08ab7

15 files changed

+964
-496
lines changed

.editorconfig

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ indent_style = tab
8686
[*.{f,f.txt}]
8787
indent_style = space
8888
indent_size = 2
89-
insert_final_newline = false
9089

9190
# Set properties for shell files:
9291
[*.{sh,sh.txt}]

CHANGELOG.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-01-15)
7+
## Unreleased (2025-01-17)
88

99
<section class="packages">
1010

@@ -20,6 +20,7 @@
2020

2121
##### Features
2222

23+
- [`6f85e44`](https://github.com/stdlib-js/stdlib/commit/6f85e44e067eb8dd189d6a80b11a4538d29f1f80) - **repl:** add settings and prototype methods for keybindings [(#3331)](https://github.com/stdlib-js/stdlib/pull/3331)
2324
- [`6f2d513`](https://github.com/stdlib-js/stdlib/commit/6f2d513c914a3b92bb202cd0e9527b8b734da65d) - add `ndarray2json` to namespace
2425
- [`917119f`](https://github.com/stdlib-js/stdlib/commit/917119ffdb42b1c15214e4accaa928b279bcd17b) - add support for custom keybindings and editor actions in the REPL [(#2739)](https://github.com/stdlib-js/stdlib/pull/2739)
2526

@@ -37,6 +38,18 @@
3738

3839
<!-- /.bug-fixes -->
3940

41+
<section class="issues">
42+
43+
##### Closed Issues
44+
45+
This release closes the following issue:
46+
47+
[#2647](https://github.com/stdlib-js/stdlib/issues/2647)
48+
49+
</section>
50+
51+
<!-- /.issues -->
52+
4053
</details>
4154

4255
</section>
@@ -169,6 +182,18 @@
169182

170183
<!-- /.packages -->
171184

185+
<section class="issues">
186+
187+
### Closed Issues
188+
189+
This release closes the following issue:
190+
191+
[#2647](https://github.com/stdlib-js/stdlib/issues/2647)
192+
193+
</section>
194+
195+
<!-- /.issues -->
196+
172197
<section class="contributors">
173198

174199
### Contributors
@@ -190,6 +215,7 @@ A total of 4 people contributed to this release. Thank you to the following cont
190215

191216
<details>
192217

218+
- [`6f85e44`](https://github.com/stdlib-js/stdlib/commit/6f85e44e067eb8dd189d6a80b11a4538d29f1f80) - **feat(repl):** add settings and prototype methods for keybindings [(#3331)](https://github.com/stdlib-js/stdlib/pull/3331) _(by Snehil Shah, Athan Reines)_
193219
- [`cd9bb62`](https://github.com/stdlib-js/stdlib/commit/cd9bb624de41013a92fa3d2c8c64e7672d4f73a2) - **docs:** update REPL namespace documentation [(#4759)](https://github.com/stdlib-js/stdlib/pull/4759) _(by stdlib-bot, Philipp Burckhardt)_
194220
- [`7f87119`](https://github.com/stdlib-js/stdlib/commit/7f8711919a1a9c6d8ff2f6ee2565c00f695cd6e3) - **docs:** update REPL namespace documentation [(#4741)](https://github.com/stdlib-js/stdlib/pull/4741) _(by stdlib-bot)_
195221
- [`bf19438`](https://github.com/stdlib-js/stdlib/commit/bf19438f835667994827111c4df472b4b091bb0a) - **docs:** update REPL namespace documentation [(#4707)](https://github.com/stdlib-js/stdlib/pull/4707) _(by stdlib-bot, Philipp Burckhardt)_

lib/actions.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* List of REPL actions.
25+
*
26+
* @private
27+
* @name ACTIONS
28+
* @type {Object}
29+
*/
30+
var ACTIONS = [
31+
'moveRight',
32+
'moveLeft',
33+
'moveWordRight',
34+
'moveWordLeft',
35+
'moveBeginning',
36+
'moveEnd',
37+
'tab',
38+
'indentLineRight',
39+
'indentLineLeft',
40+
'deleteLeft',
41+
'deleteRight',
42+
'deleteWordLeft',
43+
'deleteWordRight',
44+
'deleteLineLeft',
45+
'deleteLineRight',
46+
'yankKilled',
47+
'yankPop',
48+
'undo',
49+
'redo',
50+
'transposeAboutCursor',
51+
'uppercaseNextWord',
52+
'capitalizeNextWord',
53+
'lowercaseNextWord',
54+
'clearScreen'
55+
];
56+
57+
58+
// EXPORTS //
59+
60+
module.exports = ACTIONS;

lib/commands.js

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var onHelp = require( './commands/help.js' );
4848
var onInfo = require( './commands/info.js' );
4949
var isWorkspace = require( './commands/is_workspace.js' );
5050
var isKeyword = require( './commands/is_keyword.js' );
51+
var onKeybindings = require( './commands/keybindings.js' );
5152
var onLicense = require( './commands/license_text.js' );
5253
var onLoad = require( './commands/load.js' );
5354
var onLoadWorkspace = require( './commands/load_workspace.js' );
@@ -60,6 +61,7 @@ var onRenameWorkspace = require( './commands/rename_workspace.js' );
6061
var onRerequire = require( './commands/rerequire.js' );
6162
var onRerun = require( './commands/rerun.js' );
6263
var onReset = require( './commands/reset.js' );
64+
var onSetKeybinding = require( './commands/set_keybinding.js' );
6365
var onSettings = require( './commands/settings.js' );
6466
var onThemes = require( './commands/themes.js' );
6567
var onTutorial = require( './commands/tutorial.js' );
@@ -122,6 +124,7 @@ function commands( repl ) {
122124
cmds.push( [ 'info', onInfo( repl, cmds ), false ] );
123125
cmds.push( [ 'isKeyword', isKeyword( repl ), false ] );
124126
cmds.push( [ 'isWorkspace', isWorkspace( repl ), false ] );
127+
cmds.push( [ 'keybindings', onKeybindings( repl ), false ] );
125128
cmds.push( [ 'license', onLicense( repl ), false ] );
126129
cmds.push( [ 'load', onLoad( repl ), false ] );
127130
cmds.push( [ 'loadWorkspace', onLoadWorkspace( repl ), false ] );
@@ -134,6 +137,7 @@ function commands( repl ) {
134137
cmds.push( [ 'rerequire', onRerequire( repl ), false ] );
135138
cmds.push( [ 'rerun', onRerun( repl ), false ] );
136139
cmds.push( [ 'reset', onReset( repl ), false ] );
140+
cmds.push( [ 'setKeybinding', onSetKeybinding( repl ), false ] );
137141
cmds.push( [ 'settings', onSettings( repl ), false ] );
138142
cmds.push( [ 'themes', onThemes( repl ), false ] );
139143
cmds.push( [ 'tutorial', onTutorial( repl ), false ] );

lib/commands/keybindings.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-underscore-dangle */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var format = require( '@stdlib/string/format' );
26+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
27+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var ACTIONS = require( './../actions.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var isAction = contains( ACTIONS );
34+
35+
36+
// MAIN //
37+
38+
/**
39+
* Returns a callback to be invoked upon calling the `keybindings` command.
40+
*
41+
* @private
42+
* @param {REPL} repl - REPL instance
43+
* @returns {Function} callback
44+
*/
45+
function command( repl ) {
46+
return onCommand;
47+
48+
/**
49+
* Returns all (or select) keybindings.
50+
*
51+
* @private
52+
* @param {string} [action] - action name
53+
* @returns {(Object|Array<Object>)} keybindings object or a list of keybindings
54+
*/
55+
function onCommand() {
56+
var action;
57+
var nargs;
58+
59+
nargs = arguments.length;
60+
if ( nargs === 0 ) {
61+
return repl.keybindings();
62+
}
63+
if ( nargs === 1 ) {
64+
action = arguments[ 0 ];
65+
if ( !isString( action ) ) {
66+
repl._ostream.write( format( 'Error: invalid argument. First argument must be a string. Value: `%s`.', action ) );
67+
return;
68+
}
69+
if ( !isAction( action ) ) {
70+
repl._ostream.write( format( 'Error: invalid argument. First argument must be a valid action name. Value: `%s`.', action ) );
71+
return;
72+
}
73+
return repl.keybindings()[ action ];
74+
}
75+
}
76+
}
77+
78+
79+
// EXPORTS //
80+
81+
module.exports = command;

lib/commands/set_keybinding.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable no-underscore-dangle */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var format = require( '@stdlib/string/format' );
26+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
27+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var ACTIONS = require( './../actions.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var isAction = contains( ACTIONS );
34+
35+
36+
// MAIN //
37+
38+
/**
39+
* Returns a callback to be invoked upon calling the `setKeybinding` command.
40+
*
41+
* @private
42+
* @param {REPL} repl - REPL instance
43+
* @returns {Function} callback
44+
*/
45+
function command( repl ) {
46+
return onCommand;
47+
48+
/**
49+
* Sets a keybinding.
50+
*
51+
* @private
52+
* @param {string} action - action name
53+
* @param {Array<Object>} [keys] - list of keys
54+
* @returns {void}
55+
*/
56+
function onCommand() {
57+
var action;
58+
var nargs;
59+
var keys;
60+
61+
nargs = arguments.length;
62+
if ( nargs === 0 ) {
63+
repl._ostream.write( 'Error: invalid argument. First argument must be an action name.\n' );
64+
return;
65+
}
66+
action = arguments[ 0 ];
67+
if ( nargs === 1 ) {
68+
if ( !isString( action ) ) {
69+
repl._ostream.write( format( 'Error: invalid argument. First argument must be a string. Value: `%s`.\n', action ) );
70+
return;
71+
}
72+
if ( !isAction( action ) ) {
73+
repl._ostream.write( format( 'Error: invalid argument. First argument must be a valid action name. Value: `%s`.\n', action ) );
74+
return;
75+
}
76+
repl._ostream.write( 'Listening for keypresses...' );
77+
repl._isCapturingKeybinding = true;
78+
repl._targetAction = action;
79+
return;
80+
}
81+
keys = arguments[ 1 ];
82+
try {
83+
repl.setKeybinding( action, keys );
84+
repl._ostream.write( format( '\nSuccessfully set keybindings for action `%s`.\n', action ) );
85+
} catch ( err ) {
86+
repl._ostream.write( format( 'Error: %s\n', err.message ) );
87+
}
88+
}
89+
}
90+
91+
92+
// EXPORTS //
93+
94+
module.exports = command;

0 commit comments

Comments
 (0)