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

Retain the color of a character for underline and bar cursor styles #781

Merged
merged 2 commits into from
Aug 3, 2017
Merged

Retain the color of a character for underline and bar cursor styles #781

merged 2 commits into from
Aug 3, 2017

Conversation

mofux
Copy link
Contributor

@mofux mofux commented Jul 11, 2017

Fixes #774
Fixes #789
Fixes #790
Fixes #820
Related #783

⚠️ Warning
I had to change the cursor related css to get this feature in, and to resolve styling related issues. Consumers that have overwritten the default styles may have to adopt their stylesheet.

🚀 Improvements
The.terminal element will always have a class with the cursor style, previously, only bar and underline cursors had a class.

🐞 Fixes

🎮 Testing
I found it very useful to nvim README.md in the xterm.js demo because the Markdown syntax highlighter of nvim will create almost all visual test cases (background, foreground, underline, bold).

@coveralls
Copy link

coveralls commented Jul 11, 2017

Coverage Status

Coverage decreased (-0.06%) to 69.388% when pulling 0d570cd on mofux:cursor_color into 86c5aa0 on sourcelair:master.

@Tyriar
Copy link
Member

Tyriar commented Jul 11, 2017

@mofux we don't want to use the same color when it's a block cursor, instead we want to use the terminal's background color. Is this case covered by this?

@mofux
Copy link
Contributor Author

mofux commented Jul 11, 2017

@Tyriar I think you mean we want the foreground color, not the background color? Yes, the css rule takes precedence.

@coveralls
Copy link

coveralls commented Jul 11, 2017

Coverage Status

Coverage decreased (-0.06%) to 69.388% when pulling 7869440 on mofux:cursor_color into 86c5aa0 on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Jul 11, 2017

I've just stumbled over a couple of issues while testing:

  1. In the unfocused state, the block outline is always drawn, no matter which cursor style is selected. What should be the preferred look of the those cursor styles in the unfocused state?

  2. The line and underline cursors also need the background color, otherwise there will be a black square whenever the cursor is over a background (fix is on the way)

  3. When I open midnight command mc or nvim and perform a click, the focus class on the terminal is removed for some reason. It only comes back after I close the app. I believe this happens if the program supports mouse pointer integration. I'll try to investigate...

@coveralls
Copy link

coveralls commented Jul 11, 2017

Coverage Status

Coverage decreased (-0.1%) to 69.333% when pulling 7b5bd20 on mofux:cursor_color into 86c5aa0 on sourcelair:master.

@Tyriar
Copy link
Member

Tyriar commented Jul 11, 2017

@mofux

  1. Yeah I knew about this but I don't think there is an issue for it. gnome-terminal just shows the line/underline solid when unfocused, Terminal.app acts as it is now. I think aligning with gnome-terminal here is ideal. Created Line and underline terminal cursors show as a block when unfocused #783
  2. 👍
  3. Does it affect the cursor though? Most styles are applied to :focus and .focus

@mofux
Copy link
Contributor Author

mofux commented Jul 12, 2017

This PR is ready for review. Please see the PR description for updated details.

@coveralls
Copy link

coveralls commented Jul 12, 2017

Coverage Status

Coverage decreased (-0.2%) to 69.263% when pulling 8043c11 on mofux:cursor_color into 01453e9 on sourcelair:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 68.682% when pulling 2db0ac8 on mofux:cursor_color into 01453e9 on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Jul 13, 2017

@Tyriar I can see this running into conflicts with #756. I propose to hold this back until #756 is merged. Once it's in I'll update this PR.

If you want, you could already include the changes made here (804051e) into #756, which should solve #774.

@Tyriar
Copy link
Member

Tyriar commented Jul 13, 2017

@mofux fill hopefully get to this in the next couple of days, sorry about the delay

@coveralls
Copy link

coveralls commented Jul 13, 2017

Coverage Status

Coverage decreased (-0.2%) to 69.37% when pulling 0a3b221 on mofux:cursor_color into 25fc01c on sourcelair:master.

@coveralls
Copy link

coveralls commented Jul 14, 2017

Coverage Status

Coverage decreased (-0.2%) to 69.292% when pulling 855f73a on mofux:cursor_color into c94fdae on sourcelair:master.

src/Renderer.ts Outdated
currentElement.classList.add('reverse-video');
currentElement.classList.add('terminal-cursor');
if (cursorFg >= 0 && cursorFg < 256) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually want to do more here as well, bold, underline, invisible (maybe?). Perhaps the cursor part should try share more code with the regular part?

Some things don't make sense here: blink, inverse

And some things need to be done differently: bg/fg application

src/Renderer.ts Outdated
const ch = line[i][1];
const ch_width: any = line[i][2];
if (!ch_width) {
continue;
}

if (i === x) {
cursorData = [data & 0x1ff, (data >> 9) & 0x1ff];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the topic of sharing code, it would be good to reuse this line:

let bg
let fg = (data >> 9) & 0x1ff;

src/Renderer.ts Outdated
@@ -168,13 +168,15 @@ export class Renderer {
for (let i = 0; i < width; i++) {
// TODO: Could data be a more specific type?
let data: any = line[i][0];
let cursorData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should go outside the look and instead be let isCursor = false;

src/xterm.js Outdated
@@ -1044,6 +1045,9 @@ Terminal.prototype.bindMouse = function() {
}

on(el, 'mousedown', function(ev) {
// prevent the focus on the textarea from getting lost
ev.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might need to go after the self.mouseEvents check? Can you verify by running tmux, vim, etc. in mouse mode and see if they get the events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to have it at the start, because we will want to prevent the focus of the textarea from being lost in either case. I have tested it in nvim and mc and it works as expected. I've also made sure it doesn't cause a regression for the selection manager and linkifier.

Copy link
Contributor Author

@mofux mofux Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can and should be removed once #828 is merged, because #828 adds a focus() at the top of the handler.

Update
No, it is still required. Sorry for the hassle.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-0.02%) to 70.375% when pulling e5158ad on mofux:cursor_color into 2e9177a on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Jul 25, 2017

@Tyriar I have merged the rendering of the cursor with the existing logic, which avoids code duplication and allows for all flags to be applied to the cursor (with the exception of xterm-hidden which I believe is something we don't want for the cursor).

I have also fixed #820 on the way.

Check the updated PR head notes for running some tests (using nvim).

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-0.03%) to 70.375% when pulling 51bed8e on mofux:cursor_color into f36bd24 on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Jul 25, 2017

This is ready for re-review 😁. The diff for Renderer.ts is a little confusing because I have removed a nested if, so the whole inner block has shifted one indentation to the left now.

Copy link
Contributor

@parisk parisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @mofux 😄!

In what manner does this fix #783? This issue is closed now, as we decided to keep the current behavior.

@mofux
Copy link
Contributor Author

mofux commented Jul 26, 2017

@parisk It respects the decisions made in #783 - which means showing an outlined block cursor in the unfocused state, no matter what cursor style is currently active (basically the same behaviour as we had before). When I first started this PR it seemed that #783 would go into the direction of showing the selected cursor in unfocused state.

See commit e5158ad for details.

@Tyriar
Copy link
Member

Tyriar commented Jul 31, 2017

Sorry haven't had time to get to this yet. I've been swamped with other tasks plus I was pretty ill all last week 🙁

@parisk
Copy link
Contributor

parisk commented Aug 2, 2017

@mofux can you please rebase with master? It would be great to include this in 2.9.0 😄.

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage decreased (-0.03%) to 70.442% when pulling 164f785 on mofux:cursor_color into bcff69b on sourcelair:master.

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage decreased (-0.03%) to 70.442% when pulling 469d167 on mofux:cursor_color into bcff69b on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Aug 2, 2017

@parisk I have just rebased the branch 😅

Copy link
Contributor

@parisk parisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine for me and code looks good as well.

I think this is OK to merge now.

Let's wait a few hours for @Tyriar to take a look as well, as he was the main reviewer of this PR, or else I plan to merge this for the 2.9.0 release.

Great job 👍. Thanks!

@parisk parisk added this to the 2.9.0 milestone Aug 2, 2017
@mofux
Copy link
Contributor Author

mofux commented Aug 2, 2017

@parisk I have removed the ev.preventDefault() in the mousedown handler - which has fixed #789, because it should now be handled by your #828 PR.

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage decreased (-0.01%) to 70.456% when pulling 4ed0a9b on mofux:cursor_color into bcff69b on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Aug 2, 2017

Sorry, I was wrong, just tested with your changes from #828 and ev.preventDefault() is still required to prevent the focus from getting lost when in mouse interactive mode. I have put it back now.

Prevent focus from getting lost when in vt mouse mode
Fix: cursor style not applied on init, set a class for block cursor
Make all cursors work under all conditions (focused, unfocused, blink)
Unify cursor rendering with normal rendering code
Make sure underline AND blink can be used in co-existence
Always show outlined block cursor in unfocused state
@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage decreased (-0.03%) to 70.442% when pulling 30a9068 on mofux:cursor_color into bcff69b on sourcelair:master.

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage decreased (-0.03%) to 70.442% when pulling 5bc0ad8 on mofux:cursor_color into bcff69b on sourcelair:master.

@mofux
Copy link
Contributor Author

mofux commented Aug 2, 2017

I have updated this PR to resolve the merge conflict from #828. Ready for merge if @Tyriar has no objections 😊

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage decreased (-0.03%) to 70.497% when pulling 106eda7 on mofux:cursor_color into f134559 on sourcelair:master.

@Tyriar Tyriar modified the milestones: 2.9.0, 3.0.0 Aug 3, 2017
@Tyriar Tyriar merged commit 0079677 into xtermjs:master Aug 3, 2017
@mofux mofux deleted the cursor_color branch August 3, 2017 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants