Skip to content

Commit da7861b

Browse files
authored
Merge pull request #19 from grega/section-divider-lines
Section divider lines
2 parents b6de0fb + 15b09e6 commit da7861b

6 files changed

Lines changed: 68 additions & 16 deletions

File tree

hdi

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ declare -a CMD_INDICES=() # indices into DISPLAY_LINES that are commands
532532
declare -a SECTION_FIRST_CMD=() # cursor indices (into CMD_INDICES) of first cmd per section
533533

534534
build_display_list() {
535+
_MAX_CONTENT_WIDTH=0
535536
for i in "${!SECTION_TITLES[@]}"; do
536537
local title="${SECTION_TITLES[$i]}"
537538
local body="${SECTION_BODIES[$i]}"
@@ -559,6 +560,7 @@ build_display_list() {
559560
DISPLAY_LINES+=("$tcmd")
560561
LINE_TYPES+=("command")
561562
LINE_CMDS+=("$tcmd")
563+
(( ${#tcmd} + 4 > _MAX_CONTENT_WIDTH )) && _MAX_CONTENT_WIDTH=$(( ${#tcmd} + 4 ))
562564
done <<< "$title_cmds"
563565
fi
564566

@@ -620,6 +622,7 @@ build_display_list() {
620622
DISPLAY_LINES+=("$_entry")
621623
LINE_TYPES+=("command")
622624
LINE_CMDS+=("$_entry")
625+
(( ${#_entry} + 4 > _MAX_CONTENT_WIDTH )) && _MAX_CONTENT_WIDTH=$(( ${#_entry} + 4 ))
623626
done <<< "$cmds"
624627
fi
625628

@@ -647,7 +650,7 @@ render_static() {
647650
if $RAW; then
648651
printf "\n## %s\n" "$line"
649652
else
650-
printf "\n%s%s ▸ %s%s\n" "$BOLD" "$CYAN" "$line" "$RESET"
653+
_section_header "$line"; printf "\n%s\n" "$_SH"
651654
fi
652655
;;
653656
subheader)
@@ -698,7 +701,7 @@ render_full() {
698701
continue
699702
fi
700703

701-
printf "\n%s%s ▸ %s%s\n" "$BOLD" "$CYAN" "$title" "$RESET"
704+
_section_header "$title"; printf "\n%s\n" "$_SH"
702705

703706
local in_code=false
704707
local code_buf=""
@@ -806,6 +809,21 @@ _term_height() {
806809
echo 24
807810
}
808811

812+
# Pre-computed dash string (200 chars covers any reasonable terminal width)
813+
_DASH_POOL="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
814+
815+
# Format a section header with trailing dashes (sets _SH, no subshell)
816+
# _MAX_CONTENT_WIDTH is computed during build_display_list
817+
_SH=""
818+
_section_header() {
819+
local prefix="$1 "
820+
local prefix_len=${#prefix}
821+
local target=$(( _MAX_CONTENT_WIDTH > prefix_len ? _MAX_CONTENT_WIDTH : prefix_len + 4 ))
822+
local n=$(( target - prefix_len ))
823+
(( n < 2 )) && n=2
824+
_SH="${BOLD}${CYAN}${prefix}${RESET}${DIM}${_DASH_POOL:0:n}${RESET}"
825+
}
826+
809827
# Screen lines per display entry type — sets _SL (no subshell)
810828
# Headers/subheaders take 2 lines (blank + text), others take 1
811829
_SL=1
@@ -945,7 +963,8 @@ draw_picker() {
945963
all) hdr+=" ${DIM}[all]${RESET}" ;;
946964
esac
947965
_line "$hdr"
948-
local chrome=3
966+
_blank
967+
local chrome=4
949968

950969
# Scroll-up indicator (only if meaningful content is above the viewport)
951970
local has_above=false
@@ -986,7 +1005,7 @@ draw_picker() {
9861005
if (( idx != VIEWPORT_TOP )); then
9871006
_blank; (( rendered += 1 ))
9881007
fi
989-
_line "${BOLD}${CYAN}${line}${RESET}"
1008+
_section_header "$line"; _line "$_SH"
9901009
(( rendered += 1 ))
9911010
;;
9921011
subheader)
@@ -1482,11 +1501,18 @@ _PLATFORM_DISPLAY=""
14821501
build_platform_display() {
14831502
_PLATFORM_DISPLAY=""
14841503
if (( ${#PLATFORM_NAMES[@]} == 0 )); then return; fi
1485-
local parts=""
1504+
local parts="" prev_low=false
14861505
for i in "${!PLATFORM_NAMES[@]}"; do
1487-
if [[ -n "$parts" ]]; then parts+=", "; fi
1506+
if [[ -n "$parts" ]]; then
1507+
if $prev_low; then parts+=" "; else parts+=", "; fi
1508+
fi
14881509
parts+="${PLATFORM_NAMES[$i]}"
1489-
if [[ "${PLATFORM_CONFIDENCE[$i]}" == "low" ]]; then parts+="?"; fi
1510+
if [[ "${PLATFORM_CONFIDENCE[$i]}" == "low" ]]; then
1511+
parts+="?"
1512+
prev_low=true
1513+
else
1514+
prev_low=false
1515+
fi
14901516
done
14911517
_PLATFORM_DISPLAY="$parts"
14921518
}
@@ -1817,7 +1843,7 @@ else
18171843
;;
18181844
all) printf " %s[all]%s" "$DIM" "$RESET" ;;
18191845
esac
1820-
printf "\n"
1846+
printf "\n\n"
18211847
fi
18221848

18231849
if $FULL; then

src/display.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare -a CMD_INDICES=() # indices into DISPLAY_LINES that are commands
1010
declare -a SECTION_FIRST_CMD=() # cursor indices (into CMD_INDICES) of first cmd per section
1111

1212
build_display_list() {
13+
_MAX_CONTENT_WIDTH=0
1314
for i in "${!SECTION_TITLES[@]}"; do
1415
local title="${SECTION_TITLES[$i]}"
1516
local body="${SECTION_BODIES[$i]}"
@@ -37,6 +38,7 @@ build_display_list() {
3738
DISPLAY_LINES+=("$tcmd")
3839
LINE_TYPES+=("command")
3940
LINE_CMDS+=("$tcmd")
41+
(( ${#tcmd} + 4 > _MAX_CONTENT_WIDTH )) && _MAX_CONTENT_WIDTH=$(( ${#tcmd} + 4 ))
4042
done <<< "$title_cmds"
4143
fi
4244

@@ -98,6 +100,7 @@ build_display_list() {
98100
DISPLAY_LINES+=("$_entry")
99101
LINE_TYPES+=("command")
100102
LINE_CMDS+=("$_entry")
103+
(( ${#_entry} + 4 > _MAX_CONTENT_WIDTH )) && _MAX_CONTENT_WIDTH=$(( ${#_entry} + 4 ))
101104
done <<< "$cmds"
102105
fi
103106

src/main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ else
4646
;;
4747
all) printf " %s[all]%s" "$DIM" "$RESET" ;;
4848
esac
49-
printf "\n"
49+
printf "\n\n"
5050
fi
5151

5252
if $FULL; then

src/picker.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ _term_height() {
1919
echo 24
2020
}
2121

22+
# Pre-computed dash string (200 chars covers any reasonable terminal width)
23+
_DASH_POOL="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
24+
25+
# Format a section header with trailing dashes (sets _SH, no subshell)
26+
# _MAX_CONTENT_WIDTH is computed during build_display_list
27+
_SH=""
28+
_section_header() {
29+
local prefix="$1 "
30+
local prefix_len=${#prefix}
31+
local target=$(( _MAX_CONTENT_WIDTH > prefix_len ? _MAX_CONTENT_WIDTH : prefix_len + 4 ))
32+
local n=$(( target - prefix_len ))
33+
(( n < 2 )) && n=2
34+
_SH="${BOLD}${CYAN}${prefix}${RESET}${DIM}${_DASH_POOL:0:n}${RESET}"
35+
}
36+
2237
# Screen lines per display entry type — sets _SL (no subshell)
2338
# Headers/subheaders take 2 lines (blank + text), others take 1
2439
_SL=1
@@ -158,7 +173,8 @@ draw_picker() {
158173
all) hdr+=" ${DIM}[all]${RESET}" ;;
159174
esac
160175
_line "$hdr"
161-
local chrome=3
176+
_blank
177+
local chrome=4
162178

163179
# Scroll-up indicator (only if meaningful content is above the viewport)
164180
local has_above=false
@@ -199,7 +215,7 @@ draw_picker() {
199215
if (( idx != VIEWPORT_TOP )); then
200216
_blank; (( rendered += 1 ))
201217
fi
202-
_line "${BOLD}${CYAN}${line}${RESET}"
218+
_section_header "$line"; _line "$_SH"
203219
(( rendered += 1 ))
204220
;;
205221
subheader)

src/platform.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,18 @@ _PLATFORM_DISPLAY=""
129129
build_platform_display() {
130130
_PLATFORM_DISPLAY=""
131131
if (( ${#PLATFORM_NAMES[@]} == 0 )); then return; fi
132-
local parts=""
132+
local parts="" prev_low=false
133133
for i in "${!PLATFORM_NAMES[@]}"; do
134-
if [[ -n "$parts" ]]; then parts+=", "; fi
134+
if [[ -n "$parts" ]]; then
135+
if $prev_low; then parts+=" "; else parts+=", "; fi
136+
fi
135137
parts+="${PLATFORM_NAMES[$i]}"
136-
if [[ "${PLATFORM_CONFIDENCE[$i]}" == "low" ]]; then parts+="?"; fi
138+
if [[ "${PLATFORM_CONFIDENCE[$i]}" == "low" ]]; then
139+
parts+="?"
140+
prev_low=true
141+
else
142+
prev_low=false
143+
fi
137144
done
138145
_PLATFORM_DISPLAY="$parts"
139146
}

src/render.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ render_static() {
99
if $RAW; then
1010
printf "\n## %s\n" "$line"
1111
else
12-
printf "\n%s%s ▸ %s%s\n" "$BOLD" "$CYAN" "$line" "$RESET"
12+
_section_header "$line"; printf "\n%s\n" "$_SH"
1313
fi
1414
;;
1515
subheader)
@@ -60,7 +60,7 @@ render_full() {
6060
continue
6161
fi
6262

63-
printf "\n%s%s ▸ %s%s\n" "$BOLD" "$CYAN" "$title" "$RESET"
63+
_section_header "$title"; printf "\n%s\n" "$_SH"
6464

6565
local in_code=false
6666
local code_buf=""

0 commit comments

Comments
 (0)