File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff 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
261277Available [ here] ( https://github.com/abiosoft/ishell/blob/master/example/main.go ) .
262278``` sh
Original file line number Diff line number Diff line change 88 "time"
99
1010 "github.com/abiosoft/ishell"
11+ "github.com/fatih/color"
1112)
1213
1314func 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 :]... )
You can’t perform that action at this time.
0 commit comments