git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/5] gitk: condense repetitive code around color buttons into foreach loops

From
mark <mlevedahl@gmail.com>
Date
Aug 7, 2026, 14:37 UTC
Message-ID
<a2e12e20-ad46-4521-9d45-5b74730361f1@gmail.com>
In-Reply-To
<edb567608e1bda16efbdb8d4ec359318cf105284.1785998419.git.gitgitgadget@gmail.com>
On 8/6/26 2:40 AM, Johannes Sixt via GitGitGadget wrote:
Show 24 quoted lines
> From: Johannes Sixt <j6t@kdbg.org>
> 
> The color selection elements in the Preferences dialog are set up in a
> very uniform manner. The code doing that has grown in the past by simply
> modifying a copy of a paragraph. Extract the varying parts into a list
> and then operate the repeating parts in a foreach loop. This helps a
> later change where we want to set up the UI elements in a different way.
> 
> Change the UI names "markbgsep" and "selbgsep" to drop the "sep", which
> has obviously been left over by accident when "hunksep" was copied.
> 
> Change the suffix "but" to "btn", which resonates a bit better when
> reading the code.
> 
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
>  gitk-git/gitk | 114 ++++++++++++++++++++++++--------------------------
>  1 file changed, 55 insertions(+), 59 deletions(-)
> 
> diff --git a/gitk-git/gitk b/gitk-git/gitk
> index f5eb963b86..137940defb 100755
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -11832,55 +11832,46 @@ proc prefspage_colors {notebook} {
Show 13 quoted lines
> -
> -    label $page.linkfg -padx 40 -relief sunk
> -    ttk::button $page.linkfgbut -text [mc "Link"] \
> -        -command [list choosecolor linkfgcolor {} $page [mc "link"]]
> -    grid x $page.linkfgbut $page.linkfg -sticky w
> +
> +    set coloruielems [list \
> +        bg          bgcolor {} \
> +                    [mc "Background"] \
> +                    [mc "background"] \
> +        fg          fgcolor {} \
> +                    [mc "Foreground"] \
> +                    [mc "foreground"] \

The list is computed and used each time a dialog box is started from all static elements, no real change. But this cleanly separates the per item data from the boiler plate, definitely more readable. Good.

Previous: Johannes Sixt via GitGitGadgetNext: Johannes Sixt via GitGitGadget
Message 5 of 27 in “gitk: make color preferences visually more pleasing and better usable”
  1. 0/5 gitk: make color preferences visually more pleasing and better usableJohannes Sixt via GitGitGadget, Aug 6, 2026
  2. 1/5 gitk: set intitial colors of swatches using the available helperJohannes Sixt via GitGitGadget, Aug 6, 2026
  3. markAug 7, 2026
  4. 2/5 gitk: condense repetitive code around color buttons into foreach loopsJohannes Sixt via GitGitGadget, Aug 6, 2026
  5. markAug 7, 2026
  6. 3/5 gitk: show color preferences on the button instead of the labelJohannes Sixt via GitGitGadget, Aug 6, 2026
  7. markAug 7, 2026
  8. Johannes SixtAug 8, 2026
  9. 4/5 gitk: use more natural language for labels of color preferencesJohannes Sixt via GitGitGadget, Aug 6, 2026
  10. 5/5 gitk: avoid constructing dialog titles from text piecesJohannes Sixt via GitGitGadget, Aug 6, 2026
  11. markAug 7, 2026
  12. Johannes SixtAug 8, 2026
  13. Mark LevedahlAug 8, 2026
  14. Johannes SixtAug 9, 2026
  15. Junio C HamanoAug 8, 2026
  16. Johannes SixtAug 9, 2026
  17. 0/6 gitk: make color preferences visually more pleasing and better usableJohannes Sixt via GitGitGadget, Aug 12, 2026
  18. 1/6 gitk: set intitial colors of swatches using the available helperJohannes Sixt via GitGitGadget, Aug 12, 2026
  19. 2/6 gitk: condense repetitive code around color buttons into foreach loopsJohannes Sixt via GitGitGadget, Aug 12, 2026
  20. 3/6 gitk: show color preferences on the button instead of the labelJohannes Sixt via GitGitGadget, Aug 12, 2026
  21. Mark LevedahlAug 13, 2026
  22. 4/6 gitk: use more natural language for labels of color preferencesJohannes Sixt via GitGitGadget, Aug 12, 2026
  23. Mark LevedahlAug 13, 2026
  24. Johannes SixtAug 13, 2026
  25. Mark LevedahlAug 13, 2026
  26. 5/6 gitk: avoid constructing dialog titles from text piecesJohannes Sixt via GitGitGadget, Aug 12, 2026
  27. 6/6 gitk: move UI for generic colors above diff colorsJohannes Sixt via GitGitGadget, Aug 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.