Skip to content

Commit

Permalink
feat: highlight Env KEY=VALUE
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Maas Lalani <[email protected]>
  • Loading branch information
Delta456 and maaslalani committed Apr 24, 2024
1 parent 1fc8002 commit 0bec1f5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,13 @@ Paste
`Env` command sets the environment variable via key-value pair.

```elixir
Env HELLO WORLD
Env HELLO "WORLD"

Type "echo $HELLO"
Enter
Sleep 3s
Sleep 1s
```


### Source

The `source` command allows you to execute commands from another tape.
Expand Down
2 changes: 1 addition & 1 deletion evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Evaluate(ctx context.Context, tape string, out io.Writer, opts ...Evaluator

v := New()
for _, cmd := range cmds {
if cmd.Type == token.SET && cmd.Options == "Shell" {
if cmd.Type == token.SET && cmd.Options == "Shell" || cmd.Type == token.ENV {
Execute(cmd, &v)
}
if cmd.Type == token.ENV {
Expand Down
3 changes: 3 additions & 0 deletions examples/env/env.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/env/env.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Output examples/env/env.gif

Set Width 500
Set Height 250

Env HELLO "WORLD"

Type "echo $HELLO"
Sleep 500ms
Enter
Sleep 1s
11 changes: 10 additions & 1 deletion syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func Highlight(c parser.Command, faint bool) string {
} else {
argsStyle = StringStyle
}
case token.ENV:
optionsStyle = NoneStyle
argsStyle = StringStyle
case token.OUTPUT:
optionsStyle = NoneStyle
argsStyle = StringStyle
Expand All @@ -52,7 +55,13 @@ func Highlight(c parser.Command, faint bool) string {
var s strings.Builder
s.WriteString(CommandStyle.Render(c.Type.String()) + " ")
if c.Options != "" {
s.WriteString(optionsStyle.Render(c.Options) + " ")
s.WriteString(optionsStyle.Render(c.Options))
switch c.Type {
case token.ENV:
s.WriteString("=")
default:
s.WriteString(" ")
}
}
s.WriteString(argsStyle.Render(c.Args))
return s.String()
Expand Down

0 comments on commit 0bec1f5

Please sign in to comment.