1
1
# ishell
2
+
2
3
ishell is an interactive shell library for creating interactive cli applications.
3
4
4
5
[ ![ Documentation] ( https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square )] ( https://godoc.org/github.com/abiosoft/ishell )
5
6
[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/abiosoft/ishell )] ( https://goreportcard.com/report/github.com/abiosoft/ishell )
6
7
7
- ## Older version
8
- The current master is not backward compatible with older version. Kindly change your import path to ` gopkg.in/abiosoft/ishell.v1 ` .
9
-
10
- Older version of this library is still available at [ https://gopkg.in/abiosoft/ishell.v1 ] ( https://gopkg.in/abiosoft/ishell.v1 ) .
11
-
12
- However, you are advised to upgrade to v2 [ https://gopkg.in/abiosoft/ishell.v2 ] ( https://gopkg.in/abiosoft/ishell.v2 ) .
13
-
14
8
## Usage
15
9
16
10
``` go
@@ -38,7 +32,9 @@ func main(){
38
32
shell.Run ()
39
33
}
40
34
```
35
+
41
36
Execution
37
+
42
38
```
43
39
Sample Interactive Shell
44
40
>>> help
56
52
```
57
53
58
54
### Reading input
55
+
59
56
``` go
60
57
// simulate an authentication
61
58
shell.AddCmd (&ishell.Cmd {
@@ -80,7 +77,9 @@ shell.AddCmd(&ishell.Cmd{
80
77
},
81
78
})
82
79
```
80
+
83
81
Execution
82
+
84
83
```
85
84
>>> login
86
85
Username: someusername
@@ -89,7 +88,9 @@ Authentication Successful.
89
88
```
90
89
91
90
### Multiline input
91
+
92
92
Builtin support for multiple lines.
93
+
93
94
```
94
95
>>> This is \
95
96
... multi line
@@ -99,7 +100,9 @@ Builtin support for multiple lines.
99
100
... as a single argument.
100
101
... EOF
101
102
```
103
+
102
104
User defined
105
+
103
106
``` go
104
107
shell.AddCmd (&ishell.Cmd {
105
108
Name : " multi" ,
@@ -112,7 +115,9 @@ shell.AddCmd(&ishell.Cmd{
112
115
},
113
116
})
114
117
```
118
+
115
119
Execution
120
+
116
121
```
117
122
>>> multi
118
123
Input multiple lines and end with semicolon ';'.
@@ -122,16 +127,21 @@ You wrote:
122
127
this is user defined
123
128
multiline input;
124
129
```
130
+
125
131
### Keyboard interrupt
132
+
126
133
Builtin interrupt handler.
134
+
127
135
```
128
136
>>> ^C
129
137
Input Ctrl-C once more to exit
130
138
>>> ^C
131
139
Interrupted
132
140
exit status 1
133
141
```
142
+
134
143
Custom
144
+
135
145
``` go
136
146
shell.Interrupt (func (count int , c *ishell.Context ) { ... })
137
147
```
@@ -153,7 +163,9 @@ func(c *ishell.Context) {
153
163
}
154
164
},
155
165
```
166
+
156
167
Output
168
+
157
169
```
158
170
What are Go programmers called ?
159
171
Golangers
@@ -163,7 +175,9 @@ What are Go programmers called ?
163
175
164
176
You got it!
165
177
```
178
+
166
179
### Checklist
180
+
167
181
``` go
168
182
func (c *ishell .Context ) {
169
183
languages := []string {" Python" , " Go" , " Haskell" , " Rust" }
@@ -173,7 +187,9 @@ func(c *ishell.Context) {
173
187
c.Println (" Your choices are" , strings.Join (out (), " , " ))
174
188
}
175
189
```
190
+
176
191
Output
192
+
177
193
```
178
194
What are your favourite programming languages ?
179
195
Python
@@ -185,7 +201,9 @@ Your choices are Go, Rust
185
201
```
186
202
187
203
### Progress Bar
204
+
188
205
Determinate
206
+
189
207
``` go
190
208
func (c *ishell .Context ) {
191
209
c.ProgressBar ().Start ()
@@ -197,12 +215,15 @@ func(c *ishell.Context) {
197
215
c.ProgressBar ().Stop ()
198
216
}
199
217
```
218
+
200
219
Output
220
+
201
221
```
202
222
[==========> ] 50%
203
223
```
204
224
205
225
Indeterminate
226
+
206
227
``` go
207
228
208
229
func (c *ishell .Context ) {
@@ -212,12 +233,15 @@ func(c *ishell.Context) {
212
233
c.ProgressBar ().Stop ()
213
234
}
214
235
```
236
+
215
237
Output
238
+
216
239
```
217
240
[ ==== ]
218
241
```
219
242
220
243
Custom display using [ briandowns/spinner] ( https://github.com/briandowns/spinner ) .
244
+
221
245
``` go
222
246
display := ishell.ProgressDisplayCharSet (spinner.CharSets [11 ])
223
247
func (c *Context ) { c.ProgressBar ().Display (display) ... }
@@ -227,13 +251,14 @@ ishell.ProgressBar().Display(display)
227
251
```
228
252
229
253
### Durable history
254
+
230
255
``` go
231
256
// Read and write history to $HOME/.ishell_history
232
257
shell.SetHomeHistoryPath (" .ishell_history" )
233
258
```
234
259
235
-
236
260
### Non-interactive execution
261
+
237
262
In some situations it is desired to exit the program directly after executing a single command.
238
263
239
264
``` go
@@ -256,8 +281,8 @@ $ go run main.go exit greet Someusername
256
281
Hello Someusername
257
282
```
258
283
259
-
260
284
### Output with Color
285
+
261
286
You can use [ fatih/color] ( https://github.com/fatih/color ) .
262
287
263
288
``` go
@@ -266,56 +291,65 @@ func(c *ishell.Context) {
266
291
c.Println (yellow (" This line is yellow" ))
267
292
}
268
293
```
294
+
269
295
Execution
296
+
270
297
``` sh
271
298
>>> color
272
299
This line is yellow
273
300
```
274
301
275
-
276
302
### Example
303
+
277
304
Available [ here] ( https://github.com/abiosoft/ishell/blob/master/example/main.go ) .
305
+
278
306
``` sh
279
307
go run example/main.go
280
308
```
281
309
282
310
## Supported Platforms
283
- * [x] Linux
284
- * [x] OSX
285
- * [x] Windows [ Not tested but should work]
311
+
312
+ - [x] Linux
313
+ - [x] OSX
314
+ - [x] Windows [ Not tested but should work]
286
315
287
316
## Note
317
+
288
318
ishell is in active development and can still change significantly.
289
319
290
320
## Roadmap (in no particular order)
291
- * [x] Multiline inputs
292
- * [x] Command history
293
- * [x] Customizable tab completion
294
- * [x] Handle ^C interrupts
295
- * [x] Subcommands and help texts
296
- * [x] Scrollable paged output
297
- * [x] Progress bar
298
- * [x] Multiple choice prompt
299
- * [x] Checklist prompt
300
- * [x] Support for command aliases
301
- * [ ] Multiple line progress bars
302
- * [ ] Testing, testing, testing
321
+
322
+ - [x] Multiline inputs
323
+ - [x] Command history
324
+ - [x] Customizable tab completion
325
+ - [x] Handle ^C interrupts
326
+ - [x] Subcommands and help texts
327
+ - [x] Scrollable paged output
328
+ - [x] Progress bar
329
+ - [x] Multiple choice prompt
330
+ - [x] Checklist prompt
331
+ - [x] Support for command aliases
332
+ - [ ] Multiple line progress bars
333
+ - [ ] Testing, testing, testing
303
334
304
335
## Contribution
336
+
305
337
1 . Create an issue to discuss it.
306
338
2 . Send in Pull Request.
307
339
308
340
## License
341
+
309
342
MIT
310
343
311
344
## Credits
312
- Library | Use
313
- ------- | -----
314
- [ github.com/flynn-archive/go-shlex] ( https://github.com/flynn-archive/go-shlex ) | splitting input into command and args.
315
- [ github.com/chzyer/readline] ( https://github.com/chzyer/readline ) | readline capabilities.
316
345
346
+ | Library | Use |
347
+ | ------------------------------------------------------------------------------ | -------------------------------------- |
348
+ | [ github.com/flynn-archive/go-shlex] ( https://github.com/flynn-archive/go-shlex ) | splitting input into command and args. |
349
+ | [ github.com/chzyer/readline] ( https://github.com/chzyer/readline ) | readline capabilities. |
317
350
318
351
## Donate
352
+
319
353
```
320
354
bitcoin: 1GTHYEDiy2C7RzXn5nY4wVRaEN2GvLjwZN
321
355
0 commit comments