abiosoft/ishell được TopGit xếp vào nhóm công cụ cho lập trình viên, với 1.8k sao trên GitHub, viết chủ yếu bằng Go. Library for creating interactive cli applications.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
ishell is an interactive shell library for creating interactive cli applications.
Usage
import "strings"
import "github.com/abiosoft/ishell/v2"
func main(){
// create new shell.
// by default, new shell includes 'exit', 'help' and 'clear' commands.
shell := ishell.New()
// display welcome info.
shell.Println("Sample Interactive Shell")
// register a function for "greet" command.
shell.AddCmd(&ishell.Cmd{
Name: "greet",
Help: "greet user",
Func: func(c *ishell.Context) {
c.Println("Hello", strings.Join(c.Args, " "))
},
})
// run shell
shell.Run()
}
Execution
Sample Interactive Shell
>>> help
Commands:
clear clear the screen
greet greet user
exit exit the program
help display help
>>> greet Someone Somewhere
Hello Someone Somewhere
>>> exit
$
Reading input
// simulate an authentication
shell.AddCmd(&ishell.Cmd{
Name: "login",
Help: "simulate a login",
Func: func(c *ishell.Context) {
// disable the '>>>' for cleaner same line input.
c.ShowPrompt(false)
defer c.ShowPrompt(true) // yes, revert after login.
// get username
c.Print("Username: ")
username := c.ReadLine()
// get password.
c.Print("Password: ")
password := c.ReadPassword()
... // do something with username and password
c.Println("Authentication Successful.")
},
})
>>> This is \
... multi line
>>> Cool that << EOF
... everything here goes
... as a single argument.
... EOF
User defined
shell.AddCmd(&ishell.Cmd{
Name: "multi",
Help: "input in multiple lines",
Func: func(c *ishell.Context) {
c.Println("Input multiple lines and end with semicolon ';'.")
lines := c.ReadMultiLines(";")
c.Println("Done reading. You wrote:")
c.Println(lines)
},
})
Execution
>>> multi
Input multiple lines and end with semicolon ';'.
>>> this is user defined
... multiline input;
You wrote:
this is user defined
multiline input;
Keyboard interrupt
Builtin interrupt handler.
>>> ^C
Input Ctrl-C once more to exit
>>> ^C
Interrupted
exit status 1
Custom
shell.Interrupt(func(count int, c *ishell.Context) { ... })
Multiple Choice
func(c *ishell.Context) {
choice := c.MultiChoice([]string{
"Golangers",
"Go programmers",
"Gophers",
"Goers",
}, "What are Go programmers called ?")
if choice == 2 {
c.Println("You got it!")
} else {
c.Println("Sorry, you're wrong.")
}
},
Output
What are Go programmers called ?
Golangers
Go programmers
> Gophers
Goers
You got it!
Checklist
func(c *ishell.Context) {
languages := []string{"Python", "Go", "Haskell", "Rust"}
choices := c.Checklist(languages,
"What are your favourite programming languages ?", nil)
out := func() []string { ... } // convert index to language
c.Println("Your choices are", strings.Join(out(), ", "))
}
Output
What are your favourite programming languages ?
Python
✓ Go
Haskell
>✓ Rust
Your choices are Go, Rust
Progress Bar
Determinate
func(c *ishell.Context) {
c.ProgressBar().Start()
for i := 0; i < 101; i++ {
c.ProgressBar().Suffix(fmt.Sprint(" ", i, "%"))
c.ProgressBar().Progress(i)
... // some background computation
}
c.ProgressBar().Stop()
}
display := ishell.ProgressDisplayCharSet(spinner.CharSets[11])
func(c *Context) { c.ProgressBar().Display(display) ... }
// or set it globally
ishell.ProgressBar().Display(display)
Durable history
// Read and write history to $HOME/.ishell_history
shell.SetHomeHistoryPath(".ishell_history")
Non-interactive execution
In some situations it is desired to exit the program directly after executing a single command.
// when started with "exit" as first argument, assume non-interactive execution
if len(os.Args) > 1 && os.Args[1] == "exit" {
shell.Process(os.Args[2:]...)
} else {
// start shell
shell.Run()
}
# Run normally - interactive mode:
$ go run main.go
>>> |
# Run non-interactivelly
$ go run main.go exit greet Someusername
Hello Someusername
Output with Color
You can use fatih/color.
func(c *ishell.Context) {
yellow := color.New(color.FgYellow).SprintFunc()
c.Println(yellow("This line is yellow"))
}
Execution
>>> color
This line is yellow
Example
Available here.
go run example/main.go
Supported Platforms
Linux
OSX
Windows [Not tested but should work]
Note
ishell is in active development and can still change significantly.
abiosoft/ishell có 1.8k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/abiosoft/ishell. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
abiosoft/ishell có những chủ đề gì?
GitHub topics của abiosoft/ishell: "cli", "cli-app", "go", "ishell", "readline", "shell". TopGit xếp repo vào nhóm Developer Tools.
abiosoft/ishell có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho abiosoft/ishell. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
abiosoft/ishell còn đang phát triển không?
Commit gần nhất trên abiosoft/ishell là 3.1 năm trước (theo timestamp GitHub). Repo có 213 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
abiosoft/ishell dùng license gì?
abiosoft/ishell phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
abiosoft/ishell viết bằng ngôn ngữ gì?
abiosoft/ishell chủ yếu viết bằng Go. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về abiosoft/ishell ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/abiosoft/ishell là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về ishell?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về ishell.