mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 12:32:22 -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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var result string
|
var result, property string
|
||||||
var property string
|
var inProperty, inTemplate bool
|
||||||
var inProperty bool
|
for i, char := range t.Template {
|
||||||
for _, 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 {
|
switch char {
|
||||||
case '.':
|
case '.':
|
||||||
var lastChar rune
|
var lastChar rune
|
||||||
|
|
|
@ -20,6 +20,12 @@ func TestRenderTemplate(t *testing.T) {
|
||||||
ShouldError bool
|
ShouldError bool
|
||||||
Context interface{}
|
Context interface{}
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
Case: "dot literal",
|
||||||
|
Expected: "Hello .NET \uE77F",
|
||||||
|
Template: "{{ .Text }} .NET \uE77F",
|
||||||
|
Context: struct{ Text string }{Text: "Hello"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Case: "color override with dots",
|
Case: "color override with dots",
|
||||||
Expected: "😺💬<#FF8000> Meow! What should I do next? ...</>",
|
Expected: "😺💬<#FF8000> Meow! What should I do next? ...</>",
|
||||||
|
|
|
@ -90,16 +90,6 @@ end
|
||||||
|
|
||||||
## Template logic
|
## 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 -->
|
<!-- markdownlint-disable MD013 -->
|
||||||
|
|
||||||
| Template | Description |
|
| Template | Description |
|
||||||
|
|
Loading…
Reference in a new issue