Comments (1)
go-prompt just provides prompt.Document
object to completer functions.
And you can access all buffer information via it.
When you input a following text(period means the cursor position):
help commandA
. <- cursor position
In this case,
document.TextBeforeCursor()
returnshelp comm
document.GetWordBeforeCursor()
returnscomm
So you can implement that like:
func completer(d prompt.Document) []prompt.Suggest {
tbc := d.TextBeforeCursor()
args := strings.Split(tbc, " ")
depth := len()
switch depth {
case 1:
suggests := []prompt.Suggest{
{Text: "help", "i would my shell to show all valid commands"},
{Text: "commandA", "..."},
}
return prompt.FilterHasPrefix(suggests, d.GetWordBeforeCursor())
case 2:
switch args[0] {
case "help":
suggests := []prompt.Suggest{
{Text: "commandA", "i would like to show help message for "commandA""},
{Text: "commandB", "..."},
}
return prompt.FilterHasPrefix(suggests, d.GetWordBeforeCursor())
case "commandA":
// return subcommand suggestions of commandA
}
case 3:
switch strings.Join(args[:1], " ") {
case "help commandA":
suggests := []prompt.Suggest{
{Text: "subcommandA", "would show help command for commandA subcommandA"},
{Text: "subcommandB", "..."},
}
return suggests
}
}
}
from go-prompt.
Related Issues (20)
- [Feature Request] Example for Simple Yes/No/Quit question?
- Update README: `aws-sso` uses go-prompt
- [Feature Request] Option to escape special characters or quote strings containing special characters
- [Feature Request] MacOS keyboard support is not complete
- Sorry for the delayed response. I've just pushed v0.2.6 tag.
- [Feature Request] Need a way to terminate unresponsive executors HOT 1
- [Bug]Strange bug when using `fmt.Scanln` after upgrade to v0.2.6 HOT 1
- [Bug] `prompt.Input` leaks file descriptor of "/dev/tty"
- [Question] Force prompt.Input() redraw during goroutine
- Allow specifiying arbitrary io.ReadWriters to read input and write output to (including escape codes)
- [Bug] Unexpected behavior of log output HOT 1
- How to customize suggestion rendering?
- [Bug] Terminal Colors not reset after application exists HOT 2
- [Bug] In the v0.2.6 , the icnl attribute of the stty is modified, but the attribute is not restored. v0.2.5 is ok HOT 5
- A CI/CD Observability Solution Suggestion
- Project FireQL using go-prompt HOT 1
- GPT cli An interactive ChatGPT client featuring shortcuts and auto-complete - thanks to go-prompt
- [Feature Request]
- [Feature Request] Allow for TTYs other than STDIN
- [Bug] panic: runtime error: integer divide by zero
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-prompt.