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

Print on the Same Line Different Color #4

Open
natrajgs opened this issue Jul 8, 2019 · 4 comments
Open

Print on the Same Line Different Color #4

natrajgs opened this issue Jul 8, 2019 · 4 comments

Comments

@natrajgs
Copy link

natrajgs commented Jul 8, 2019

I am trying to print some characters in one color and rest of then in another color - but cannot
Console.Write is acting like Console.WriteLine i.e. adding an line break.

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write(FiggleFonts.Cards.Render($"{charArray[0]}{charArray[1]}{charArray[2]}"));
Console.ForegroundColor = ConsoleColor.White;
Console.Write(FiggleFonts.Cards.Render($"{charArray[3]}"));
@drewnoakes
Copy link
Owner

There are two kinds of lines at play here.

 _____ _         _     
|   __|_|___ ___| |___ 
|   __| | . | . | | -_|
|__|  |_|_  |_  |_|___|
        |___|___|   

In that example, you could say the first line is the word "Figgle". But actually, from the perspective of the console, that text is 5 different lines of text:

Line 1:  _____ _         _     
Line 2: |   __|_|___ ___| |___ 
Line 3: |   __| | . | . | | -_|
Line 4: |__|  |_|_  |_  |_|___|
Line 5:         |___|___|   

The Render method is returning a multi-line string (i.e. containing line endings). When you write it to the console, the cursor ends up at the bottom right corner of the text. If you try to write more text, it'll probably appear slightly broken and underneath the first thing you wrote.


Assuming I understand you correctly, you're asking for multi-colour printing support. Does that sound right? If so, then this is a feature request as it's not something that's currently supported.

@natrajgs
Copy link
Author

natrajgs commented Jul 8, 2019

Yes, that is what exactly I was looking for - please change to a feature request.

@ghost
Copy link

ghost commented Sep 8, 2020

Try like this.

var text = FiggleFonts.Standard.Render(message);
var result = Regex.Split(text, "\r\n|\r|\n");
var currentColor = Console.ForegroundColor;
var colors = new Queue<ConsoleColor>();

colors.Enqueue(ConsoleColor.Red);
colors.Enqueue(ConsoleColor.Green);
colors.Enqueue(ConsoleColor.Blue);

foreach (var line in result)
{
    var color = colors.Dequeue();

    Console.ForegroundColor = color;
    Console.WriteLine(line);

    colors.Enqueue(color);
}

Console.ForegroundColor = currentColor;

image

@drewnoakes
Copy link
Owner

I interpret the original request here as allowing individual characters to be printed in different colours. In the "Hello World!" example, the 'H' might be a different colour to the 'e'.

I suspect something like this would need to use control characters in the output to work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants