-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
@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? |
@Tyriar I think you mean we want the foreground color, not the background color? Yes, the css rule takes precedence. |
I've just stumbled over a couple of issues while testing:
|
|
This PR is ready for review. Please see the PR description for updated details. |
@mofux fill hopefully get to this in the next couple of days, sorry about the delay |
src/Renderer.ts
Outdated
currentElement.classList.add('reverse-video'); | ||
currentElement.classList.add('terminal-cursor'); | ||
if (cursorFg >= 0 && cursorFg < 256) { |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 I have also fixed #820 on the way. Check the updated PR head notes for running some tests (using nvim). |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
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 🙁 |
@mofux can you please rebase with master? It would be great to include this in 2.9.0 😄. |
@parisk I have just rebased the branch 😅 |
There was a problem hiding this 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!
Sorry, I was wrong, just tested with your changes from #828 and |
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
Fixes #774
Fixes #789
Fixes #790
Fixes #820
Related #783
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, onlybar
andunderline
cursors had a class.🐞 Fixes
bar
andunderline
cursors now render correctly and do not alter the foreground color of the text,blink
is now working correctly if the block cursor is over a background,focus
class is kept when interacting with programs that support mouse pointer integration🎮 Testing
I found it very useful to
nvim README.md
in the xterm.js demo because the Markdown syntax highlighter ofnvim
will create almost all visual test cases (background, foreground, underline, bold).