From 3ff30f993ef0506bf143a52dd6b9f1e4d696d53f Mon Sep 17 00:00:00 2001 From: Michael Rose Date: Fri, 14 Jun 2024 08:12:33 +0200 Subject: [PATCH] feat(tooltips): allow multiple tooltips for tip Instead of rendering only the last tooltip that matches a given tip it will now render all tooltips that trigger for that tip. --- src/engine/tooltip.go | 32 ++++++++++++------------- website/docs/configuration/tooltips.mdx | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/engine/tooltip.go b/src/engine/tooltip.go index b19704d3..256626ad 100644 --- a/src/engine/tooltip.go +++ b/src/engine/tooltip.go @@ -8,32 +8,32 @@ import ( func (e *Engine) Tooltip(tip string) string { tip = strings.Trim(tip, " ") - var tooltip *Segment - for _, tp := range e.Config.Tooltips { - if !tp.shouldInvokeWithTip(tip) { + tooltips := make([]*Segment, 0, 1) + + for _, tooltip := range e.Config.Tooltips { + if !tooltip.shouldInvokeWithTip(tip) { continue } - tooltip = tp + + if err := tooltip.mapSegmentWithWriter(e.Env); err != nil { + continue + } + + if !tooltip.writer.Enabled() { + continue + } + + tooltips = append(tooltips, tooltip) } - if tooltip == nil { + if len(tooltips) == 0 { return "" } - if err := tooltip.mapSegmentWithWriter(e.Env); err != nil { - return "" - } - - if !tooltip.writer.Enabled() { - return "" - } - - tooltip.Enabled = true - // little hack to reuse the current logic block := &Block{ Alignment: Right, - Segments: []*Segment{tooltip}, + Segments: tooltips, } switch e.Env.Shell() { diff --git a/website/docs/configuration/tooltips.mdx b/website/docs/configuration/tooltips.mdx index 5e8000fa..6cd1f618 100644 --- a/website/docs/configuration/tooltips.mdx +++ b/website/docs/configuration/tooltips.mdx @@ -47,4 +47,28 @@ This configuration will render a right-aligned git segment when you type `git` o A tip should not include any spaces. Keep in mind that this is a blocking call, meaning that if the segment renders slow, you can't type until it's visible. Optimizations in this space are being explored. +Note that you can also define multiple tooltips for the same tip to compose tooltips for individual commands. For example, +this configuration will render the AWS profile as well as the Azure subscription information when you type `terraform` +followed by a space. + + + [clink]: https://chrisant996.github.io/clink/