當前位置: 首頁>>代碼示例>>Java>>正文


Java ConsoleReader.setPrompt方法代碼示例

本文整理匯總了Java中jline.console.ConsoleReader.setPrompt方法的典型用法代碼示例。如果您正苦於以下問題:Java ConsoleReader.setPrompt方法的具體用法?Java ConsoleReader.setPrompt怎麽用?Java ConsoleReader.setPrompt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jline.console.ConsoleReader的用法示例。


在下文中一共展示了ConsoleReader.setPrompt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: increasePop

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * Raise population of hippopotamus amphibius within console.
 * @param console
 */
public static void increasePop(ConsoleReader console) {
    HippopotamusFactory builder = HippopotamusFactory.builder();

    if (System.getenv("HIPPO_SIZE") != null) {
        int hippoSize = Integer.parseInt(System.getenv("HIPPO_SIZE"));
        builder.size(hippoSize);
    }

    Hippopotamus hippo = builder.build();

    try {
        for (double i = 0; i < Math.PI; i += 0.1) {
            console.println(hippo.toString().replaceAll("^|\n", "\n" + StringUtils.repeat(" ", (int) (Math.sin(i) * 100))));
            console.flush();
            Thread.sleep(100);
        }
    } catch (IOException | InterruptedException e) {
        System.err.println("Supercalafrajilistichippopotamusexception");
    }

    hippo.submerge();

    console.setPrompt(hippo.toString());
}
 
開發者ID:graknlabs,項目名稱:grakn,代碼行數:29,代碼來源:HippopotamusFactory.java

示例2: getPassword

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public char[] getPassword() throws IOException {
    char[] password = new char[0];

    final ConsoleReader reader = getReader();
    reader.setPrompt("Password: ");
    String passwordStr = reader.readLine('*');
    password = passwordStr.toCharArray();

    // Reading the password into memory as a String is less safe than a char[]
    // because the String is immutable. We can't clear it out. At best, we can
    // remove all references to it and suggest the GC clean it up. There are no
    // guarantees though.
    passwordStr = null;
    System.gc();

    return password;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:19,代碼來源:PasswordPrompt.java

示例3: start_0

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void start_0() {
    try {
        ConsoleReader console = new ConsoleReader();
        console.setPrompt("> ");
        while (true) {
            try {
                String line = console.readLine();
                switch (line) {
                case "init:stop().":
                    console.shutdown();
                    Init.stop();
                    break;
                default:
                    if (!simple_call(line)) {
                        throw new Error("Unsupported operation");
                    }
                }
            } catch (Error error) {
                System.err.println(error);
            }
        }
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }
}
 
開發者ID:jerlang,項目名稱:jerlang,代碼行數:26,代碼來源:ShellStart.java

示例4: buildInstance

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static HeroicInteractiveShell buildInstance(
    final List<CommandDefinition> commands, FileInputStream input
) throws Exception {
    final ConsoleReader reader = new ConsoleReader("heroicsh", input, System.out, null);

    final FileHistory history = setupHistory(reader);

    if (history != null) {
        reader.setHistory(history);
    }

    reader.setPrompt(String.format("heroic> "));
    reader.addCompleter(new StringsCompleter(
        ImmutableList.copyOf(commands.stream().map((d) -> d.getName()).iterator())));
    reader.setHandleUserInterrupt(true);

    return new HeroicInteractiveShell(reader, commands, history);
}
 
開發者ID:spotify,項目名稱:heroic,代碼行數:19,代碼來源:HeroicInteractiveShell.java

示例5: readCommands

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public void readCommands() {
    try {
        console = new ConsoleReader();
        List commandNames = new ArrayList();
        for (Command c : commands) {
            c.setupCompleter();
            commandNames.add(c.names[0]);
        }
        console.addCompleter(new StringsCompleter(commandNames));
        console.setPrompt("proptester> ");
        String line;
        while ((line = console.readLine()) != null) {
            processCommand(line);
        }
    } catch (IOException io) {
        io.printStackTrace();
    }
}
 
開發者ID:Talend,項目名稱:components,代碼行數:19,代碼來源:PropertiesTester.java

示例6: start

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public void start() throws Exception {
    console = new ConsoleReader();
    console.getTerminal().setEchoEnabled(false);
    console.setPrompt("\u001B[32menkan\u001B[0m> ");
    History history = new FileHistory(new File(System.getProperty("user.home"), ".enkan_history"));
    console.setHistory(history);

    CandidateListCompletionHandler handler = new CandidateListCompletionHandler();
    console.setCompletionHandler(handler);
    consoleHandler = new ConsoleHandler(console);
    clientThread.execute(consoleHandler);
    clientThread.shutdown();
}
 
開發者ID:kawasima,項目名稱:enkan,代碼行數:14,代碼來源:ReplClient.java

示例7: CliRun

import jline.console.ConsoleReader; //導入方法依賴的package包/類
CliRun( CommandRunner commandRunner,
        CliProperties cliProperties )
        throws IOException {
    this.commandRunner = commandRunner;
    this.cliProperties = cliProperties;
    this.input = new InterruptableInputStream( System.in );

    // JLine must run with a blocking InputStream
    System.setProperty( "jline.esc.timeout", "0" );
    consoleReader = new ConsoleReader( input, System.out );
    started = new AtomicBoolean( false );
    consoleReader.setPrompt( getPrompt() );
    consoleReader.setExpandEvents( false );
}
 
開發者ID:renatoathaydes,項目名稱:osgiaas,代碼行數:15,代碼來源:CliRun.java

示例8: ReflexRunnerDebugger

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public ReflexRunnerDebugger(IReflexHandler handler, ConsoleReader reader, PrintWriter writer) {
    this.reader = reader;
    this.writer = writer;
    this.handler = handler;
    writer.println("Reflex Debugger");
    writer.println();
    writer.println("Type h <CR> for help");
    writer.flush();
    reader.setPrompt("reflex> ");
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:11,代碼來源:ReflexRunnerDebugger.java

示例9: readInputString

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private static String readInputString(ConsoleReader reader, PrintWriter out, String prompt, String defaultString) {
  try {
    // save file
    StringBuilder sb = new StringBuilder("warp10:");
    sb.append(prompt);
    if (!Strings.isNullOrEmpty(defaultString)) {
      sb.append(", default(");
      sb.append(defaultString);
      sb.append(")");
    }
    sb.append(">");
    reader.setPrompt(sb.toString());
    String line;
    while ((line = reader.readLine()) != null) {
      line = line.trim();
      if (Strings.isNullOrEmpty(line) && Strings.isNullOrEmpty(defaultString)) {
        continue;
      }
      if (Strings.isNullOrEmpty(line) && !Strings.isNullOrEmpty(defaultString)) {
        return defaultString;
      }
      if (line.equalsIgnoreCase("cancel")) {
        break;
      }
      return line;
    }
  } catch (Exception exp) {
    if (WorfCLI.verbose) {
      exp.printStackTrace();
    }
    out.println("Error, unable to read the string. error=" + exp.getMessage());
  }
  return null;

}
 
開發者ID:cityzendata,項目名稱:warp10-platform,代碼行數:36,代碼來源:WorfInteractive.java

示例10: promptBoolean

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * Prompts a user for a boolean value. The prompt will be repeated until
 * a value true/false string has been submitted. If a default value is
 * provided, then it will be used if the user doens't enter anything.
 *
 * @param prompt - The prompt for the input. (not null)
 * @param defaultValue - The default value for the input if one is provided. (not null)
 * @return The value the user entered.
 * @throws IOException There was a problem reading values from the user.
 */
protected boolean promptBoolean(final String prompt, final Optional<Boolean> defaultValue) throws IOException {
    requireNonNull(prompt);
    requireNonNull(defaultValue);

    final ConsoleReader reader = getReader();
    reader.setPrompt(prompt);

    Boolean value = null;
    boolean prompting = true;

    while(prompting) {
        // An empty input means to use the default value.
        final String input = reader.readLine();
        if(input.isEmpty() && defaultValue.isPresent()) {
            value = defaultValue.get();
            prompting = false;
        }

        // Check if it is one of the affirmative answers.
        if(isAffirmative(input)) {
            value = true;
            prompting = false;
        }

        // Check if it is one of the negative answers.
        if(isNegative(input)) {
            value = false;
            prompting = false;
        }

        // If we are still prompting, the input was invalid.
        if(prompting) {
            reader.println("Invalid response (true/false)");
        }
    }

    return value;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:49,代碼來源:JLinePrompt.java

示例11: promptString

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * Prompts a user for a String value. The prompt will be repeated until a
 * value has been submitted. If a default value is provided, then it will be
 * used if the user doesn't enter anything.
 *
 * @param prompt - The prompt for the input. (not null)
 * @param defaultValue - The default value for the input if one is provided. (not null)
 * @return The value the user entered.
 * @throws IOException There was a problem reading values from the user.
 */
protected String promptString(final String prompt, final Optional<String> defaultValue) throws IOException {
    requireNonNull(prompt);
    requireNonNull(defaultValue);

    final ConsoleReader reader = getReader();
    reader.setPrompt(prompt);

    String value = null;
    boolean prompting = true;

    while(prompting) {
        // Read a line of input.
        final String input = reader.readLine();

        if(!input.isEmpty()) {
            // If a value was provided, return it.
            value = input;
            prompting = false;
        } else {
            // Otherwise, if a default value was provided, return it;
            if(defaultValue.isPresent()) {
                value = defaultValue.get();
                prompting = false;
            } else {
                // Otherwise, the user must provide a value.
                reader.println("Invalid response. Must provide a value.");
            }
        }
    }

    return value;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:43,代碼來源:JLinePrompt.java

示例12: main

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        final Optional<String> host = args.length > 0 ? Optional.of(args[0]) : Optional.empty();
        final Optional<Integer> port = args.length > 1 ? Optional.of(Integer.valueOf(args[1])) : Optional.empty();

        try {
            ConsoleReader console = new ConsoleReader(null, System.in, System.out, null);
            console.setPrompt("\nmintDS> ");
            console.setBellEnabled(false);

            MintDsClient client = new MintDsClient.Builder()
                    .host(host.orElse(DEFAULT_HOST))
                    .port(port.orElse(DEFAULT_PORT))
                    .numberOfThreads(1)
                    .numberOfConnections(1)
                    .build();

            for (; ;) {
                String line = console.readLine();
                if (line == null || "bye".equals(line.toLowerCase())) {
                    break;
                }

                if (line.trim().isEmpty()) {
                    continue;
                }

                // Waits for the response
                CompletableFuture<Response> future = client.send(DefaultRequest.fromString(line));
                System.out.println(future.get());
            }

            client.close();

        } finally {
            TerminalFactory.get().restore();
        }
    }
 
開發者ID:mintDS,項目名稱:mintds,代碼行數:39,代碼來源:MintDsTerminal.java

示例13: onRun

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Inject(method = "run", at = @At("HEAD"), cancellable = true, remap = false)
private void onRun(CallbackInfo ci) {
    final ConsoleReader reader = TerminalConsoleAppender.getReader();

    if (reader != null) {
        TerminalConsoleAppender.setFormatter(ConsoleFormatter::format);
        reader.addCompleter(new ConsoleCommandCompleter());

        reader.setPrompt("> ");
        reader.setHandleUserInterrupt(true);

        try {
            String line;
            while (!this.server.isServerStopped() && this.server.isServerRunning()) {
                try {
                    line = reader.readLine();
                    if (line == null) {
                        break;
                    }

                    line = line.trim();
                    final String lineFinal = line;
                    if (!line.isEmpty()) {
                        this.server.addScheduledTask(() -> Canary.getServer().consoleCommand(lineFinal));
                    }
                } catch (IOException e) {
                    Canary.log.error("Exception handling console input", e);
                }
            }
        } catch (UserInterruptException exception) {
            reader.shutdown();
            Canary.commands().parseCommand(Canary.getServer(), "stop", new String[]{ "stop", "Ctrl-C", "at", "console" });
        }

        ci.cancel();
    } else {
        TerminalConsoleAppender.setFormatter(EnumChatFormatting::getTextWithoutFormattingCodes);
    }
}
 
開發者ID:NeptunePowered,項目名稱:NeptuneMod,代碼行數:40,代碼來源:MixinConsoleHandler.java

示例14: main

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    RunnerConfigure.getInstance();

    Logger.info("starting bootscope runner...");

    Runtime.getRuntime().addShutdownHook(new Thread()
    {
        @Override
        public void run()
        {
            System.out.println("Shutdown progressing...");
            BytescopeContext.close();
        }
    });

    AnsiPrint.enable = (!SystemUtils.IS_OS_WINDOWS);

    if (ArrayUtils.contains(args, "-ansi"))
        AnsiPrint.enable = true;
    else if (ArrayUtils.contains(args, "-noansi"))
        AnsiPrint.enable = false;

    ConsoleReader console = BytescopeConsole.getConsole();
    console.setPrompt(AnsiPrint.green("bytescope> "));

    //console.addCompleter(new AggregateCompleter(new ArgumentCompleter()));

    String line;

    Logger.info("bootscope runner started.");
    while (true) {
        line = console.readLine().trim();
        if($.isEmpty(line)) continue;
        if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("bye")) {
            Logger.info("Shutdown progressing...");
            return;
        } else if (line.equalsIgnoreCase("cls")) {
            console.clearScreen();
            continue;
        }

        try {
            CommandResult result = CommandChainExecutor.getInstance().execute(line);
            if(result.getResult() < 0) {
                BytescopeConsole.getWriter().write(AnsiPrint.red("[error] ") + result.getMessage() + "\n");
            } else {
                if($.isNotBlank(result.getMessage())) {
                    BytescopeConsole.getWriter().write(result.getMessage() + "\n");
                }
            }
        } catch(Throwable t) {
            t.printStackTrace();
        }
    }
}
 
開發者ID:scouter-project,項目名稱:bytescope,代碼行數:56,代碼來源:RunnerMain.java

示例15: readInputPath

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private static String readInputPath(ConsoleReader reader, PrintWriter out, String prompt, String defaultPath) {
  try {
    // save file
    StringBuilder sb = new StringBuilder();
    sb.append("warp10:");
    sb.append(prompt);
    if (!Strings.isNullOrEmpty(defaultPath)) {
      sb.append(", default(");
      sb.append(defaultPath);
      sb.append(")");
    }
    sb.append(">");

    reader.setPrompt(sb.toString());
    String line;
    while ((line = reader.readLine()) != null) {
      line = line.trim();
      if (Strings.isNullOrEmpty(line) && Strings.isNullOrEmpty(defaultPath)) {
        continue;
      }

      if (Strings.isNullOrEmpty(line) && !Strings.isNullOrEmpty(defaultPath)) {
        return defaultPath;
      }

      if (line.equalsIgnoreCase("cancel")) {
        break;
      }

      Path outputPath = Paths.get(line);
      if (Files.notExists(outputPath)) {
        out.println("The path " + line + " does not exists");
        continue;
      }
      return line;
    }
  } catch (Exception exp) {
    if (WorfCLI.verbose) {
      exp.printStackTrace();
    }
    out.println("Error, unable to read the path. error=" + exp.getMessage());
  }
  return null;
}
 
開發者ID:cityzendata,項目名稱:warp10-platform,代碼行數:45,代碼來源:WorfInteractive.java


注:本文中的jline.console.ConsoleReader.setPrompt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。