1- import { color } from "../color" ;
1+ import { color , stripColors } from "../color" ;
22import {
33 IKeyCommandHelper ,
44 IKeyCommandPlatform ,
5- IValidKeyCommands ,
5+ IValidKeyName ,
6+ SpecialKeys ,
67 SupportedProcessType ,
78} from "../common/definitions/key-commands" ;
89import { injector } from "../common/yok" ;
@@ -13,25 +14,25 @@ export default class KeyCommandHelper implements IKeyCommandHelper {
1314 private processType : SupportedProcessType ;
1415 private overrides : { [ key : string ] : ( ) => Promise < boolean > } = { } ;
1516
16- public addOverride ( key : IValidKeyCommands , execute : ( ) => Promise < boolean > ) {
17+ public addOverride ( key : IValidKeyName , execute : ( ) => Promise < boolean > ) {
1718 this . overrides [ key ] = execute ;
1819 }
1920
20- public removeOverride ( key : IValidKeyCommands ) {
21+ public removeOverride ( key : IValidKeyName ) {
2122 this . overrides [ key ] = undefined ;
2223 }
2324
2425 private onKeyPressed = async ( data : Buffer ) => {
2526 const key = data . toString ( ) ;
2627
2728 // Allow Ctrl + C always.
28- if ( this . keyCommandExecutionBlocked && key !== "\u0003" ) return ;
29+ if ( this . keyCommandExecutionBlocked && key !== SpecialKeys . CtrlC ) return ;
2930
3031 try {
3132 const exists = injector . getRegisteredKeyCommandsNames ( ) . includes ( key ) ;
3233
3334 if ( exists ) {
34- const keyCommand = injector . resolveKeyCommand ( key as IValidKeyCommands ) ;
35+ const keyCommand = injector . resolveKeyCommand ( key as IValidKeyName ) ;
3536
3637 if (
3738 keyCommand . platform === "all" ||
@@ -57,6 +58,16 @@ export default class KeyCommandHelper implements IKeyCommandHelper {
5758 }
5859 }
5960
61+ if ( keyCommand . key !== SpecialKeys . CtrlC ) {
62+ const line = ` ${ color . dim ( "→" ) } ${ color . bold ( keyCommand . key ) } — ${
63+ keyCommand . description
64+ } `;
65+ const lineLength = stripColors ( line ) . length - 1 ;
66+ console . log ( color . dim ( ` ┌${ "─" . repeat ( lineLength ) } ┐` ) ) ;
67+ console . log ( line + color . dim ( " │" ) ) ;
68+ console . log ( color . dim ( ` └${ "─" . repeat ( lineLength ) } ┘` ) ) ;
69+ console . log ( "" ) ;
70+ }
6071 const result = await keyCommand . execute ( this . platform ) ;
6172 this . keyCommandExecutionBlocked = false ;
6273
@@ -78,7 +89,7 @@ export default class KeyCommandHelper implements IKeyCommandHelper {
7889 public printCommands ( platform : IKeyCommandPlatform ) {
7990 const commands = injector . getRegisteredKeyCommandsNames ( ) ;
8091 const commandHelp = commands . reduce ( ( arr , key ) => {
81- const command = injector . resolveKeyCommand ( key as IValidKeyCommands ) ;
92+ const command = injector . resolveKeyCommand ( key as IValidKeyName ) ;
8293
8394 if (
8495 ! command . description ||
@@ -102,6 +113,7 @@ export default class KeyCommandHelper implements IKeyCommandHelper {
102113 ) } , you can press the following keys any time (make sure the terminal has focus).`,
103114 "" ,
104115 ...commandHelp ,
116+ "" ,
105117 ] . join ( "\n" )
106118 ) ;
107119 }
0 commit comments