Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

Feature underline

Open jmperricone opened this issue 4 years ago • 12 comments

UNDERLINE

jmperricone avatar Apr 30 '21 00:04 jmperricone

It works with WindowsDriver, CursesDriver and NetDriver(windows).

The only thing that seems off to me is that I did not make Attribute.Value contain this value as well.

If someone is using this value assuming it only have color, it would be very bad.

NetDriver sets the biggest number.

value = ((((int) f) & 0xffff) << 16) | (((int) b) & 0xffff)

with ConsoleColor.White = 15

value == 0xF000F

using something like 0x100000 for underline would be possible if I'm not wrong.

Tell me what you think. I set this as a draft.

jmperricone avatar Apr 30 '21 01:04 jmperricone

Good work. Any day we will have the #48 RGB working :-) You can play with that limit values, you'll see very interesting. You can achieve a greater colors values. Only it'll need to change the default for each of ColorScheme. Otherwise you'll have identical colors. It's possible to underline only words too?

BDisp avatar Apr 30 '21 08:04 BDisp

Yes you, can underline words, like you change the color of a word.

I just realized that it will only work for windows, when using the netdriver.

jmperricone avatar Apr 30 '21 14:04 jmperricone

I am pleased for my CSI (Code Sequence Introducer) implementation on the NetDriver. Too bad it's too slow on Windows.

BDisp avatar Apr 30 '21 15:04 BDisp

I just realized that it will only work for windows, when using the netdriver. (@jmperricone)

Now that I read this, it seems to me that it is not clear.

It works with CursesDriver and the WindowsDriver.

What I meant is that with the NetDriver, it only works on Windows. This is what I did:

void SetUnderline (bool state)
{
	redrawUnderline = state;
	if (IsWinPlatform == true) {
		var OutputHandle = NetWinVTConsole.GetStdHandle (NetWinVTConsole.STD_OUTPUT_HANDLE);
		var success = NetWinVTConsole.GetConsoleScreenBufferInfo (OutputHandle, out var csbi);
		if (success) {
			if (state == true) {
				csbi.wAttributes |= 0x8000;
			} else {
				csbi.wAttributes &= 0x7FFF;
			}
			NetWinVTConsole.SetConsoleTextAttribute (OutputHandle, csbi.wAttributes);
		}
	}
}

jmperricone avatar Nov 20 '21 03:11 jmperricone

What I meant is that with the NetDriver, it only works on Windows.

You don't need to use Windows API to work on Windows. The only reason I use Windows API was because the System.Console don't recognize escape sequences on Windows and I needed to use ENABLE_VIRTUAL_TERMINAL_PROCESSING for that. To do that, you need to use escape sequences "\x1B[4m" to underline and "\x1B[24m" to reset, maintaining any colors set, both valid to Windows and Linux.

BDisp avatar Nov 20 '21 19:11 BDisp

But is better to add the underline bitwise to the contents attribute than increase the contents length to save the underline.

BDisp avatar Nov 20 '21 22:11 BDisp

@jmperricone, when you have the time please check my PR https://github.com/jmperricone/gui.cs/pull/1, please. Thanks.

BDisp avatar Nov 21 '21 11:11 BDisp

Hi, thanks for the pull #1 @BDisp

About the bitwise underline, I thought about that:

If someone is using this value assuming it only have color, it would be very bad. https://github.com/migueldeicaza/gui.cs/pull/1275#issuecomment-829734583

Because Driver.GetAttribute() is

public override Attribute GetAttribute ()
{
	return currentAttribute;
}
...
public static implicit operator Attribute (int v) => new Attribute (v);
...

Then Attribute.Value contains that

If that is not a problem, is ok!

jmperricone avatar Nov 21 '21 21:11 jmperricone

If that is not a problem, is ok!

It's okay because if Attribute.Underline is true it's possible to extract from the value.

BDisp avatar Nov 21 '21 22:11 BDisp

Should be that added to the Attribute.Value Property Get(). For example if someone have code like:

if (attr.Value > 100) {
   ...
}

Having Underline set, will always return true.

jmperricone avatar Nov 21 '21 22:11 jmperricone

Having Underline set, will always return true.

Is true, but the user may check if Underline property is true and so the value isn't only colors, taking the desired action. But, normally, the user may take the colors by checking in the Background and Foreground colors.

BDisp avatar Nov 21 '21 22:11 BDisp

We need to create an Issue for this set to point to the v2 Project (https://github.com/orgs/gui-cs/projects/1) and retarget this PR at the v2_develop branch.

tig avatar Mar 03 '23 22:03 tig

This work should be merged into #2612. Closing.

tig avatar Jul 25 '23 15:07 tig