public String getInputNomask(String prompt, boolean isNotInputMask)
      throws IOException, UserInterruption {
    String userInput = "";

    String breakConnectPrompt = EXIT_PROD_STR;
    if (isNotInputMask) breakConnectPrompt = "Command Interrupted - Please hit <Enter> ... ";

    crObj.setPrompt(breakConnectPrompt, false, false);

    try {
      System.out.print("                                 \r" + prompt);
      userInput = crObj.getLine();
    } catch (Throwable t) {
      UserInterruption uie = null;
      if (t instanceof UserInterruption) {
        uie = (UserInterruption) t;
        retryCnt = 0;
      } else uie = new UserInterruption();

      throw uie;
    } finally {
      cwObj.print(SessionDefaults.lineSeperator);
    }
    // return characters entered by the user
    return userInput;
  }
예제 #2
0
파일: BaseX.java 프로젝트: james-jw/basex
  /** Launches the console mode, which reads and executes user input. */
  private void console() {
    Util.outln(header() + NL + TRY_MORE_X);
    verbose = true;

    // create console reader
    try (final ConsoleReader cr = ConsoleReader.get()) {
      // loop until console is set to false (may happen in server mode)
      while (console) {
        // get next line
        final String in = cr.readLine(PROMPT);
        // end of input: break loop
        if (in == null) break;
        // skip empty lines
        if (in.isEmpty()) continue;

        try {
          if (!execute(new CommandParser(in, context).pwReader(cr.pwReader()))) {
            // show goodbye message if method returns false
            Util.outln(BYE[new Random().nextInt(4)]);
            break;
          }
        } catch (final IOException ex) {
          // output error messages
          Util.errln(ex);
        }
      }
    }
  }
  public String getInputMask(String prompt, boolean isInputMask)
      throws IOException, UserInterruption {
    String password = "";
    WCIUtils wcs = null;
    boolean isWindows = System.getProperty("os.name").toUpperCase().startsWith("WINDOW");

    MaskingThread et = new MaskingThread(prompt);
    Thread mask = new Thread(et);
    mask.start();

    // if it is windows envrionment use the dll to disable echo
    if (isWindows) {
      try {
        wcs = new WCIUtils();
        wcs.disableEcho();

      } catch (Throwable e) {
      }
    }
    crObj.setMaskingThread(et, wcs);

    String breakConnectPrompt = EXIT_PROD_STR;
    if (!this.isLaunchConnect || isInputMask)
      breakConnectPrompt =
          "Command Interrupted - Please hit <Enter> ... " + SessionDefaults.lineSeperator;

    crObj.setPrompt(breakConnectPrompt, false, false);

    try {
      password = crObj.getLine();
    } catch (Throwable t) {
      UserInterruption uie = null;
      if (t instanceof UserInterruption) {
        uie = (UserInterruption) t;
        retryCnt = 0;
      } else uie = new UserInterruption();

      throw uie;
    } finally {

      // stop masking
      et.stopMasking();

      if (isWindows) {
        try {
          wcs.enableEcho();

        } catch (Exception e) {
        }

        wcs = null;
      }
      cwObj.print(SessionDefaults.lineSeperator);
    }
    // return the password entered by the user

    return password;
  }
  private String getRequiredArg(String prompt) throws IOException, UserInterruption {
    String value = null;
    String breakConnectPrompt = EXIT_PROD_STR;
    if (!this.isLaunchConnect)
      breakConnectPrompt =
          "Command Interrupted - Please hit <Enter> ... " + SessionDefaults.lineSeperator;

    crObj.setPrompt(breakConnectPrompt, false, false);
    cwObj.print(prompt);

    // set retry count to 0 if user hits a Ctrl+C while entering login parameters
    try {
      value = crObj.getLine();
    } catch (UserInterruption ui) {
      retryCnt = 0;
      throw ui;
    }
    return value;
  }
  ParseArguments(ConsoleReader crObj, ConsoleWriter cwObj) {
    this.crObj = crObj;
    this.cwObj = cwObj;

    // Prompt for login input retries if in console/interactive mode
    if (crObj.isInteractive()) this.retryCnt = 3;

    /*-------------------------------------------------------------------------**
    //Prompt for n login retries if property set
    String loginRetries=System.getProperty ("trafci.loginRetries");
    if (loginRetries!=null)
    if ((this.retryCnt = Integer.parseInt(loginRetries.trim())) <= 0)
    this.retryCnt = 1;
    **-------------------------------------------------------------------------*/
    if (retryCntProp > 0) retryCnt = retryCntProp;
  }
예제 #6
0
 public static void main(String[] args) {
   System.out.println("---> START Calculator application <---");
   // для того, чтобы читать данные из консоли спользуйте данную конструкцию
   while (true) {
     in = ConsoleReader.readFromConsole();
     if (!in[0].equals("exit")) {
       switch (in[0]) {
         case "+":
           res = res + Double.valueOf(in[1]);
           break;
         case "-":
           res = res - Double.valueOf(in[1]);
           break;
         case "*":
           res = res * Double.valueOf(in[1]);
           break;
         case "/":
           res = res / Double.valueOf(in[1]);
           break;
         default:
           double a = Double.valueOf(in[0]);
           double b = Double.valueOf(in[2]);
           double currRes = count(a, in[1], b);
           if (in.length > 3) {
             for (int i = 3; i < in.length; i += 2) {
               // double temp = currRes;
               currRes = count(currRes, in[i], Double.valueOf(in[i + 1]));
             }
           }
           res = res + currRes;
       }
       System.out.println("Result = " + res);
     } else {
       break;
     }
   }
   System.out.println("---> EXIT Calculator application <---");
 }