From 0bec1f5823ed2656b912edab1dd3bdc896a8df79 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Thu, 25 Apr 2024 00:59:51 +0530 Subject: [PATCH] feat: highlight Env KEY=VALUE --------- Co-authored-by: Maas Lalani --- README.md | 5 ++--- evaluator.go | 2 +- examples/env/env.gif | 3 +++ examples/env/env.tape | 11 +++++++++++ syntax.go | 11 ++++++++++- 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 examples/env/env.gif create mode 100644 examples/env/env.tape diff --git a/README.md b/README.md index 071887f9..87404849 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/evaluator.go b/evaluator.go index 048cd327..59548c87 100644 --- a/evaluator.go +++ b/evaluator.go @@ -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 { diff --git a/examples/env/env.gif b/examples/env/env.gif new file mode 100644 index 00000000..2754416a --- /dev/null +++ b/examples/env/env.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:805e61873e5099846cbbbeac3948b922cfd94581aef519d7829be33d66d52821 +size 9937 diff --git a/examples/env/env.tape b/examples/env/env.tape new file mode 100644 index 00000000..7df9e346 --- /dev/null +++ b/examples/env/env.tape @@ -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 diff --git a/syntax.go b/syntax.go index 981e0fd7..b6a320c9 100644 --- a/syntax.go +++ b/syntax.go @@ -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 @@ -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()