Skip to content

Instantly share code, notes, and snippets.

@xinhaoyuan
Last active November 22, 2016 16:27
Show Gist options
  • Save xinhaoyuan/faf304ca746cc91c96f05c953fe61e98 to your computer and use it in GitHub Desktop.
Save xinhaoyuan/faf304ca746cc91c96f05c953fe61e98 to your computer and use it in GitHub Desktop.
Highlighting the background of even lines when control + alt is pressed. Handy for aligning lines.
diff -ru mintty-2.7.0/src/term.h mintty-2.7.0-modified/src/term.h
--- mintty-2.7.0/src/term.h 2016-11-11 08:27:15.000000000 -0500
+++ mintty-2.7.0-modified/src/term.h 2016-11-22 00:01:05.582947600 -0500
@@ -462,6 +462,9 @@
termresults results;
termimgs imgs;
+
+ bool even_line_highlight_mode;
+ bool even_line_highlight_toggle;
};
extern struct term term;
diff -ru mintty-2.7.0/src/wininput.c mintty-2.7.0-modified/src/wininput.c
--- mintty-2.7.0/src/wininput.c 2016-11-11 10:55:24.000000000 -0500
+++ mintty-2.7.0-modified/src/wininput.c 2016-11-22 11:24:32.753498100 -0500
@@ -397,6 +397,14 @@
#define trace_key(tag)
#endif
+void
+term_set_even_line_highlight_toggle(bool toggle)
+{
+ term.even_line_highlight_toggle = toggle;
+ term_invalidate(0, 0, term.cols - 1, term.rows - 1);
+ win_schedule_update();
+}
+
bool
win_key_down(WPARAM wp, LPARAM lp)
{
@@ -451,6 +459,15 @@
bool ctrl_lalt_altgr = cfg.ctrl_alt_is_altgr & ctrl & lalt & !ralt;
bool altgr = ralt | ctrl_lalt_altgr;
+ if (!term.even_line_highlight_mode) {
+ if ((alt && ctrl) && !term.even_line_highlight_toggle) {
+ term_set_even_line_highlight_toggle(true);
+ }
+ if (!(alt && ctrl) && term.even_line_highlight_toggle) {
+ term_set_even_line_highlight_toggle(false);
+ }
+ }
+
mod_keys mods = shift * MDK_SHIFT | alt * MDK_ALT | ctrl * MDK_CTRL;
update_mouse(mods);
@@ -1186,6 +1203,17 @@
#ifdef debug_virtual_key_codes
printf(" win_key_up %04X %s\n", key, vk_name(key));
#endif
+ inline bool is_key_down(uchar vk) { return GetKeyState(vk) & 0x80; }
+ if (key == VK_MENU || key == VK_CONTROL || key == VK_SHIFT) {
+ bool alt = is_key_down(VK_LMENU) || is_key_down(VK_RMENU);
+ bool ctrl = is_key_down(VK_LCONTROL) || is_key_down(VK_RCONTROL);
+ if (key == VK_SHIFT && alt && ctrl) {
+ term.even_line_highlight_mode = !term.even_line_highlight_mode;
+ }
+ if (!(alt && ctrl) && !term.even_line_highlight_mode && term.even_line_highlight_toggle) {
+ term_set_even_line_highlight_toggle(false);
+ }
+ }
win_update_mouse();
@@ -1200,7 +1228,6 @@
if (alt_F2_pending) {
if ((uint)wp == VK_F2) {
- inline bool is_key_down(uchar vk) { return GetKeyState(vk) & 0x80; }
if (is_key_down(VK_SHIFT))
alt_F2_shifted = true;
if (alt_F2_shifted)
diff -ru mintty-2.7.0/src/wintext.c mintty-2.7.0-modified/src/wintext.c
--- mintty-2.7.0/src/wintext.c 2016-11-07 11:27:38.000000000 -0500
+++ mintty-2.7.0-modified/src/wintext.c 2016-11-22 11:25:17.413264300 -0500
@@ -884,6 +884,7 @@
void
win_text(int x, int y, wchar *text, int len, cattr attr, int lattr, bool has_rtl)
{
+ bool even_line = y % 2;
trace_line("win_text:", text, len);
lattr &= LATTR_MODE;
int char_width = cell_width * (1 + (lattr != LATTR_NORM));
@@ -982,6 +983,16 @@
colour fg = fgi >= TRUE_COLOUR ? attr.truefg : colours[fgi];
colour bg = bgi >= TRUE_COLOUR ? attr.truebg : colours[bgi];
+#define EVEN_DELTA 7
+ if (even_line && (term.even_line_highlight_mode || term.even_line_highlight_toggle)) {
+ int r = red(bg), g = green(bg), b = blue(bg);
+ bg = make_colour(
+ r < 128 ? (r + EVEN_DELTA) : (r - EVEN_DELTA),
+ g < 128 ? (g + EVEN_DELTA) : (g - EVEN_DELTA),
+ b < 128 ? (b + EVEN_DELTA) : (b - EVEN_DELTA)
+ );
+ }
+
if (attr.attr & ATTR_DIM) {
fg = (fg & 0xFEFEFEFE) >> 1; // Halve the brightness.
if (!cfg.bold_as_colour || fgi >= 256)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment