question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NonInteractiveCliktConsole only reads in the first line from an input file

See original GitHub issue

Currently the NonInteractiveCliktConsole only reads in the first line of any input file passed as the input stream.

This can be fixed by caching the buffered reader like I have below.

class NonInteractiveCliktConsole : CliktConsole {
    private val bufferedReader by lazy {
        System.`in`.bufferedReader()
    }

    override fun promptForLine(prompt: String, hideInput: Boolean) = try {
        print(prompt, false)
        bufferedReader.readLine()
    } catch (err: IOException) {
        null
    }

    override fun print(text: String, error: Boolean) {
        if (error) {
            System.err
        } else {
            System.out
        }.print(text)
    }

    override val lineSeparator: String get() = System.lineSeparator()
}

I’m using version 1.5.0.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ajaltcommented, May 12, 2019

Thanks for the reports! This is fixed in 4425fe2, which is part of the 2.0.0 release.

1reaction
grotecommented, Mar 26, 2019

Yeah I just ran the tests myself in the hope of finding the issue, but they passed for me, even when using stdin.provideText("test\ntest\n") instead of the line joining.

When modifying one of the samples to use the code above, I could reproduce the problem though by running:

echo "test
test
" | ./runsample prompt

or

echo "test\ntest\n" | ./runsample prompt

Before thinking about how to add a test here, maybe let’s see if you can reproduce the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# File.ReadAllLines only recognizing the first line [closed]
The Console.ReadLine(); code will used input stream. Therefore, The program will wait till the user input something. Read Below article.
Read more >
3 ways for reading user's input from console in Java
The Console class was introduced in Java 1.6, and it has been becoming a preferred way for reading user's input from the command...
Read more >
36.1. Interactive and non-interactive shells and scripts
An interactive shell reads commands from user input on a tty. Among other things, such a shell reads startup files on activation, displays...
Read more >
Having trouble with the Read-Host cmdlet not actually waiting ...
Having trouble with the Read-Host cmdlet not actually waiting for the user input before moving to the next line in the script.
Read more >
tcsh - Invoke a C shell - IBM
login file. In the normal case, the shell begins reading commands from the terminal, prompting with >. The shell repeatedly reads a line...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found