mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 04:21:19 -08:00
fix(template): remove the need for escaping a dot literal
This commit is contained in:
parent
c5b7c7fbfc
commit
80b92505bc
|
@ -108,10 +108,23 @@ func (t *Text) cleanTemplate() {
|
|||
return false
|
||||
}
|
||||
|
||||
var result string
|
||||
var property string
|
||||
var inProperty bool
|
||||
for _, char := range t.Template {
|
||||
var result, property string
|
||||
var inProperty, inTemplate bool
|
||||
for i, char := range t.Template {
|
||||
// define start or end of template
|
||||
if !inTemplate && char == '{' {
|
||||
if i-1 >= 0 && rune(t.Template[i-1]) == '{' {
|
||||
inTemplate = true
|
||||
}
|
||||
} else if inTemplate && char == '}' {
|
||||
if i-1 >= 0 && rune(t.Template[i-1]) == '}' {
|
||||
inTemplate = false
|
||||
}
|
||||
}
|
||||
if !inTemplate {
|
||||
result += string(char)
|
||||
continue
|
||||
}
|
||||
switch char {
|
||||
case '.':
|
||||
var lastChar rune
|
||||
|
|
|
@ -20,6 +20,12 @@ func TestRenderTemplate(t *testing.T) {
|
|||
ShouldError bool
|
||||
Context interface{}
|
||||
}{
|
||||
{
|
||||
Case: "dot literal",
|
||||
Expected: "Hello .NET \uE77F",
|
||||
Template: "{{ .Text }} .NET \uE77F",
|
||||
Context: struct{ Text string }{Text: "Hello"},
|
||||
},
|
||||
{
|
||||
Case: "color override with dots",
|
||||
Expected: "😺💬<#FF8000> Meow! What should I do next? ...</>",
|
||||
|
|
|
@ -90,16 +90,6 @@ end
|
|||
|
||||
## Template logic
|
||||
|
||||
:::tip
|
||||
Oh My Posh replaces all unknown `.Var` variables in the template with the right references. If you need a literal `.Var`, use `\.Var`
|
||||
in the template.
|
||||
|
||||
```json
|
||||
"template": " \\.NET \uE77F "
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
<!-- markdownlint-disable MD013 -->
|
||||
|
||||
| Template | Description |
|
||||
|
|
Loading…
Reference in a new issue