Skip to content

Commit ee8d8e4

Browse files
committed
feat: make hint color configurable
1 parent a616a7f commit ee8d8e4

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Available environment variables(default values):
2727
# Keys used for hints
2828
TMUX_EASYMOTION_KEYS="asdfghjkl;"
2929

30+
# Hint colors
31+
TMUX_EASYMOTION_HINT1_FG="\033[1;31m"
32+
TMUX_EASYMOTION_HINT2_FG="\033[1;32m"
33+
3034
# Border characters
3135
TMUX_EASYMOTION_VERTICAL_BORDER=""
3236
TMUX_EASYMOTION_HORIZONTAL_BORDER=""

easymotion.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
from itertools import islice
1313
from typing import List, Optional
1414

15+
# ANSI escape sequences
16+
ESC = '\033'
17+
CLEAR = f'{ESC}[2J'
18+
CLEAR_LINE = f'{ESC}[2K'
19+
HIDE_CURSOR = f'{ESC}[?25l'
20+
SHOW_CURSOR = f'{ESC}[?25h'
21+
RESET = f'{ESC}[0m'
22+
DIM = f'{ESC}[2m'
23+
24+
# Configuration from environment
25+
KEYS = os.environ.get('TMUX_EASYMOTION_KEYS', 'asdfghjkl;')
26+
VERTICAL_BORDER = os.environ.get('TMUX_EASYMOTION_VERTICAL_BORDER', '│')
27+
HORIZONTAL_BORDER = os.environ.get('TMUX_EASYMOTION_HORIZONTAL_BORDER', '─')
28+
HINT1_FG = os.environ.get('TMUX_EASYMOTION_HINT1_FG', f'{ESC}[1;31m')
29+
HINT2_FG = os.environ.get('TMUX_EASYMOTION_HINT2_FG', f'{ESC}[1;32m')
1530

1631
def perf_timer(func_name=None):
1732
"""Performance timing decorator that only logs when TMUX_EASYMOTION_PERF is true"""
@@ -41,31 +56,14 @@ def setup_logging():
4156
logging.getLogger().disabled = True
4257
return
4358

44-
log_file = os.path.expanduser( '~/easymotion.log')
59+
log_file = os.path.expanduser('~/easymotion.log')
4560
logging.basicConfig(
4661
filename=log_file,
4762
level=logging.DEBUG,
4863
format='%(asctime)s - %(levelname)s - %(message)s'
4964
)
5065

5166

52-
# ANSI escape sequences
53-
ESC = '\033'
54-
CLEAR = f'{ESC}[2J'
55-
CLEAR_LINE = f'{ESC}[2K'
56-
HIDE_CURSOR = f'{ESC}[?25l'
57-
SHOW_CURSOR = f'{ESC}[?25h'
58-
RESET = f'{ESC}[0m'
59-
RED_FG = f'{ESC}[31m'
60-
GREEN_FG = f'{ESC}[32m'
61-
DIM = f'{ESC}[2m'
62-
63-
# Configuration from environment
64-
KEYS = os.environ.get('TMUX_EASYMOTION_KEYS', 'asdfghjkl;')
65-
VERTICAL_BORDER = os.environ.get('TMUX_EASYMOTION_VERTICAL_BORDER', '│')
66-
HORIZONTAL_BORDER = os.environ.get('TMUX_EASYMOTION_HORIZONTAL_BORDER', '─')
67-
68-
6967
@functools.lru_cache(maxsize=1024)
7068
def get_char_width(char: str) -> int:
7169
"""Get visual width of a single character with caching"""
@@ -222,6 +220,7 @@ def to_terminal_coords(y: int, x: int) -> tuple[int, int]:
222220
"""
223221
return y + 1, x + 1
224222

223+
225224
def getch():
226225
"""Get a single character from terminal"""
227226
fd = sys.stdin.fileno()
@@ -361,14 +360,17 @@ def draw_all_panes(panes, max_x, padding_cache, terminal_height):
361360
# draw vertical borders
362361
if pane.start_x + pane.width < max_x:
363362
for y in range(pane.start_y, pane.start_y + visible_height):
364-
term_y, term_x = to_terminal_coords(y, pane.start_x + pane.width)
365-
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{DIM}{VERTICAL_BORDER}{RESET}')
363+
term_y, term_x = to_terminal_coords(
364+
y, pane.start_x + pane.width)
365+
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{
366+
DIM}{VERTICAL_BORDER}{RESET}')
366367

367368
# draw horizontal borders for non-last pane
368369
end_y = pane.start_y + visible_height
369370
if end_y < terminal_height and pane != sorted_panes[-1]:
370371
term_y, term_x = to_terminal_coords(end_y, pane.start_x)
371-
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{DIM}{HORIZONTAL_BORDER * pane.width}{RESET}')
372+
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{DIM}{
373+
HORIZONTAL_BORDER * pane.width}{RESET}')
372374

373375
sys.stdout.flush()
374376

@@ -403,11 +405,13 @@ def draw_all_hints(panes, terminal_height):
403405
x = pane.start_x + col
404406
if (y < min(pane.start_y + pane.height, terminal_height) and x + get_char_width(char) <= pane.start_x + pane.width):
405407
term_y, term_x = to_terminal_coords(y, x)
406-
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{RED_FG}{hint[0]}{RESET}')
408+
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{
409+
HINT1_FG}{hint[0]}{RESET}')
407410
char_width = get_char_width(char)
408411
if x + char_width < pane.start_x + pane.width:
409412
term_y, term_x = to_terminal_coords(y, x + char_width)
410-
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{GREEN_FG}{hint[1]}{RESET}')
413+
sys.stdout.write(f'{ESC}[{term_y};{term_x}H{
414+
HINT2_FG}{hint[1]}{RESET}')
411415
sys.stdout.flush()
412416

413417

@@ -448,10 +452,12 @@ def main():
448452
char_width = get_char_width(char)
449453
if (y < min(pane.start_y + pane.height, terminal_height) and x + char_width <= pane.start_x + pane.width):
450454
# Clear first position and show second character
451-
sys.stdout.write(f'{ESC}[{y + 1};{x + 1}H{GREEN_FG}{hint[1]}{RESET}')
455+
sys.stdout.write(
456+
f'{ESC}[{y + 1};{x + 1}H{HINT2_FG}{hint[1]}{RESET}')
452457
# Restore original character in second position (if there's space)
453458
if x + char_width + 1 < pane.start_x + pane.width:
454-
sys.stdout.write(f'{ESC}[{y + 1};{x + char_width + 1}H{char}')
459+
sys.stdout.write(
460+
f'{ESC}[{y + 1};{x + char_width + 1}H{char}')
455461
sys.stdout.flush()
456462

457463
# Handle second character selection

0 commit comments

Comments
 (0)