From 0910844896475418dc28ebfd2d3bae43528d5b26 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sat, 4 Jul 2020 01:15:14 -0700 Subject: [PATCH] Invert selected text instead of highlighting Highlighting text in the terminal often makes it hard to read, which can be problematic for users who want to adjust or review selections before copying them. For example, the default theme makes white and green text hard to read on its light gray selection background, and there are plenty of other themes where the choice of text and cursor colors would hinder selection readability. To fix this issue and make selected text more legible in nearly all combinations of colors, invert selected text instead of highlighting it. This is more common among terminal emulators anyway: Invert: xterm, fbcon, kitty, Konsole, Alacritty, Tilix, gnome-terminal (7) Highlight: Termux, Terminal.app, iTerm2, Windows Terminal (4) --- .../main/java/com/termux/view/TerminalRenderer.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/terminal-view/src/main/java/com/termux/view/TerminalRenderer.java b/terminal-view/src/main/java/com/termux/view/TerminalRenderer.java index 7a182441..92df53f8 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalRenderer.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalRenderer.java @@ -117,11 +117,10 @@ public final class TerminalRenderer { } else { final int columnWidthSinceLastRun = column - lastRunStartColumn; final int charsSinceLastRun = currentCharIndex - lastRunStartIndex; - int cursorColor = (lastRunInsideCursor || lastRunInsideSelection) ? mEmulator.mColors.mCurrentColors[TextStyle.COLOR_INDEX_CURSOR] : 0; - int cursorStyle = lastRunInsideSelection ? TerminalEmulator.CURSOR_STYLE_BLOCK : cursorShape; + int cursorColor = lastRunInsideCursor ? mEmulator.mColors.mCurrentColors[TextStyle.COLOR_INDEX_CURSOR] : 0; drawTextRun(canvas, line, palette, heightOffset, lastRunStartColumn, columnWidthSinceLastRun, lastRunStartIndex, charsSinceLastRun, measuredWidthForRun, - cursorColor, cursorStyle, lastRunStyle, reverseVideo); + cursorColor, cursorShape, lastRunStyle, reverseVideo || lastRunInsideSelection); } measuredWidthForRun = 0.f; lastRunStyle = style; @@ -143,10 +142,9 @@ public final class TerminalRenderer { final int columnWidthSinceLastRun = columns - lastRunStartColumn; final int charsSinceLastRun = currentCharIndex - lastRunStartIndex; - int cursorColor = (lastRunInsideCursor || lastRunInsideSelection) ? mEmulator.mColors.mCurrentColors[TextStyle.COLOR_INDEX_CURSOR] : 0; - int cursorStyle = lastRunInsideSelection ? TerminalEmulator.CURSOR_STYLE_BLOCK : cursorShape; + int cursorColor = lastRunInsideCursor ? mEmulator.mColors.mCurrentColors[TextStyle.COLOR_INDEX_CURSOR] : 0; drawTextRun(canvas, line, palette, heightOffset, lastRunStartColumn, columnWidthSinceLastRun, lastRunStartIndex, charsSinceLastRun, - measuredWidthForRun, cursorColor, cursorStyle, lastRunStyle, reverseVideo); + measuredWidthForRun, cursorColor, cursorShape, lastRunStyle, reverseVideo || lastRunInsideSelection); } }