Skip to content
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

IO.print without new line #10858

Merged
merged 8 commits into from
Aug 24, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
- [Mixed Decimal/Float arithmetic now throws an error; mixed comparisons now
attach warnings.][10725]
- [Support for creating Atoms in expressions.][10820]
- [IO.print without new line][10858]

[10614]: https://github.com/enso-org/enso/pull/10614
[10660]: https://github.com/enso-org/enso/pull/10660
[10761]: https://github.com/enso-org/enso/pull/10761
[10733]: https://github.com/enso-org/enso/pull/10733
[10725]: https://github.com/enso-org/enso/pull/10725
[10820]: https://github.com/enso-org/enso/pull/10820
[10858]: https://github.com/enso-org/enso/pull/10858

#### Enso Language & Runtime

Expand Down
19 changes: 18 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import project.Any.Any
import project.Data.Text.Text
import project.Nothing.Nothing
import project.Internal.IO_Helpers

## PRIVATE
ADVANCED
Expand Down Expand Up @@ -30,7 +31,23 @@ print_err message = @Builtin_Method "IO.print_err"

IO.println "Oh yes!"
println : Any -> Nothing
println message = @Builtin_Method "IO.println"
println message = IO_Helpers.println message '\n'

## PRIVATE
ADVANCED
Prints the provided message to standard output without adding a new line at the end.

Arguments:
- message: The message to print. It will have to_text called on it to
generate a textual representation that is then printed.

> Example
Print the message "Oh yes!" to standard output using `print` and then `println`.

IO.print "Oh "
IO.println "yes!"
print : Any -> Nothing
print message = IO_Helpers.println message ''

## PRIVATE
ADVANCED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ private
# building native image version of Enso with Standard
# libraries included in

# needed for Standard.Test.Test_Reporter
# tracked as https://github.com/enso-org/enso/issues/10028
polyglot java import java.io.PrintStream

# needed by Util_Spec
polyglot java import org.enso.base.text.CaseFoldedString as JCaseFoldedString
polyglot java import org.enso.base.text.CaseFoldedString.Grapheme
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
private

println message ends_with = @Builtin_Method "IO.println"
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ print_progress current_progress total_count status_text =
truncated_line = if line.length <= progress_width then line else
line.take (progress_width - 3) + '...'

Java_System.out.print '\r'
Java_System.out.print (' ' * progress_width)
Java_System.out.print '\r'
Java_System.out.print truncated_line
Java_System.out.print '\r'
IO.print '\r'
IO.print (' ' * progress_width)
IO.print '\r'
IO.print truncated_line
IO.print '\r'

## PRIVATE
clear_progress =
Java_System.out.print '\r'
Java_System.out.print (' ' * progress_width)
Java_System.out.print '\r'
IO.print '\r'
IO.print (' ' * progress_width)
IO.print '\r'

## PRIVATE
type Ignore_Progress_Reporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.oracle.truffle.api.nodes.Node;
import java.io.File;
Expand Down Expand Up @@ -279,7 +280,7 @@ private static String extractPositions(
Assert.assertEquals(List.newBuilder().addOne(originalOutput), context.consumeOut());

var allNodesAfterException =
nodeCountingInstrument.assertNewNodes("Execution creates some nodes", 20, 35);
nodeCountingInstrument.assertNewNodes("Execution creates some nodes", 30, 40);

// push foo call
context.send(
Expand Down Expand Up @@ -354,7 +355,14 @@ private <T extends Node> T findLiteralNode(
Class<T> type, Map<Class, java.util.List<Node>> nodes) {
var intNodes = nodes.get(type);
assertNotNull("Found LiteralNode in " + nodes, intNodes);
assertEquals("Expecting one node: " + intNodes, 1, intNodes.size());
assertEquals("Expecting two nodes: " + intNodes, 2, intNodes.size());
if (intNodes.get(1) instanceof LiteralNode ln) {
var text = ln.executeGeneric(null);
assertEquals("The second node is ends_with from IO.println", "\n", text.toString());
} else {
fail("Expecting literal two nodes: " + intNodes);
}

return type.cast(intNodes.get(0));
}

Expand Down
Loading
Loading