aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/colorful/README.md2
-rw-r--r--examples/colorful/colorful.tm17
2 files changed, 14 insertions, 5 deletions
diff --git a/examples/colorful/README.md b/examples/colorful/README.md
index 2253431c..e0572bac 100644
--- a/examples/colorful/README.md
+++ b/examples/colorful/README.md
@@ -47,7 +47,7 @@ You can run `colorful` as a standalone executable to render colorful text with
ANSI escape sequences so it looks nice on a terminal.
```
-colorful [--inplace] [file] [--by-line]
+colorful [--help] [texts...] [--by-line] [--files ...]
```
## Library Usage
diff --git a/examples/colorful/colorful.tm b/examples/colorful/colorful.tm
index 48405811..71b83873 100644
--- a/examples/colorful/colorful.tm
+++ b/examples/colorful/colorful.tm
@@ -1,7 +1,7 @@
# Colorful language
HELP := "
colorful: A domain-specific language for writing colored text to the terminal
- Usage: colorful [--by-line] [files...]
+ Usage: colorful [args...] [--by-line] [--files files...]
"
CSI := "$\033["
@@ -189,12 +189,21 @@ lang Colorful:
func print(c:Colorful, newline=yes):
say(c:for_terminal(), newline=newline)
-func main(files=[(/dev/stdin)], by_line=no):
+func main(texts:[Text], files=[:Path], by_line=no):
+ for i,text in texts:
+ colorful := Colorful.without_escaping(text)
+ colorful:print(newline=no)
+ if i == texts.length: say("")
+ else: say(" ", newline=no)
+
+ if texts.length == 0 and files.length == 0:
+ files = [(/dev/stdin)]
+
for file in files:
if by_line:
- for line in file:by_line() or exit("Couldn't read file: $file"):
+ for line in file:by_line() or exit("Could not read file: $(file.text)"):
colorful := Colorful.without_escaping(line)
colorful:print()
else:
- colorful := Colorful.without_escaping(file:read() or exit("Couldn't read file: $file"))
+ colorful := Colorful.without_escaping(file:read() or exit("Could not read file: $(file.text)"))
colorful:print(newline=no)