IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off

拈花ヽ惹草 提交于 2021-02-10 17:54:16

问题


I enjoy using the REPL in intelliJ for coding problems like you would find on codesignal. I currently have the version:

IntelliJ IDEA 2019.1.3 (Ultimate Edition)
Build #IU-191.7479.19, built on May 27, 2019
JRE: 1.8.0_202-release-1483-b58 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.4

I have always been really confused by the fact that when running any of these scratch files, the first 5-9 lines I am trying to print output to will just, not exist.

Below is an example program that would print out a pyramid of X's to the console

fun createPyramid(height: Int, drawChar: String = "X") {
//    repeat(9) {
//        println("blank")
//    }

    for (i in 1 until height) {
        val blank = " ".repeat(height - i)
        val row = blank + drawChar.repeat(i * 2 - 1)
        println(row)
    }
}

createPyramid(11)

If I have the repeat block commented out, my output looks like:

If I uncomment the repeat I will then get output looking like:

The really confusing part about this situation is the number of lines seem to be random, and there is inconsistencies in how it works. If I do repeat(9) I normally get 1 actually printed out "blank" If I do repeat(8) most of the time it will actually not put out the first expected "X" from the pyramid.


回答1:


Output for scratches is printed right in the editor, next to the expression, that provide this output. Scratch Output tool window prints only the output that doesn’t fit into the editor.



来源:https://stackoverflow.com/questions/56838611/intellij-ultimate-kotlin-script-repl-skips-first-printed-lines-scratch-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!