diff --git a/tui/render.py b/tui/render.py index 622927b..ccc43d6 100644 --- a/tui/render.py +++ b/tui/render.py @@ -5,8 +5,6 @@ import curses import json import os -import textwrap -import config # -- Color pair IDs (id 1-9, id 0 = default curses) -- C_HEADER = 1 # header bar: biru @@ -90,21 +88,21 @@ def draw_chat(app, stdscr): rendered.append(segments) def _add_blank(): - rendered.append([(None, "")]) + rendered.append([(None, "", False)]) - def _wrap_render(text, indent=0, color=C_INPUT): + def _wrap_render(text, indent=0, color=C_INPUT, bold=False): available = w - indent - 1 # sisakan 1 kolom margin kanan if available <= 0: - _add_row([(color, " " * indent)]) + _add_row([(color, " " * indent, bold)]) return for line in text.split("\n"): if not line: - _add_row([(color, " " * indent)]) + _add_row([(color, " " * indent, bold)]) continue start = 0 while start < len(line): chunk = line[start:start + available] - _add_row([(color, " " * indent + chunk)]) + _add_row([(color, " " * indent + chunk, bold)]) start += available for idx, item in enumerate(app.log): @@ -130,21 +128,20 @@ def draw_chat(app, stdscr): model_info = item.get("model_info", None) if model_info: p_name, m_name = model_info + if p_name: + info_line = f" {p_name} - {m_name} " + else: + info_line = f" {m_name} " else: - p_name = config.resolve_provider(app.llm.base_url, app.llm.model) - m_name = app.llm.model - if p_name: - info_line = f" {p_name} - {m_name} " - else: - info_line = f" {m_name} " - _add_row([(C_USER, info_line)]) + info_line = " Unknown - Model info not found " + _add_row([(C_USER, info_line, False)]) label = f" You ({item['time']}) " _add_row([(C_USER, label)]) - _wrap_render(text, indent=1, color=C_INPUT) + _wrap_render(text, indent=1, color=C_INPUT, bold=False) elif role == "ai": label = f" Hendrik ({item['time']}) " _add_row([(C_AI, label)]) - _wrap_render(text, indent=1, color=C_INPUT) + _wrap_render(text, indent=1, color=C_INPUT, bold=False) elif role == "system": lines = text.split("\n") _add_row([(C_SYSTEM, lines[0])]) @@ -218,10 +215,11 @@ def draw_chat(app, stdscr): for i in range(app.scroll, min(app.scroll + chat_h, total)): segments = rendered[i] x = 0 - for color, text in segments: + for color, text, *bold_flag in segments: if not text: continue - attr = curses.color_pair(color) | curses.A_BOLD if color else curses.A_NORMAL + is_bold = bold_flag[0] if bold_flag else True + attr = curses.color_pair(color) | (curses.A_BOLD if is_bold else 0) if color else curses.A_NORMAL remaining = w - x if remaining <= 0: break