1- import generatePrompt from " ./openai.js" ;
1+ import generatePrompt from ' ./openai.js' ;
22import { execa } from 'execa' ;
3- import readline from "readline" ;
3+ import readline from 'readline' ;
4+ import React from 'react' ;
5+ import { Box , render , Text , useApp } from 'ink' ;
6+ import SelectInput from 'ink-select-input' ;
47
58async function askForCommitMessage ( ) {
6- const prompt = await generatePrompt ( ) ;
9+ const prompt = await generatePrompt ( ) ;
710
8- const rl = readline . createInterface ( {
9- input : process . stdin ,
10- output : process . stdout ,
11- } ) ;
11+ const rl = readline . createInterface ( {
12+ input : process . stdin ,
13+ output : process . stdout ,
14+ } ) ;
1215
13- if ( prompt ) {
14- rl . question ( `Suggested commit message: ${ prompt } \nDo you want to proceed? (y/N) ` , ( answer ) => {
15- if ( answer . toLowerCase ( ) === "y" ) {
16- execa ( "git" , [ "commit" , "-m" , prompt ] )
17- . then ( ( ) => {
18- console . log ( "Changes committed successfully!" ) ;
19- } )
20- . catch ( ( error ) => {
21- console . error ( "Failed to commit changes:" , error ) ;
22- } ) ;
23- } else {
24- console . log ( "Changes not committed." ) ;
25- }
16+ const SelectSuggestedCommit = ( ) => {
17+ const { exit} = useApp ( ) ;
18+ const handleSelect = item => {
19+ if ( item . value ) {
20+ execa ( 'git' , [ 'commit' , '-m' , prompt ] )
21+ . then ( ( ) => {
22+ console . log ( 'Changes committed successfully!' ) ;
23+ } )
24+ . catch ( error => {
25+ console . error ( 'Failed to commit changes:' , error ) ;
26+ } ) ;
27+ }
28+ else {
29+ console . log ( 'Changes not committed.' ) ;
30+ }
31+ exit ( ) ;
32+ } ;
2633
27- rl . close ( ) ;
28- } ) ;
29- } else {
30- console . log ( "No changes to commit..." ) ;
31- rl . close ( ) ;
32- }
34+ const items = [
35+ {
36+ label : 'No' ,
37+ value : false ,
38+ } ,
39+ {
40+ label : 'Yes' ,
41+ value : true ,
42+ } ,
43+ ] ;
44+
45+ return (
46+ < Box flexDirection = "column" >
47+ < Text > { `Suggested commit message: ${ prompt } \nDo you want to proceed?` } </ Text >
48+ < SelectInput items = { items } onSelect = { handleSelect } />
49+ </ Box >
50+ ) ;
51+ } ;
52+
53+ if ( prompt ) {
54+ render ( < SelectSuggestedCommit /> ) ;
55+ } else {
56+ console . log ( 'No changes to commit...' ) ;
57+ rl . close ( ) ;
58+ }
3359}
3460
35- export default askForCommitMessage ;
61+ export default askForCommitMessage ;
0 commit comments