GithubHelp home page GithubHelp logo

Comments (9)

goblinfactory avatar goblinfactory commented on June 9, 2024

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

from konsole.

agbarbosa avatar agbarbosa commented on June 9, 2024

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.

from konsole.

goblinfactory avatar goblinfactory commented on June 9, 2024

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

from konsole.

agbarbosa avatar agbarbosa commented on June 9, 2024

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.

from konsole.

agbarbosa avatar agbarbosa commented on June 9, 2024

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.

from konsole.

goblinfactory avatar goblinfactory commented on June 9, 2024

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.

  1. What is "currentText" - What does the sample code you provide do to current Text?
  2. What does the code currently do, and what do you WANT it to do?
  3. If Goblinfactory.Konsole were to support the feature you are describing, what would the code look like?

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

from konsole.

goblinfactory avatar goblinfactory commented on June 9, 2024

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

from konsole.

agbarbosa avatar agbarbosa commented on June 9, 2024

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.

from konsole.

goblinfactory avatar goblinfactory commented on June 9, 2024

:)
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

from konsole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.