From 82619ece689de8b73c77baa85927346a03822158 Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Tue, 17 Feb 2026 10:28:24 +0100 Subject: [PATCH] feat: convert help-table to dynamic width and update AGENTS.md formatting - Converted help-table function in task.template to use dynamic column widths based on content - Removed fixed width parameters and implemented logic to calculate maximum widths from table data - Added new prompt file documenting the conversion from fixed to dynamic width table - Removed redundant bold formatting in AGENTS.md for consistency with project style - Updated task.template permissions to executable (755) --- AGENTS.md | 2 +- .../convert-help-table-to-dynamic-width.md | 57 +++++++++++++++++++ task.template | 0 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 prompts/convert-help-table-to-dynamic-width.md mode change 100644 => 100755 task.template diff --git a/AGENTS.md b/AGENTS.md index 93462e5..9152f07 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -47,7 +47,7 @@ This project uses the standard. The `./task` file is a bash script that provides all functions necessary to work with this project. -**Execute**: Always try to run a command with the `./task` file script. +Always try to run a command with the `./task` file script. ## Coding conventions diff --git a/prompts/convert-help-table-to-dynamic-width.md b/prompts/convert-help-table-to-dynamic-width.md new file mode 100644 index 0000000..386555c --- /dev/null +++ b/prompts/convert-help-table-to-dynamic-width.md @@ -0,0 +1,57 @@ +Check if the `task` file has `help-table` function that has a fixed width. + +```bash +help-table() { + local cmd_width=30 + local opt_width=26 + local desc_width=70 + local column="| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" + + printf "$column" 'Command' 'Option' 'Description' + echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|" + # Env + printf "$column" 'version' '' 'Show tool versions.' + ... +} +``` + +Convert the fixed with do a dynamic width. + +```bash +help-table() { + local -a rows + local max_cmd=7 max_opt=6 max_desc=11 + + rows+=("Command|Option|Description") + # Env + rows+=("version||Show version of required tools.") + ... + + for row in "${rows[@]}"; do + IFS='|' read -r cmd opt desc <<< "$row" + (( ${#cmd} > max_cmd )) && max_cmd=${#cmd} + (( ${#opt} > max_opt )) && max_opt=${#opt} + (( ${#desc} > max_desc )) && max_desc=${#desc} + done + + printf '| %-*s | %-*s | %-*s |\n' \ + "$max_cmd" "Command" \ + "$max_opt" "Option" \ + "$max_desc" "Description" + + printf '|-%*s-|-%*s-|-%*s-|\n' \ + "$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \ + "$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \ + "$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')" + + for row in "${rows[@]:1}"; do + IFS='|' read -r cmd opt desc <<< "$row" + printf '| %-*s | %-*s | %-*s |\n' \ + "$max_cmd" "$cmd" \ + "$max_opt" "$opt" \ + "$max_desc" "$desc" + done +} +``` + +Only comment the row entry section. Do not comment the logic of the dynamic table code. \ No newline at end of file diff --git a/task.template b/task.template old mode 100644 new mode 100755