33 lines
890 B
Python
Executable file
33 lines
890 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import sys
|
|
# import subprocess
|
|
|
|
session_id = sys.argv[1]
|
|
line_n = int(sys.argv[2])
|
|
col = int(sys.argv[3])
|
|
width = int(sys.argv[4])
|
|
count = int(sys.argv[5])
|
|
path = sys.argv[6]
|
|
direction = sys.argv[7]
|
|
digits = len(str(count))
|
|
wrap_width = width - (digits + 3)
|
|
line = ""
|
|
with open(path, "r") as f:
|
|
for n, l in enumerate(f, start=1):
|
|
if n == line_n:
|
|
line = l
|
|
|
|
chunks = [line[i : i + wrap_width] for i in range(0, len(line), wrap_width)]
|
|
visual_row = col // wrap_width
|
|
visual_col = col % wrap_width
|
|
|
|
new_visual_row = visual_row + (-1 if direction == "up" else 1)
|
|
if 0 <= new_visual_row < len(chunks):
|
|
target_chunk = chunks[new_visual_row]
|
|
new_col = min(visual_col, len(target_chunk) - 1)
|
|
new_abs_col = new_visual_row * wrap_width + new_col
|
|
diff = abs(new_abs_col - col)
|
|
print(diff)
|
|
# _ = subprocess.run(args=["kak", "-c"])
|
|
|