Skip to content

Commit 10f8819

Browse files
authored
Merge pull request #69 from poppycompass/add-color-example
Added example for color usage
2 parents 14fffe7 + 08ea615 commit 10f8819

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ Hello Someusername
257257
```
258258

259259

260+
### Output with Color
261+
You can use [fatih/color](https://github.com/fatih/color).
262+
263+
```go
264+
func(c *ishell.Context) {
265+
yellow := color.New(color.FgYellow).SprintFunc()
266+
c.Println(yellow("This line is yellow"))
267+
}
268+
```
269+
Execution
270+
```sh
271+
>>> color
272+
This line is yellow
273+
```
274+
275+
260276
### Example
261277
Available [here](https://github.com/abiosoft/ishell/blob/master/example/main.go).
262278
```sh

example/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/abiosoft/ishell"
11+
"github.com/fatih/color"
1112
)
1213

1314
func main() {
@@ -190,6 +191,19 @@ This is another line of it.
190191
},
191192
})
192193

194+
cyan := color.New(color.FgCyan).SprintFunc()
195+
yellow := color.New(color.FgYellow).SprintFunc()
196+
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
197+
shell.AddCmd(&ishell.Cmd{
198+
Name: "color",
199+
Help: "color print",
200+
Func: func(c *ishell.Context) {
201+
c.Print(cyan("cyan\n"))
202+
c.Println(yellow("yellow"))
203+
c.Printf("%s\n", boldRed("bold red"))
204+
},
205+
})
206+
193207
// when started with "exit" as first argument, assume non-interactive execution
194208
if len(os.Args) > 1 && os.Args[1] == "exit" {
195209
shell.Process(os.Args[2:]...)

0 commit comments

Comments
 (0)