langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java
changeset 38613 2a8e50869b08
parent 38539 71874886920f
child 38908 f0c186d76c8a
equal deleted inserted replaced
38612:43c4bd1d4cb5 38613:2a8e50869b08
   371      * @param key the resource key
   371      * @param key the resource key
   372      * @param args
   372      * @param args
   373      */
   373      */
   374     @Override
   374     @Override
   375     public void errormsg(String key, Object... args) {
   375     public void errormsg(String key, Object... args) {
   376         cmdout.println(prefix(messageFormat(key, args), feedback.getErrorPre()));
   376         if (isRunningInteractive()) {
       
   377             cmdout.println(prefix(messageFormat(key, args), feedback.getErrorPre()));
       
   378         } else {
       
   379             startmsg(key, args);
       
   380         }
   377     }
   381     }
   378 
   382 
   379     /**
   383     /**
   380      * Print command-line error using resource bundle look-up, MessageFormat
   384      * Print command-line error using resource bundle look-up, MessageFormat
   381      *
   385      *
   556                     case "-v":
   560                     case "-v":
   557                         commandLineFeedbackMode = "verbose";
   561                         commandLineFeedbackMode = "verbose";
   558                         break;
   562                         break;
   559                     case "-startup":
   563                     case "-startup":
   560                         if (startup != null) {
   564                         if (startup != null) {
   561                             startmsg("jshell.err.opt.startup.conflict");
   565                             startmsg("jshell.err.opt.startup.one");
   562                             return null;
   566                             return null;
   563                         }
   567                         }
   564                         startup = readFile(ai.hasNext()? ai.next() : null, "'-startup'");
   568                         startup = readFile(ai.hasNext()? ai.next() : null, "-startup");
   565                         if (startup == null) {
   569                         if (startup == null) {
   566                             return null;
   570                             return null;
   567                         }
   571                         }
   568                         break;
   572                         break;
   569                     case "-nostartup":
   573                     case "-nostartup":
   570                         if (startup != null && !startup.isEmpty()) {
   574                         if (startup != null) {
   571                             startmsg("jshell.err.opt.startup.conflict");
   575                             startmsg("jshell.err.opt.startup.one");
   572                             return null;
   576                             return null;
   573                         }
   577                         }
   574                         startup = "";
   578                         startup = "";
   575                         break;
   579                         break;
   576                     default:
   580                     default:
   658 
   662 
   659         startUpRun(startup);
   663         startUpRun(startup);
   660         currentNameSpace = mainNamespace;
   664         currentNameSpace = mainNamespace;
   661     }
   665     }
   662 
   666 
       
   667     private boolean isRunningInteractive() {
       
   668         return currentNameSpace != null && currentNameSpace == mainNamespace;
       
   669     }
       
   670 
   663     //where -- one-time per run initialization of feedback modes
   671     //where -- one-time per run initialization of feedback modes
   664     private void initFeedback() {
   672     private void initFeedback() {
   665         // No fluff, no prefix, for init failures
   673         // No fluff, no prefix, for init failures
   666         MessageHandler initmh = new InitMessageHandler();
   674         MessageHandler initmh = new InitMessageHandler();
   667         // Execute the feedback initialization code in the resource file
   675         // Execute the feedback initialization code in the resource file
   720         input = in;
   728         input = in;
   721         try {
   729         try {
   722             String incomplete = "";
   730             String incomplete = "";
   723             while (live) {
   731             while (live) {
   724                 String prompt;
   732                 String prompt;
   725                 if (currentNameSpace == mainNamespace) {
   733                 if (isRunningInteractive()) {
   726                     prompt = testPrompt
   734                     prompt = testPrompt
   727                                     ? incomplete.isEmpty()
   735                                     ? incomplete.isEmpty()
   728                                             ? "\u0005" //ENQ
   736                                             ? "\u0005" //ENQ
   729                                             : "\u0006" //ACK
   737                                             : "\u0006" //ACK
   730                                     : incomplete.isEmpty()
   738                                     : incomplete.isEmpty()
   768             input = oldInput;
   776             input = oldInput;
   769         }
   777         }
   770     }
   778     }
   771 
   779 
   772     private void addToReplayHistory(String s) {
   780     private void addToReplayHistory(String s) {
   773         if (currentNameSpace == mainNamespace) {
   781         if (isRunningInteractive()) {
   774             replayableHistory.add(s);
   782             replayableHistory.add(s);
   775         }
   783         }
   776     }
   784     }
   777 
   785 
   778     private String processSourceCatchingReset(String src) {
   786     private String processSourceCatchingReset(String src) {