From d92768dd2374e313d3def96e67bef780f4923439 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 12 May 2026 21:27:00 +0200 Subject: [PATCH] list_view --- Gemfile.lock | 2 +- lib/tui/helpers.rb | 23 +++++++---------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index dc38719..63c5251 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://git.teletype.hu/tools/rubbs.git - revision: da5acfd55e5e9dcb9959437bba84db21e5540aa8 + revision: be21826eccc8eb2930b7a83a97b8ed9672219a9c specs: bbs (0.3.0) artii (~> 2.1) diff --git a/lib/tui/helpers.rb b/lib/tui/helpers.rb index 5d24237..f182d76 100644 --- a/lib/tui/helpers.rb +++ b/lib/tui/helpers.rb @@ -55,22 +55,13 @@ module TUIHelpers end def render_wiki_list - list_height = content_height - 3 - visible = @items[@scroll, list_height] || [] - if visible.empty? - text 'No items found.', x: CONTENT_X, y: CONTENT_Y, style: THEME[:normal] - else - list visible.map { |wiki_page| wiki_page.title[0, content_width - 2] }, - x: CONTENT_X, - y: CONTENT_Y, - selected: @item_selection - @scroll, - style: THEME[:normal], - highlight: THEME[:selected] - if (wiki_page = @items[@item_selection]) - hint = wiki_page.description.to_s.strip[0, content_width] - text hint, x: CONTENT_X, y: CONTENT_Y + content_height - 2, style: THEME[:normal] unless hint.empty? - end - end + list_view @items, + x: CONTENT_X, y: CONTENT_Y, + height: content_height - 3, scroll: @scroll, selected: @item_selection, + label: ->(p) { p.title[0, content_width - 2] }, + hint: ->(p) { p.description.to_s[0, content_width] }, + hint_y: CONTENT_Y + content_height - 2, + style: THEME[:normal], highlight: THEME[:selected] text '↑↓ navigate Enter read r refresh q back', x: CONTENT_X, y: CONTENT_Y + content_height, style: THEME[:label] end