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


Java ConsoleReader.println方法代碼示例

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


在下文中一共展示了ConsoleReader.println方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: promptMongoVerified

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * Prompt the user asking them if they are sure they would like to do the
 * install.
 *
 * @param instanceName - The Rya instance name. (not null)
 * @param installConfig - The configuration that will be presented to the user. (not null)
 * @return The value they entered.
 * @throws IOException There was a problem reading the value.
 */
private boolean promptMongoVerified(final String instanceName, final InstallConfiguration installConfig)  throws IOException {
    requireNonNull(instanceName);
    requireNonNull(installConfig);

    final ConsoleReader reader = getReader();
    reader.println();
    reader.println("A Rya instance will be installed using the following values:");
    reader.println("   Instance Name: " + instanceName);
    reader.println("   Use Free Text Indexing: " + installConfig.isFreeTextIndexEnabled());
    reader.println("   Use Temporal Indexing: " + installConfig.isTemporalIndexEnabled());
    reader.println("   Use PCJ Indexing: " + installConfig.isPcjIndexEnabled());
    reader.println("");

    return promptBoolean("Continue with the install? (y/n) ", Optional.absent());
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:25,代碼來源:InstallPrompt.java

示例3: printLine

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void printLine(ConsoleReader console, String author, String message) {
    try {
        CursorBuffer stashed = stashLine(console);
        console.println(author + " > " + message);
        unstashLine(console, stashed);
        console.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:11,代碼來源:ConsoleUtil.java

示例4: getSparql

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public Optional<String> getSparql() throws IOException {
    final ConsoleReader reader = getReader();
    reader.setCopyPasteDetection(true); // disable tab completion from activating
    reader.setHistoryEnabled(false);    // don't store SPARQL fragments in the command history
    try {
        reader.println("Enter a SPARQL Query.");
        reader.println("Type '" + EXECUTE_COMMAND + "' to execute the current query.");
        reader.println("Type '" + CLEAR_COMMAND + "' to clear the current query.");
        reader.flush();

        final StringBuilder sb = new StringBuilder();
        String line = reader.readLine("SPARQL> ");
        while (!line.endsWith(CLEAR_COMMAND) && !line.endsWith(EXECUTE_COMMAND)) {
            sb.append(line).append("\n");
            line = reader.readLine("     -> ");
        }

        if (line.endsWith(EXECUTE_COMMAND)) {
            sb.append(line.substring(0, line.length() - EXECUTE_COMMAND.length()));
            return Optional.of(sb.toString());
        }
        return Optional.absent();
    } finally {
        reader.setHistoryEnabled(true);      // restore the ConsoleReader's settings
        reader.setCopyPasteDetection(false); // restore tab completion
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:29,代碼來源:SparqlPrompt.java

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

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

示例7: promptAccumuloVerified

import jline.console.ConsoleReader; //導入方法依賴的package包/類
/**
 * Prompt the user asking them if they are sure they would like to do the
 * install.
 *
 * @param instanceName - The Rya instance name. (not null)
 * @param installConfig - The configuration that will be presented to the user. (not null)
 * @return The value they entered.
 * @throws IOException There was a problem reading the value.
 */
private boolean promptAccumuloVerified(final String instanceName, final InstallConfiguration installConfig)  throws IOException {
    requireNonNull(instanceName);
    requireNonNull(installConfig);

    final ConsoleReader reader = getReader();
    reader.println();
    reader.println("A Rya instance will be installed using the following values:");
    reader.println("   Instance Name: " + instanceName);
    reader.println("   Use Shard Balancing: " + installConfig.isTableHashPrefixEnabled());
    reader.println("   Use Entity Centric Indexing: " + installConfig.isEntityCentrixIndexEnabled());
    reader.println("   Use Free Text Indexing: " + installConfig.isFreeTextIndexEnabled());
    // RYA-215            reader.println("   Use Geospatial Indexing: " + installConfig.isGeoIndexEnabled());
    reader.println("   Use Temporal Indexing: " + installConfig.isTemporalIndexEnabled());
    reader.println("   Use Precomputed Join Indexing: " + installConfig.isPcjIndexEnabled());
    if(installConfig.isPcjIndexEnabled()) {
        if(installConfig.getFluoPcjAppName().isPresent()) {
            reader.println("   PCJ Updater Fluo Application Name: " + installConfig.getFluoPcjAppName().get());
        } else {
            reader.println("   Not using a PCJ Updater Fluo Application");
        }
    }

    reader.println("");

    return promptBoolean("Continue with the install? (y/n) ", Optional.absent());
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:36,代碼來源:InstallPrompt.java

示例8: main

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    // Connect to the sever
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", PORT).usePlaintext(true).build();
    ReactorChatGrpc.ReactorChatStub stub = ReactorChatGrpc.newReactorStub(channel);

    CountDownLatch done = new CountDownLatch(1);
    ConsoleReader console = new ConsoleReader();

    // Prompt the user for their name
    console.println("Press ctrl+D to quit");
    String author = console.readLine("Who are you? > ");
    stub.postMessage(toMessage(author, author + " joined.")).subscribe();

    // Subscribe to incoming messages
    Disposable chatSubscription = stub.getMessages(Mono.just(Empty.getDefaultInstance())).subscribe(
        message -> {
            // Don't re-print our own messages
            if (!message.getAuthor().equals(author)) {
                printLine(console, message.getAuthor(), message.getMessage());
            }
        },
        throwable -> {
            printLine(console, "ERROR", throwable.getMessage());
            done.countDown();
        },
        done::countDown
    );

    // Publish outgoing messages
    Flux.fromIterable(new ConsoleIterator(console, author + " > "))
        .map(msg -> toMessage(author, msg))
        .flatMap(stub::postMessage)
        .subscribe(
            empty -> { },
            throwable -> {
                printLine(console, "ERROR", throwable.getMessage());
                done.countDown();
            },
            done::countDown
        );

    // Wait for a signal to exit, then clean up
    done.await();
    stub.postMessage(toMessage(author, author + " left.")).subscribe();
    chatSubscription.dispose();
    channel.shutdown();
    channel.awaitTermination(1, TimeUnit.SECONDS);
    console.getTerminal().restore();
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:50,代碼來源:ReactorChatClient.java

示例9: printLine

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void printLine(ConsoleReader console, String author, String message) throws IOException {
    CursorBuffer stashed = stashLine(console);
    console.println(author + " > " + message);
    unstashLine(console, stashed);
    console.flush();
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:7,代碼來源:ConsoleUtil.java

示例10: main

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    // Connect to the sever
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", PORT).usePlaintext(true).build();
    RxChatGrpc.RxChatStub stub = RxChatGrpc.newRxStub(channel);

    CountDownLatch done = new CountDownLatch(1);
    ConsoleReader console = new ConsoleReader();

    // Prompt the user for their name
    console.println("Press ctrl+D to quit");
    String author = console.readLine("Who are you? > ");
    stub.postMessage(toMessage(author, author + " joined.")).subscribe();

    // Subscribe to incoming messages
    Disposable chatSubscription = stub.getMessages(Single.just(Empty.getDefaultInstance())).subscribe(
        message -> {
            // Don't re-print our own messages
            if (!message.getAuthor().equals(author)) {
                printLine(console, message.getAuthor(), message.getMessage());
            }
        },
        throwable -> {
            printLine(console, "ERROR", throwable.getMessage());
            done.countDown();
        },
        done::countDown
    );

    // Publish outgoing messages
    Observable.fromIterable(new ConsoleIterator(console, author + " > "))
        .map(msg -> toMessage(author, msg))
        .flatMapSingle(stub::postMessage)
        .subscribe(
            empty -> { },
            throwable -> {
                printLine(console, "ERROR", throwable.getMessage());
                done.countDown();
            },
            done::countDown
        );

    // Wait for a signal to exit, then clean up
    done.await();
    stub.postMessage(toMessage(author, author + " left.")).subscribe();
    chatSubscription.dispose();
    channel.shutdown();
    channel.awaitTermination(1, TimeUnit.SECONDS);
    console.getTerminal().restore();
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:50,代碼來源:ChatClient.java

示例11: printCandidates

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public static void printCandidates(ConsoleReader reader, Collection<CharSequence> candidates) throws IOException {
    HashSet distinct = new HashSet(candidates);
    if(distinct.size() > reader.getAutoprintThreshold()) {
        reader.print(Messages.DISPLAY_CANDIDATES.format(candidates.size()));
        reader.flush();
        String i$ = Messages.DISPLAY_CANDIDATES_NO.format();
        String next = Messages.DISPLAY_CANDIDATES_YES.format();
        char[] allowed = new char[]{next.charAt(0), i$.charAt(0)};

        int copy;
        while((copy = reader.readCharacter(allowed)) != -1){
            String tmp = new String(new char[]{(char) copy});
            if(i$.startsWith(tmp)) {
                reader.println();
                return;
            }

            if(next.startsWith(tmp)) {
                break;
            }

            reader.beep();
        }
    }

    if(distinct.size() != candidates.size()) {
        ArrayList copy1 = new ArrayList();
        Iterator i$1 = ((Collection) candidates).iterator();

        while(i$1.hasNext()){
            CharSequence next1 = (CharSequence) i$1.next();
            if(!copy1.contains(next1)) {
                copy1.add(next1);
            }
        }

        candidates = copy1;
    }

    reader.println();

    // clear candidates
    Collection<CharSequence> clearedCandidates = new ArrayList<>();
    for(CharSequence candidate : candidates) {
        String str = candidate + "";
        String[] spl = str.split(" ");
        if(spl.length != 1) {
            str = spl[spl.length - 1];
        }
        clearedCandidates.add(str);
    }

    reader.printColumns(clearedCandidates);
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:55,代碼來源:CandidateCompletionHandler.java


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