-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattach.py
68 lines (55 loc) · 1.45 KB
/
attach.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import argparse
import time
import pynvim
from pynvim import attach
class ArrowGuy:
UP = "^"
DOWN = "v"
LEFT = "<"
RIGHT = ">"
MOVES = {
UP: (-1, 0),
DOWN: (1, 0),
LEFT: (0, -1),
RIGHT: (0, 1),
}
def __init__(self, nvim):
self.nvim = nvim
def get_pos(self):
return self.nvim.current.window.cursor
def get_char(self):
_, column = self.get_pos()
return self.nvim.current.line[column]
def move_cursor(self, direction):
line, col = self.get_pos()
l, c = direction
line += l
col += c
self.nvim.current.window.cursor = [line, col]
def read_direction(self):
c = self.get_char()
return self.MOVES[c]
def move(self):
while True:
try:
direction = self.read_direction()
self.move_cursor(direction)
time.sleep(0.3)
except KeyError:
continue
except (
pynvim.api.common.NvimError,
IndexError,
EOFError,
KeyboardInterrupt,
):
break
def main(args):
nvim = attach("socket", path=args.socket)
fd = ArrowGuy(nvim)
fd.move()
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("-s", "--socket", required=True, help="Path to nvim socket")
args = ap.parse_args()
exit(main(args))