File tree Expand file tree Collapse file tree 3 files changed +26
-9
lines changed Expand file tree Collapse file tree 3 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 1+ const { resolve} = require ( 'path' )
2+ const { render} = require ( '../pure' )
3+ const { fireEvent} = require ( "../events" ) ;
4+
5+ test ( 'Should render { and } in user keyboard' , async ( ) => {
6+ const { findByText, userEvent : userEventLocal } = await render ( 'node' , [
7+ resolve ( __dirname , './execute-scripts/stdio-inquirer-input.js' ) ,
8+ ] )
9+
10+ const instance = await findByText ( 'What is your name?' )
11+ expect ( instance ) . toBeTruthy ( )
12+
13+ userEventLocal . keyboard ( '{Hello}' )
14+
15+ expect ( await findByText ( '{Hello}' ) ) . toBeTruthy ( )
16+
17+ await fireEvent . sigterm ( instance )
18+ } )
Original file line number Diff line number Diff line change 11import { keyboardKey , keyboardOptions } from './types'
22
33enum bracketDict {
4- '{' = '}' ,
54 '[' = ']' ,
65}
76
@@ -28,14 +27,11 @@ export function getNextKeyDef(
2827 const keyDef : keyboardKey = options . keyboardMap . find ( def => {
2928 if ( type === '[' ) {
3029 return def . code ?. toLowerCase ( ) === descriptor . toLowerCase ( )
31- } else if ( type === '{' ) {
32- return def . hex ?. toLowerCase ( ) === descriptor . toLowerCase ( )
3330 }
3431 return def . hex === descriptor
3532 } ) ?? {
36- code : 'Unknown' ,
33+ code : descriptor ,
3734 hex : 'Unknown' ,
38- [ type === '[' ? 'code' : 'key' ] : descriptor ,
3935 }
4036
4137 return {
@@ -51,15 +47,14 @@ function readNextDescriptor(text: string) {
5147
5248 pos += startBracket . length
5349
54- // `foo{{ bar` is an escaped char at position 3,
55- // but `foo{{{ >5}bar` should be treated as `{` pressed down for 5 keydowns.
50+ // `foo[[ bar` is an escaped char at position 3,
51+ // but `foo[[[ >5 }bar` should be treated as `{` pressed down for 5 keydowns.
5652 const startBracketRepeated = startBracket
5753 ? ( text . match ( new RegExp ( `^\\${ startBracket } +` ) ) as RegExpMatchArray ) [ 0 ]
5854 . length
5955 : 0
6056 const isEscapedChar =
61- startBracketRepeated === 2 ||
62- ( startBracket === '{' && startBracketRepeated > 3 )
57+ startBracketRepeated === 2
6358
6459 const type = isEscapedChar ? '' : startBracket
6560
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ export const defaultKeyMap: keyboardKey[] = [
2121 { code : 'Digit-' , hex : '\x2d' } ,
2222 { code : 'Digit@' , hex : '\x40' } ,
2323 { code : 'Digit^' , hex : '\x5e' } ,
24+ { code : 'Digit{' , hex : '\x7b' } ,
25+ { code : 'Digit|' , hex : '\x7c' } ,
26+ { code : 'Digit}' , hex : '\x7d' } ,
27+ { code : 'Digit~' , hex : '\x7e' } ,
2428 { code : 'Digit0' , hex : '\x30' } ,
2529 { code : 'Digit1' , hex : '\x31' } ,
2630 { code : 'Digit2' , hex : '\x32' } ,
You can’t perform that action at this time.
0 commit comments