@@ -32,6 +32,14 @@ let hasRun = false;
3232const pageLoaded = new Promise ( ( resolve ) => onLoad ( resolve ) ) ;
3333const modPromise = import ( minizincUrl ) ;
3434
35+ const getOutput = ( solution : any ) =>
36+ solution ?. output ?. default ??
37+ solution ?. output ?. dzn ??
38+ solution ?. output ?. json ??
39+ solution ?. output ?. raw ??
40+ solution ?. output ??
41+ '' ;
42+
3543const run = ( data : MiniZincData = { } ) => {
3644 if ( ! MiniZinc ) {
3745 throw new Error ( 'MiniZinc is not initialized. await livecodes.minizinc.init() first.' ) ;
@@ -67,12 +75,22 @@ livecodes.minizinc = {
6775 await livecodes . minizinc . init ( ) ;
6876 return new Promise ( ( resolve ) => {
6977 const solve = run ( data ) ;
78+ let lastOutput = '' ;
7079 const errors : any [ ] = [ ] ;
7180 solve . on ( 'error' , ( error : any ) => {
81+ const msg = `MiniZinc: ${ error ?. what ?? 'Error' } : ${ error . message } ` ;
7282 // eslint-disable-next-line no-console
73- console . error ( error ) ;
83+ console . error ( msg ) ;
7484 errors . push ( error ) ;
7585 } ) ;
86+ solve . on ( 'solution' , ( solution : any ) => {
87+ const output = getOutput ( solution ) ;
88+ const line = '----------' ;
89+ const msg = typeof output === 'string' ? output + line : output ;
90+ // eslint-disable-next-line no-console
91+ console . log ( msg ) ;
92+ lastOutput = output ;
93+ } ) ;
7694 solve . on ( 'exit' , ( msg : any ) => {
7795 if ( msg . code === 0 ) return ;
7896 if ( errors . length ) {
@@ -103,13 +121,8 @@ livecodes.minizinc = {
103121 ERROR : '=====ERROR=====' ,
104122 } ;
105123 const status = statusMap [ result . status ] || '' ;
106- const output =
107- result . solution ?. output ?. default ??
108- result . solution ?. output ?. dzn ??
109- result . solution ?. output ?. json ??
110- result . solution ?. output ?. raw ??
111- result . solution ?. output ??
112- '' ;
124+ const resultOutput = getOutput ( result . solution ) ;
125+ const output = lastOutput === resultOutput ? '' : resultOutput ;
113126 const msg = typeof output === 'string' ? output + status : output ;
114127 // eslint-disable-next-line no-console
115128 console . log ( msg ) ;
0 commit comments