25 lines
640 B
Python
Executable file
25 lines
640 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import sys
|
|
|
|
line_n = int(sys.argv[1])
|
|
col = int(sys.argv[2])
|
|
width = int(sys.argv[3])
|
|
count = int(sys.argv[4])
|
|
path = sys.argv[5]
|
|
direction = sys.argv[6]
|
|
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]
|