@@ -3,10 +3,9 @@ import path from 'path'
33import { fileURLToPath } from 'url'
44import { exit } from 'process'
55import chalk from 'chalk'
6- import inquirer from 'inquirer'
6+ import { confirm , select } from '@ inquirer/prompts '
77import csv from 'csv-parser'
88import Table from 'cli-table3'
9- import readlineSync from 'readline-sync'
109
1110import singleFeatureProcess from './single-feature.js'
1211import multiFeatureProcess from './multi-feature.js'
@@ -49,24 +48,21 @@ const DATA_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '
4948SIMPLE LINEAR REGRESSION DEMO
5049 ` )
5150
52- const answers = await inquirer . prompt ( [
53- {
54- type : 'list' ,
55- name : 'menu' ,
56- message : 'Choose menu' ,
57- choices : [
58- '1. Guide' ,
59- '2. Run Demo' ,
60- '3. Exit'
61- ]
62- }
63- ] )
51+ const answers = await select ( {
52+ message : 'Choose menu' ,
53+ choices : [
54+ '1. Guide' ,
55+ '2. Run Demo' ,
56+ '3. Exit'
57+ ]
58+ } )
6459
6560 console . clear ( )
66-
67- switch ( answers . menu ) {
61+
62+
63+ switch ( answers ) {
6864 case '1. Guide' :
69- showGuide ( )
65+ await showGuide ( )
7066 break ;
7167 case '2. Run Demo' :
7268 await runDemo ( )
@@ -79,22 +75,22 @@ SIMPLE LINEAR REGRESSION DEMO
7975 print ( 'Invalid input!' )
8076 break ;
8177 }
82- } while ( readlineSync . keyInYNStrict ( chalk . green ( '\nContinue program? ' ) ) )
78+ } while ( await confirm ( { message : '\nContinue program? ' } ) )
8379} ) ( ) ;
8480
8581
8682
8783
8884
8985
90- function showGuide ( ) {
86+ async function showGuide ( ) {
9187 print ( 'This is a guide for this program!' ) ;
9288 for ( let i = 1 ; i <= 5 ; i ++ ) {
9389 print ( 'Data: ' , i )
9490 }
9591
9692
97- if ( ! readlineSync . keyInYNStrict ( chalk . green ( '\nBack' ) ) ) {
93+ if ( ! await confirm ( { message : 'Back?' } ) ) {
9894 exit ( 0 )
9995 }
10096}
@@ -114,24 +110,18 @@ async function runDemo() {
114110 }
115111
116112
117- const answers = await inquirer . prompt ( [
118- {
119- type : 'list' ,
120- name : 'data' ,
121- message : 'Choose data' ,
122- choices : files
123- }
124- ] )
113+ const answers = await select ( {
114+ message : 'Choose data' ,
115+ choices : files
116+ } )
125117
126- if ( readlineSync . keyInYNStrict ( chalk . green ( '\nPreview data' ) ) ) {
127- await previewData ( answers . data )
118+ if ( await confirm ( { message : 'Preview data?' } ) ) {
119+ await previewData ( answers )
128120 }
129121}
130122
131123
132124
133-
134-
135125function readFileAsync ( filePath ) {
136126 return new Promise ( ( resolve , reject ) => {
137127 const data = [ ]
@@ -145,8 +135,6 @@ function readFileAsync(filePath) {
145135
146136
147137
148-
149-
150138async function previewData ( filePath ) {
151139 print ( '\n-----------------------------------------------------\n' )
152140 print ( 'Preview data: ' , filePath )
@@ -163,32 +151,27 @@ async function previewData(filePath) {
163151
164152 print ( table . toString ( ) )
165153
166- if ( readlineSync . keyInYNStrict ( chalk . green ( '\nContinue next process' ) ) ) {
154+ if ( await confirm ( { message : '\nContinue next process' } ) ) {
167155 await dataIdentification ( data )
168156 }
169157}
170158
171159
172160
173-
174161async function dataIdentification ( data ) {
175162 print ( '\n-----------------------------------------------------\n' )
176163 print ( 'Data identification' )
177164
178165
179- const answers = await inquirer . prompt ( [
180- {
181- type : 'list' ,
182- name : 'type' ,
183- message : 'Choose model type' ,
184- choices : [
185- '1. Single feature' ,
186- '2. Multi feature'
187- ]
188- }
189- ] )
190-
191- switch ( answers . type ) {
166+ const answers = await select ( {
167+ message : 'Choose model type' ,
168+ choices : [
169+ '1. Single feature' ,
170+ '2. Multi feature'
171+ ]
172+ } )
173+
174+ switch ( answers ) {
192175 case '1. Single feature' :
193176 await singleFeatureProcess ( data )
194177 break ;
0 commit comments