mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
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.
This commit is contained in:
parent
ad4b27b8dd
commit
3ff30f993e
|
@ -8,32 +8,32 @@ import (
|
||||||
|
|
||||||
func (e *Engine) Tooltip(tip string) string {
|
func (e *Engine) Tooltip(tip string) string {
|
||||||
tip = strings.Trim(tip, " ")
|
tip = strings.Trim(tip, " ")
|
||||||
var tooltip *Segment
|
tooltips := make([]*Segment, 0, 1)
|
||||||
for _, tp := range e.Config.Tooltips {
|
|
||||||
if !tp.shouldInvokeWithTip(tip) {
|
for _, tooltip := range e.Config.Tooltips {
|
||||||
|
if !tooltip.shouldInvokeWithTip(tip) {
|
||||||
continue
|
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 ""
|
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
|
// little hack to reuse the current logic
|
||||||
block := &Block{
|
block := &Block{
|
||||||
Alignment: Right,
|
Alignment: Right,
|
||||||
Segments: []*Segment{tooltip},
|
Segments: tooltips,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch e.Env.Shell() {
|
switch e.Env.Shell() {
|
||||||
|
|
|
@ -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,
|
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.
|
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/
|
[clink]: https://chrisant996.github.io/clink/
|
||||||
|
|
Loading…
Reference in a new issue