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

Fix Console.Write on iOS #56713

Merged
merged 33 commits into from
Sep 2, 2021
Merged

Conversation

MaximLipnin
Copy link
Contributor

@MaximLipnin MaximLipnin commented Aug 2, 2021

Fixes #36440.

This is iOS-part of Egor's fix (with Ralf's suggestion) from #37078.

For this code snippet:

Console.Write ("A");
Console.Write ("B");
Console.WriteLine ("C");

Console.Write ("D\nd");
Console.Write ("E\ne");
Console.WriteLine ("F");

the output will be:

2021-08-02 12:19:25.865365+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] ABC
2021-08-02 12:19:25.868503+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] D
2021-08-02 12:19:25.869020+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] dE
2021-08-02 12:19:25.869138+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] eF

@ghost
Copy link

ghost commented Aug 2, 2021

Tagging subscribers to this area: @dotnet/area-system-console
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #36440.

This is iOS-part of Egor's fix from #37078.

For this code snippet:

Console.Write ("A");
Console.Write ("B");
Console.WriteLine ("C");

Console.Write ("D\nd");
Console.Write ("E\ne");
Console.WriteLine ("F");

the output will be:

2021-08-02 12:19:25.865365+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] ABC
2021-08-02 12:19:25.868503+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] D
2021-08-02 12:19:25.869020+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] dE
2021-08-02 12:19:25.869138+0300 iOS.Simulator.ConsoleWrite.Test[4681:132934] eF
Author: MaximLipnin
Assignees: -
Labels:

area-System.Console

Milestone: -

@am11
Copy link
Member

am11 commented Aug 2, 2021

Can we enable

[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Not supported on Browser, iOS, MacCatalyst, or tvOS.")]
public void TestEncoding(string inputString)

or any other test for this on iOS? (from the skip reason message of this test, it's not clear which API is not supported)

@MaximLipnin MaximLipnin marked this pull request as ready for review August 2, 2021 15:11
@MaximLipnin
Copy link
Contributor Author

Can we enable

[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Not supported on Browser, iOS, MacCatalyst, or tvOS.")]
public void TestEncoding(string inputString)

or any other test for this on iOS? (from the skip reason message of this test, it's not clear which API is not supported)

Added TestConsoleWrite test

@adamsitnik adamsitnik added this to the 6.0.0 milestone Aug 9, 2021
@MaximLipnin
Copy link
Contributor Author

It's quite close to a working state, the only problem is that I cannot find the right moment to write the data remaining in the cache to the stream before closing the app.

@MaximLipnin
Copy link
Contributor Author

The PR looks pretty green now. @stephentoub Would you like to take another look?

}

// no newlines found, add the entire buffer to the cache
cache.Append(charBuffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question about this change... it seems like this change means that if I have code that does:

while (true)
{
    Console.Write(".");
    await Task.Delay(1000);
}

to print out a period to the console once a second, for example as you might find with a progress indicator in a console app, that the data will never be emitted to the console, because newlines are never found. Am I understanding correctly? Is that not an issue, e.g. because Console is only used for diagnostic messages in an iOS app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a thing I wasn't able to beat. I mentioned it a bit earlier #56713 (comment). The current Xamarin implementation has the same drawback so it won't surprise the existing customers.

@MaximLipnin MaximLipnin merged commit faafb32 into dotnet:main Sep 2, 2021
@MaximLipnin MaximLipnin deleted the fix_console_write_on_ios branch September 2, 2021 13:53
@MaximLipnin
Copy link
Contributor Author

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2021

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1194460075

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2021

@MaximLipnin backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix Console.Write on iOS
Applying: Move the helper method to iOS-specific location
Applying: Add a test
Applying: Remove unused using
Applying: Apply Ralf's suggestion
Applying: Move Interop.Sys.Log to a local function
Applying: Move the caching logic over to StreamWriter
Applying: feedback
Applying: Remove unused usings
Applying: Derive from StreamWriter
Applying: Feedback
Applying: Try a solution not changing public API surface and using NSLogStream with a decoder
Applying: Some feedback
Applying: Use ArrayPool
Applying: Not rely on the length of the rented array
Applying: Address the feedback
Applying: not use _ prefix for local variable
Applying: Address the feedback
Using index info to reconstruct a base tree...
M	src/libraries/System.Console/src/System/ConsolePal.iOS.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Console/src/System/ConsolePal.iOS.cs
CONFLICT (content): Merge conflict in src/libraries/System.Console/src/System/ConsolePal.iOS.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0018 Address the feedback
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

akoeplinger pushed a commit that referenced this pull request Sep 3, 2021
akoeplinger pushed a commit that referenced this pull request Sep 3, 2021
steveisok pushed a commit to steveisok/runtime that referenced this pull request Sep 10, 2021
Expands on dotnet#56713 by moving the caching implementation to a separate internal class leaving only the interop calls in ConsolePal.iOS and ConsolePal.Android

Fixes dotnet#57304
steveisok added a commit that referenced this pull request Sep 14, 2021
Expands on #56713 by moving the caching implementation to a separate internal class leaving only the interop calls in ConsolePal.iOS and ConsolePal.Android

Fixes #57304
github-actions bot pushed a commit that referenced this pull request Sep 14, 2021
Expands on #56713 by moving the caching implementation to a separate internal class leaving only the interop calls in ConsolePal.iOS and ConsolePal.Android

Fixes #57304
@ghost ghost locked as resolved and limited conversation to collaborators Oct 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Console.Write prints a new line on iOS
9 participants