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


Java ConsoleReader.readLine方法代碼示例

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


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

示例1: defaultInitDoc

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private void defaultInitDoc(ConsoleReader consoleReader) throws Exception
{
    if (Files.exists(servicePath)) return;

    String hostName = NetworkUtils.getHostName();
    if (hostName.equals("127.0.0.1") || hostName.equalsIgnoreCase("127.0.1.1") || hostName.split("\\.").length != 4)
    {
        String input;
        System.out.println("Please write the first Wrapper IP address:");
        while ((input = consoleReader.readLine()) != null)
        {
            if ((input.equals("127.0.0.1") || input.equalsIgnoreCase("127.0.1.1") || input.split("\\.").length != 4))
            {
                System.out.println("Please write the real ip address :)");
                continue;
            }

            hostName = input;
            break;
        }
    }
    new Document("wrapper", Arrays.asList(new WrapperMeta("Wrapper-1", hostName, "admin")))
            .append("serverGroups", Arrays.asList(new LobbyGroup()))
            .append("proxyGroups", Arrays.asList(new BungeeGroup()))
            .saveAsConfig(servicePath);
}
 
開發者ID:Dytanic,項目名稱:CloudNet,代碼行數:27,代碼來源:CloudConfig.java

示例2: run

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public void run()
{
    if (! CoreMain.isConsoleEnabled())
    {
        return;
    }
    final ConsoleReader reader = this.core.getReader();
    try
    {
        while (this.core.isRunning())
        {
            final String line = CoreMain.isUseJline() ? reader.readLine(">", null) : reader.readLine();
            if ((line == null) || (line.trim().length() <= 0))
            {
                continue;
            }
            EventType.callEvent(new SenderCommandEvent(this.core.getConsoleSender(), line));
        }
    } catch (final NoSuchElementException ignored)
    {
    } catch (final IOException e)
    {
        e.printStackTrace();
    }
}
 
開發者ID:Diorite,項目名稱:Diorite-old,代碼行數:27,代碼來源:ConsoleReaderThread.java

示例3: run

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public void run() {
    if (Nukkit.useConsole) {
        ConsoleReader reader = this.server.reader;

        try {
            while (!server.isStopped() && server.isRunning()) {
                String line;

                if (Nukkit.useJline) {
                    line = reader.readLine("> ", null);
                } else {
                    line = reader.readLine();
                }

                if (line != null && !line.trim().isEmpty()) {
                    server.issueCommand(line);
                }
            }
        } catch (IOException e) {
            Bukkit.getLogger().log(Level.SEVERE, "Exception handling console input", e);
        }
    }
}
 
開發者ID:MagicDroidX,項目名稱:Brynhildr,代碼行數:25,代碼來源:ConsoleHandler.java

示例4: promptForText

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * @param prompt
 *         to display to the user
 * @param mask
 *         single character to display instead of what the user is typing, use null if text is not secret
 * @return the text which was entered
 * @throws Exception
 *         in case of errors
 */
@Nonnull
private String promptForText(@Nonnull String prompt, @Nullable Character mask) throws Exception {
    String line;
    ConsoleReader consoleReader = new ConsoleReader(in, out);
    // Disable expansion of bangs: !
    consoleReader.setExpandEvents(false);
    // Ensure Reader does not handle user input for ctrl+C behaviour
    consoleReader.setHandleUserInterrupt(false);
    line = consoleReader.readLine(prompt + ": ", mask);
    consoleReader.close();

    if (line == null) {
        throw new CommandException("No text could be read, exiting...");
    }

    return line;
}
 
開發者ID:neo4j,項目名稱:cypher-shell,代碼行數:27,代碼來源:Main.java

示例5: getProperty

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private static void getProperty(
    ConsoleReader reader, Properties properties, String property, String defaultProperty) {
  if (properties.get(property) == null) {
    //log.warn(property + " property was not found neither in the file [" + CONFIGURATION_FILE + "] nor in Environment Variables");
    try {
      String insertedProperty = reader.readLine(property + "[" + defaultProperty + "]: ");
      if (insertedProperty == null) {
        insertedProperty = defaultProperty;
      }
      properties.put(property, insertedProperty);
    } catch (IOException e) {
      System.out.println("Error while reading from input");
      exit(1);
    }
  }
}
 
開發者ID:openbaton,項目名稱:openbaton-client,代碼行數:17,代碼來源:NFVOCommandLineInterface.java

示例6: 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

示例7: 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

示例8: Main

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public Main() throws Exception {
	reader = new ConsoleReader();
	try {
		String apiToken = reader.readLine("API Token: ");
		int startAt = Integer.parseInt(reader.readLine("Start at: "));
		int timeout = Integer.parseInt(reader.readLine("Timeout: "));

		bot = new TelegramBotBuilder(apiToken, this, startAt).setGetUpdatesUpdater(timeout).build();
	} finally {
		reader.getTerminal().restore();
	}

	// User botUser = bot.getMe();

	bot.run();
}
 
開發者ID:azteca1998,項目名稱:telegram-api-java,代碼行數:17,代碼來源:Main.java

示例9: 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

示例10: main

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception
{
    Log.setOutput( new PrintStream( ByteStreams.nullOutputStream() ) );
    AnsiConsole.systemInstall();
    consoleReader = new ConsoleReader();
    consoleReader.setExpandEvents( false );

    logger = new BungeeLogger();
    System.setErr( new PrintStream( new LoggingOutputStream( logger, Level.SEVERE ), true ) );
    System.setOut( new PrintStream( new LoggingOutputStream( logger, Level.INFO ), true ) );

    instance = new ChunkrServer();

    while ( isRunning )
    {
        String line = consoleReader.readLine( ">" );
        if ( line != null )
        {
            if ( !getInstance().getPluginManager().dispatchCommand( line ) )
            {
                logger.info( "Command not found" );
            }
        }
    }
}
 
開發者ID:Chnkr,項目名稱:ChunkrConnect,代碼行數:26,代碼來源:ChunkrServer.java

示例11: createReader

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * creates the cli and listens for input
 */
public void createReader() throws IOException {
    try {
        reader = new ConsoleReader();
        changeStatusInPrompt("parsed");
        setUpCompletors(reader);
        String line;
        while ((line = reader.readLine()) != null) {
            if (handleInput(line)) break;
        }
    } catch (IOException ex) {
        LOG.error("Setting up the CLI failed.",ex);
        throw ex;
    }
}
 
開發者ID:StuPro-TOSCAna,項目名稱:stupro_toscana_vorprojekt,代碼行數:18,代碼來源:Controller.java

示例12: getInput

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public String getInput(String prompt) throws Exception {
    if (!Settings.instance().getLocalMode()) {
        Log.error("You can only call 'getInput' in local mode");
        return "";
    }

    ConsoleReader reader = new ConsoleReader();
    return reader.readLine(prompt);
}
 
開發者ID:StallionCMS,項目名稱:stallion-core,代碼行數:10,代碼來源:JavaToJsHelpers.java

示例13: 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

示例14: readLine

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private String readLine(ConsoleReader reader)
  throws IOException
{
  if (forcePrompt == null) {
    prompt = "";
    if (consolePresent) {
      if (changingLogicalPlan) {
        prompt = "logical-plan-change";
      } else {
        prompt = "apex";
      }
      if (currentApp != null) {
        prompt += " (";
        prompt += currentApp.getApplicationId().toString();
        prompt += ") ";
      }
      prompt += "> ";
    }
  } else {
    prompt = forcePrompt;
  }
  String line = reader.readLine(prompt, consolePresent ? null : (char)0);
  if (line == null) {
    return null;
  }
  return ltrim(line);
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:28,代碼來源:ApexCli.java

示例15: execute

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  String name = args[1];
  if (macros.containsKey(name) || aliases.containsKey(name)) {
    System.err.println("Name '" + name + "' already exists.");
    return;
  }
  try {
    List<String> commands = new ArrayList<>();
    while (true) {
      String line;
      if (consolePresent) {
        line = reader.readLine("macro def (" + name + ") > ");
      } else {
        line = reader.readLine("", (char)0);
      }
      if (line.equals("end")) {
        macros.put(name, commands);
        updateCompleter(reader);
        if (consolePresent) {
          System.out.println("Macro '" + name + "' created.");
        }
        return;
      } else if (line.equals("abort")) {
        System.err.println("Aborted");
        return;
      } else {
        commands.add(line);
      }
    }
  } catch (IOException ex) {
    System.err.println("Aborted");
  }
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:36,代碼來源:ApexCli.java


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