Skip to content

Commit b3cf79a

Browse files
committed
Rename symbol function
1 parent 6d1cff7 commit b3cf79a

File tree

9 files changed

+58
-58
lines changed

9 files changed

+58
-58
lines changed

.tokeignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
assets/glyphnames.json
2-
internal/symbols/map.go
2+
internal/integrations/nerdfonts/symbols.go

cmd/mkprompt/symbols.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"slices"
66

7-
"github.com/Soft/mkprompt/internal/symbols"
7+
"github.com/Soft/mkprompt/internal/integrations/nerdfonts"
88
)
99

1010
type Symbol struct {
@@ -13,8 +13,8 @@ type Symbol struct {
1313
}
1414

1515
func listSymbols() {
16-
symbolList := make([]Symbol, 0, len(symbols.SymbolMap))
17-
for name, code := range symbols.SymbolMap {
16+
symbolList := make([]Symbol, 0, len(nerdfonts.SymbolMap))
17+
for name, code := range nerdfonts.SymbolMap {
1818
symbolList = append(symbolList, Symbol{
1919
Name: name,
2020
Code: code,

examples/fancy.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"call": "concat",
5353
"strings": [
5454
" ",
55-
{ "call": "symbol", "name": "dev-linux" },
55+
{ "call": "nerd_fonts", "symbol": "dev-linux" },
5656
" ",
5757
{ "call": "username" },
5858
" "
@@ -65,7 +65,7 @@
6565
"call": "concat",
6666
"strings": [
6767
" ",
68-
{ "call": "symbol", "name": "oct-server" },
68+
{ "call": "nerd_fonts", "symbol": "oct-server" },
6969
" ",
7070
{ "call": "hostname" },
7171
" "
@@ -83,7 +83,7 @@
8383
"call": "concat",
8484
"strings": [
8585
" ",
86-
{ "call": "symbol", "name": "dev-git_branch" },
86+
{ "call": "nerd_fonts", "symbol": "dev-git_branch" },
8787
" ",
8888
{ "ref": "git_branch" },
8989
" "
@@ -115,7 +115,7 @@
115115
"call": "concat",
116116
"strings": [
117117
" ",
118-
{ "call": "symbol", "name": "dev-python" },
118+
{ "call": "nerd_fonts", "symbol": "dev-python" },
119119
" ",
120120
{
121121
"call": "lookup",
@@ -145,7 +145,7 @@
145145
"call": "concat",
146146
"strings": [
147147
" ",
148-
{ "call": "symbol", "name": "fa-warning" },
148+
{ "call": "nerd_fonts", "symbol": "fa-warning" },
149149
" "
150150
]
151151
}
@@ -227,8 +227,8 @@
227227
"content": {
228228
"call": "text",
229229
"content": {
230-
"call": "symbol",
231-
"name": "ple-left_half_circle_thick"
230+
"call": "nerd_fonts",
231+
"symbol": "ple-left_half_circle_thick"
232232
}
233233
}
234234
},
@@ -248,8 +248,8 @@
248248
"content": {
249249
"call": "text",
250250
"content": {
251-
"call": "symbol",
252-
"name": "ple-right_half_circle_thick"
251+
"call": "nerd_fonts",
252+
"symbol": "ple-right_half_circle_thick"
253253
}
254254
}
255255
},
@@ -260,8 +260,8 @@
260260
"content": {
261261
"call": "text",
262262
"content": {
263-
"call": "symbol",
264-
"name": "pl-left_hard_divider"
263+
"call": "nerd_fonts",
264+
"symbol": "pl-left_hard_divider"
265265
}
266266
}
267267
}

internal/builtins/builtins.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ var Builtins = []*Builtin{
4040
&SplitCount,
4141
&ToString,
4242

43-
// Symbol functions
44-
&Symbol,
45-
4643
// List functions
4744
&Length,
4845
&Empty,
@@ -105,6 +102,9 @@ var Builtins = []*Builtin{
105102
// Python functions
106103
&PythonVirtualEnvStatus,
107104

105+
// Nerd Font functions
106+
&NerdFonts,
107+
108108
// Environment functions
109109
&Environment,
110110

internal/builtins/nerdfonts.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package builtins
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/Soft/mkprompt/internal/eval"
7+
"github.com/Soft/mkprompt/internal/integrations/nerdfonts"
8+
)
9+
10+
func nerdFontsFunction(args map[string]eval.Value) (value eval.Value, err error) {
11+
nameValue := args["symbol"]
12+
13+
var name eval.String
14+
if name, err = eval.AsString(nameValue); err != nil {
15+
return
16+
}
17+
18+
var symbolRune rune
19+
var ok bool
20+
if symbolRune, ok = nerdfonts.SymbolMap[name.Value]; !ok {
21+
err = fmt.Errorf("unknown symbol %q", name.Value)
22+
return
23+
}
24+
25+
value = eval.String{Value: string(symbolRune)}
26+
return
27+
}
28+
29+
var NerdFonts = Builtin{
30+
Name: "nerd_fonts",
31+
Description: "Return the specified Nerd Fonts symbol.",
32+
Function: eval.BuiltinFunction{
33+
Parameters: []eval.ParameterSpec{{Name: "symbol"}},
34+
Function: nerdFontsFunction,
35+
},
36+
}

internal/builtins/symbol.go

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package nerdfonts
2+
3+
//go:generate go run ../../build/cmd/gensymbols/main.go nerdfonts ../../../assets/glyphnames.json symbols.go

internal/symbols/map.go renamed to internal/integrations/nerdfonts/symbols.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/symbols/symbols.go

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)