Closed agbarbosa closed 3 years ago
Hi agbarbosa, please give me an example of how this should ideally work, and I'll see what I can do? i.e. pretend it was done, ... what would some sample code look like with that functionality? txs, Alan
Hi @goblinfactory, thanks for your reply and for the question. The reason I brought this up was due to my attempt to make the code in this repository here to work inside an IConsole window: https://gist.github.com/DanielSWolf/0ab6a96899cc5377bf54
More specifically for the method UpdateText(string text). See if that makes sense to you.
Unfortunately that's too much to read, and doesn't "help me ... help you." Please provide the smallest code example you can make up, ...write it down now, in this preview, of how you would like it to behave...
var w = new Window();
var sb = new StringBuilder();
w.WriteLine( ... ??? sb ??);
or
sb.WriteLine(...using Konsole semantics?);
Give me 2 or 3 lines of code that shows me how you would ideally like to be able to use an IConsole instance? For example, are you looking for something like the following?
var sb = new StringBuilder();
var w = new Window(sb);
w.SplitLeft().WriteLine("I am in the left window");
Console.WriteLine(sb.ToString());
My point is that you need to provide a simple example that explains exactly what you want. Be specific. Write code that can be easily understood, and that demonstrates the problem you want to solve. Keep the code as short as possible, a few lines only.
good luck! We want to try to help you, but you have to help us first by writing a short, clean example.
Alan
Sure... thanks again for the so quick reply!
The idea is to keep refreshing a string instead the entire console window. The object type StringBuilder allows me to refresh that specific string (by using the Append() method) in the Console for the specific line where that string was printed. That works like a charm in the code below:
// Backtrack to the first differing character
StringBuilder outputBuilder = new StringBuilder();
outputBuilder.Append('\b', currentText.Length - commonPrefixLength);
// Output new suffix
outputBuilder.Append(text.Substring(commonPrefixLength));
// If the new text is shorter than the old one: delete overlapping characters
int overlapCount = currentText.Length - text.Length;
if (overlapCount > 0) {
outputBuilder.Append(' ', overlapCount);
outputBuilder.Append('\b', overlapCount);
}
Console.Write(outputBuilder);
currentText = text;
I hope that explains better the reason for the change. I am not a native english speaker since I am a Brazilian. But let me know in case you still need more details on that and I will be pleased to interact.
Best regards,
Alex.
Oh, by the way, I have tried to use the Konsole with the "outputBuilder" variable converted using .ToString() but the results are not the same as it does in the normal Console class. So the Konsole.Write should accept the type StringBuilder so I could try it.
Hi Agbarbosa
... Eita!
Unfortunately it's still not clear from your example what code will do? Please explain as follows ...
If I do this ...
// same code goes here
Then I expect the following output
line 1...
line 2...
line 3...
instead of
line 1...
line 1...
line 1...
Insert a suitable example that explains what you want the code to do. Pretend this was a unit test, what would the simplest test be, that can both verify the behavior works as expected, and also service as documentation that describes how to use the feature?
The code sample you provided does not show what you expect to see at the end of the code.
If you can't answers these questions very simply and provide simple sample code, then perhaps speak to a colleague and friend first before replying further to this thread?
Remember, I don't use the pattern or library that you might be referring to. So you have to explain it very simply.
Here is a good article to read that will help you write a clean example; : https://stackoverflow.com/help/minimal-reproducible-example
Please read through the stack overflow notes before replying again.
good luck
regards
Alan
have you tried using the HighSpeedWriter which supports writing to a buffer of a portion of a screen? You ca make multiple updates "writes" and then call .Flush()
to only render the portion of window that the writer covers.
see here : https://github.com/goblinfactory/konsole#highspeedwriter-end-to-end-sample
Hi @goblinfactory, I am gonna try how to implement the HighSpeedWriter. As for the sugestion of change I made in this topic, you can ignore it for now since I could use the ProgressBar class Konsole already has in the way I wanted, which would be my main reason for this. Anyways, CONGRATULATIONS for the great work you've done here! And thanks for your attention on this matter.
:) Glad you like it. Just be aware that if you're using progress bar, that Goblinfactory.Konsole is currently not cross platform, despite being .net core. if you want a cross platform progress bar, or, if that's the only part of Konsole you're using you can also use https://github.com/goblinfactory/progress-bar
cheers, Alan
Is there a possibility to create the IWrite.Write method overload to also get a a StringBuilder type as parameter and act as the same when it receives the String one? The main reason for that is to implement a dynamic string output for a specific line without having to move the cursor back to that line.