Skip to content

repl eats program output #1369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DarkDimius opened this issue Jul 8, 2016 · 6 comments
Closed

repl eats program output #1369

DarkDimius opened this issue Jul 8, 2016 · 6 comments

Comments

@DarkDimius
Copy link
Contributor

taken from http://scalapuzzlers.com/#pzzlr-013

Welcome to Scala.next (pre-alpha)  (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> implicit object RomanOrdering extends Ordering[RomanNumeral] {
         def compare(a: RomanNumeral, b: RomanNumeral) = a.value compare b.value
       }
defined module RomanOrdering
scala>
scala>
val numerals = SortedSet(RomanNumeral("M", 1000), RomanNumeral("C", 100), RomanNumeral("X", 10), RomanNumeral("I", 1), RomanNumeral("D", 500), RomanNumeral("L", 50),  RomanNumeral("V", 5))
numerals: scala.collection.immutable.SortedSet[RomanNumeral] = TreeSet(RomanNumeral(I,1), RomanNumeral(V,5), RomanNumeral(X,10), RomanNumeral(L,50), RomanNumeral(C,100), RomanNumeral(D,500), RomanNumeral(

scala>
scala> println("Roman numeral symbols for 1 5 10 50 100 500 1000:")
Roman numeral symbols for 1 5 10 50 100 500 1000:
scala> for (num <- numerals; sym = num.symbol) { print(s"${sym} ") }
scala> numerals map { _.symbol } foreach { sym => print(s"${sym} ") }
scala>

The numbers were printed, but then they were swallowed by repl and replaced by scala> invitation.

@kzys
Copy link
Contributor

kzys commented Jul 28, 2016

We probably don't need the entire puzzle to reproduce the issue.

% ./bin/dotr
Starting dotty REPL...
Welcome to Scala.next (pre-alpha)  (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> print("hello") 
scala>  

@nicolasstucki
Copy link
Contributor

This is still an issue with the new repl

@benkobalog
Copy link
Contributor

benkobalog commented Jan 10, 2018

I looked into this issue. The problem seems to be that the line redraw is oblivious to the output what is printed by the interpreted Scala code, because it only follows the standard input. So the redraw overwrites anything printed in the last line.

I have two solutions, but I'm not sure if they are good solutions.

  1. If something has a Unit return value print "\n" or "()". This will look a bit off in any other situations than a print without a "\n" at the end, because there will be an additional new line.

  2. Watch the standard output and if the line is not empty after interpreting a code part

    1. write a "\n" character, so the "scala>" prompt will come in the next line.
    2. set the prompt offset so it doesn't start at the start of the line, but right after the last output.

If any of these are acceptable or you have a better idea, I'd like to implement it.

@smarter
Copy link
Member

smarter commented Jan 10, 2018

Ammonite-REPL seems to handle this correctly. Would be interesting to figure out how since our REPL UI code is based on Ammonite.

@allanrenucci
Copy link
Contributor

I think a very simple fix would be to print a new line after a command is interpreted

@benkobalog
Copy link
Contributor

Ammonite prints an additional new line after each command.
It also prints a new line for commands returning Unit values.

benkobalog added a commit to benkobalog/dotty that referenced this issue Jan 25, 2018
Keeping only one newline for Unit values if there are more of them, in a command.
benkobalog added a commit to benkobalog/dotty that referenced this issue Jan 26, 2018
benkobalog added a commit to benkobalog/dotty that referenced this issue Jan 28, 2018
Added ScriptedTests which keep the original output and input instead of
cutting end of line whitespaces
Added a test case for Unit
benkobalog added a commit to benkobalog/dotty that referenced this issue Jan 28, 2018
benkobalog added a commit to benkobalog/dotty that referenced this issue Jan 28, 2018
Added ScriptedTests which keep the original output and input instead of
cutting end of line whitespaces
Added a test case for Unit
allanrenucci added a commit that referenced this issue May 9, 2018
Fix #1369 Print a newline after interpreted commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants