Comments (4)
Thank you for the bug report. Are you able to provide a little more detail please? A screenshot of how it breaks, what "breaks" looks like, and what platform you're running it from (terminal emulator, OS), etc.
I use \n a lot and haven't run into any breakages because of \n however the CLI landscape is a diverse one so without a little more detail it will be impossible for me to replicate your issue and fix the problem.
from readline.
I am extremely sorry for opening the issue here. The issue actually is in readline lib which I am using and when I set
SetPrompt ("User Jhon\n$ ") breaks the shell kind of it repeatedly prints the prompt on every key press. Is there a quick fix or a workaround that I can use the '\n' is important in my case.
Terminal Output :
User Jhon
User Jhon
User Jhon
User Jhon
$ abcd
from readline.
Ahh ok, that makes sense. :)
The prompt it intended to be only a single line by design however the effect you're seeing is definitely readline not handling the new line correctly (it should either strip it or be rewritten to support multi-line prompts).
The reason I say it's not intended to be multi-line "by design" is because the additional helper detail is intended to be supplied via the "hint" text: https://github.com/lmorg/readline/blob/master/instance.go#L59
So you'd have code that might look a little like:
// WARNING: this code has been directly typed into Github and thus untested. So it might not compile verbatim.
rl.SetPrompt("$ ")
rl.HintText = func([]rune, int) []rune {
return []rune("User Jhon")
}()
The idea behind this design is so that the additional line in most people's multi-line prompts can be context aware. Each time you press a key the HintText function (which is the func
you've assigned to the HintText
variable above) gets called with []rune
being the entire text that the user has inputted thus far, and the int
being the cursor position.
This is means you can do some cool stuff like:
// WARNING: this code has been directly typed into Github and thus untested. So it might not compile verbatim.
rl.SetPrompt("$ ")
rl.HintText = func(text []rune, pos int) []rune {
hint := fmt.Sprintf("You have typed: %s\nYour cursor position is %d", string(text), pos)
return []rune(hint)
}()
That all said, I'm not totally against adding multi-line prompt support to readline. It just wasn't part of the original intended design.
As an aside, you can also change the formatting of the hint text via HintFormatting
(https://github.com/lmorg/readline/blob/master/instance.go#L64):
// WARNING: this code has been directly typed into Github and thus untested. So it might not compile verbatim.
rl.SetPrompt("$ ")
rl.HintText = func([]rune, int) []rune {
return []rune("User Jhon")
}()
rl.HintFormatting = "" // no formatting
rl.HintFormatting = "\x1b[41m" // red background
// etc
from readline.
I'm going to close this ticket. If you feel I haven't solved your problem then I'm happy to re-open.
from readline.
Related Issues (3)
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 readline.