-
Notifications
You must be signed in to change notification settings - Fork 31
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
RenderDocumentToText adds an extra newline #21
Comments
@seanomaly Full code: var doc = new Document(/* ... */);
var sw = new StringWriter();
ConsoleRenderer.RenderDocumentToText(doc, new TextRenderTarget(sw));
string str = sw.GetStringBuilder().ToString();
Console.WriteLine(str); The problem lies in the way Windows console is implemented (actually, configured by .NET to behave). When current cursor position reaches the end of line (that is, when If you inspect If you want a string which can be written to console, you need to override default new line sequence, even if it looks counterintuitive: var sw = new StringWriter { NewLine = "" };
ConsoleRenderer.RenderDocumentToText(doc, new TextRenderTarget(sw));
Console.Write(sw.GetStringBuilder().ToString()); The produced string will contain no new lines, so will be written to console correctly. You also need to change Why are you using this method of writing to console? |
Thanks for the detailed explanation and the workaround. On a related note, how do I get the output properly formatted on the command prompt? i.e. cmd.exe |
@seanomaly Also colors may be changed even if it isn't needed by the app... I should probably add rendering options to allow disabling some of attributes. But that would make sense only after implementing #11 and #14, which are planned for the next major release, so it would take some time to get there. Speaking of formatting in |
@Athari
It renders beautifully in the console : |
@DumboJetEngine |
@Athari |
@DumboJetEngine As to spaces at the end of line, they come from It's possible to set buffer width after measuring and arranging elements (see You'll need to trim whitespace either way as, say, paragraphs of text would still have trailing whitespace, even when rendered the exactly sized By the way, |
Aha! |
If I do this
ConsoleRenderer.RenderDocument(doc);
I get the output as expected.But if I do this:
StringWriter sw = new StringWriter();
vs
ConsoleRenderer.RenderDocumentAsText(doc, sw);
and then
Console.WriteLine(sw.StringBuilder().toString());
There is an extra
"\r\n"
between each line.The text was updated successfully, but these errors were encountered: