当前位置: 首页>>代码示例>>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;未经允许,请勿转载。