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

24bit fg/bg color is not implemented and I haz questions... #78

Open
tig opened this issue Apr 30, 2020 · 2 comments
Open

24bit fg/bg color is not implemented and I haz questions... #78

tig opened this issue Apr 30, 2020 · 2 comments
Labels
help wanted Extra attention is needed up-for-grabs Relatively simple, and could use a volunteer to take on it

Comments

@tig
Copy link

tig commented Apr 30, 2020

https://github.com/migueldeicaza/XtermSharp/blob/master/XtermSharp/Terminal.cs#L683

		public int MatchColor (int r1, int g1, int b1)
		{
			throw new NotImplementedException ();
		}

The code in InputHandler.cs looks right:

				} else if (p == 38) {
					// fg color 256
					if (pars [i + 1] == 2) {
						i += 2;
						fg = terminal.MatchColor (
							pars [i] & 0xff,
							pars [i + 1] & 0xff,
							pars [i + 2] & 0xff);
						if (fg == -1)
							fg = 0x1ff;
						i += 2;
					} else if (pars [i + 1] == 5) {
						i += 2;
						p = pars [i] & 0xff;
						fg = p;
					}
				} else if (p == 48) {

But without MatchColor implemented, 24bit color is not implemented. The spec is:

ESC[ 38;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB foreground color
ESC[ 48;2;⟨r⟩;⟨g⟩;⟨b⟩ m Select RGB background color

I tried a naïve try:

	public int MatchColor (int r1, int g1, int b1)
	{
            return (int)System.Drawing.Color.FromArgb(r1,g1, b1).ToArgb();
	}

I obviously don't know what I'm doing because this always returns 255 even though in the debugger I see my values for r1, g1, and b1 being passed in.

What is the value of the the int fg and int bg supposed to hold?

I built this too to help:

        public class XtermCharAttribute {
            public int Attribute { get; set; }

            public static XtermCharAttribute FromAttribute(int attribute) {
                return new XtermCharAttribute(attribute);
            }

            public XtermCharAttribute(int attribute) {
                Attribute = attribute;
            }

            public bool Bold => ((FLAGS)(Attribute >> 18)).HasFlag(FLAGS.BOLD);
            public bool Italic => ((FLAGS)(Attribute >> 18)).HasFlag(FLAGS.ITALIC);
            public bool Underline => ((FLAGS)(Attribute >> 18)).HasFlag(FLAGS.UNDERLINE);

            public System.Drawing.Color FgColor => System.Drawing.Color.FromArgb((Attribute >> 9) & 0x1ff);
            public System.Drawing.Color BgColor => System.Drawing.Color.FromArgb(Attribute & 0x1ff);
        }

What am I doing wrong/missing?

@migueldeicaza
Copy link
Owner

I recently implemented this in SwiftTerm - the good news is that you don’t need the MatchColor, that whole chunk of code is wrong.

Greg who used to be on the VSMac team was merging the improvements I was doing on SwiftTerm regularly until he moved on to another project.

@migueldeicaza
Copy link
Owner

This is the commit that got true color support to SwiftTerm:

migueldeicaza/SwiftTerm#57

@migueldeicaza migueldeicaza added help wanted Extra attention is needed up-for-grabs Relatively simple, and could use a volunteer to take on it labels Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed up-for-grabs Relatively simple, and could use a volunteer to take on it
Projects
None yet
Development

No branches or pull requests

2 participants