Skip to content

Commit

Permalink
feat(tooltips): allow multiple tooltips for tip
Browse files Browse the repository at this point in the history
Instead of rendering only the last tooltip that matches a given tip it
will now render all tooltips that trigger for that tip.
  • Loading branch information
rose-m authored and JanDeDobbeleer committed Jun 14, 2024
1 parent ad4b27b commit 3ff30f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/engine/tooltip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 tooltip == nil {
return ""
}
if err := tooltip.mapSegmentWithWriter(e.Env); err != nil {
continue
}

if err := tooltip.mapSegmentWithWriter(e.Env); err != nil {
return ""
if !tooltip.writer.Enabled() {
continue
}

tooltips = append(tooltips, tooltip)
}

if !tooltip.writer.Enabled() {
if len(tooltips) == 0 {
return ""
}

tooltip.Enabled = true

// little hack to reuse the current logic
block := &Block{
Alignment: Right,
Segments: []*Segment{tooltip},
Segments: tooltips,
}

switch e.Env.Shell() {
Expand Down
24 changes: 24 additions & 0 deletions website/docs/configuration/tooltips.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Config data={{
"blocks": [],
"tooltips": [
{
"type": "aws",
"tips": ["aws", "terraform"],
"style": "plain",
"foreground": "#e0af68",
"template": "\uf0e0f {{.Profile}}{{if .Region}}@{{.Region}}{{end}}"
},
{
"type": "az",
"tips": ["az", "terraform"],
"style": "plain",
"foreground": "#b4f9f8",
"template": "\uebd8 {{ .Name }}"
}
]
}}/>

[clink]: https://chrisant996.github.io/clink/

0 comments on commit 3ff30f9

Please sign in to comment.