Fix input box border rendering and layout math

This commit is contained in:
Dita Aji Pratama 2026-05-12 10:12:07 +07:00
parent 9c7e34409e
commit 18bbb07737

View File

@ -146,7 +146,6 @@ class HendrikTUI:
def _draw_input(self, stdscr): def _draw_input(self, stdscr):
iy = self.h - 4 iy = self.h - 4
blank = " " * (self.w - 2)
for off, text in [ for off, text in [
(0, "\u250c" + "\u2500" * (self.w - 2) + "\u2510"), (0, "\u250c" + "\u2500" * (self.w - 2) + "\u2510"),
@ -170,15 +169,20 @@ class HendrikTUI:
for i in range(2): for i in range(2):
idx = show + i idx = show + i
y = iy + 1 + i y = iy + 1 + i
prefix = "> " if idx < total else " "
line = self.input_buffer[idx] if idx < total else "" line = self.input_buffer[idx] if idx < total else ""
vis = prefix + line max_text = self.w - 6
if len(vis) > self.w - 2: if len(line) > max_text:
vis = vis[: self.w - 2] line = line[:max_text]
fmt = "\u2502 " + vis + blank[len(vis):] + "\u2502" if idx < total:
stdscr.addstr(y, 0, fmt, curses.color_pair(self.C_INPUT)) fmt = "\u2502 > " + line + " " * (max_text + 1 - len(line)) + "\u2502"
else:
fmt = "\u2502 " + " " * (self.w - 5) + "\u2502"
try:
stdscr.addstr(y, 0, fmt, curses.color_pair(self.C_INPUT))
except curses.error:
pass
if idx == self.input_line and not self.processing: if idx == self.input_line and not self.processing:
col = min(2 + self.input_col, self.w - 3) col = 4 + min(self.input_col, max_text)
stdscr.move(y, col) stdscr.move(y, col)
# ---- status bar ------------------------------------------------------- # ---- status bar -------------------------------------------------------