Comments (11)
Gonna bring this up the priority list. No ETA but working on the fix.
from ishell.
Ideally, shell must have started before prompt shows up. And that's why feed(c)
outputs before the prompt.
Just to be clear, what is the expected behaviour ?
from ishell.
I want to permanently listen to a channel that will print some info in the shell from time to time.
package main
import (
"time"
"github.com/abiosoft/ishell"
)
func feed(c chan string) {
time.Sleep(2*time.Second)
for i := 0; i<3; i++ {
c <- "Feedback"
time.Sleep(time.Second)
}
}
func main(){
shell := ishell.New()
c := make(chan string)
shell.AddCmd(&ishell.Cmd{
Name: "hi",
Help: "hello",
Func: func(ctx *ishell.Context) {
ctx.Println("Hello")
go feed(c)
},
})
// listen
go func() {
for msg := range(c) {
shell.Println(msg)
}
}()
shell.Start()
}
This outputs:
>>> hi
Hello
>>> Feedback
Feedback
Feedback
The desired behavior is:
>>> hi
Hello
>>>
Feedback
Feedback
Feedback
>>>
from ishell.
Ideally I would like to have a shell print channel to where I can throw output in from goroutines
from ishell.
You think a call to Println
should not print on the same line as the prompt ?
from ishell.
Yes: if it can do the job it would be fine. It should preserve the text being typed:
>>> typing someth
Feedback
>>> typing someth
from ishell.
I would not totally agree with always printing on the next line as the password prompt in the example shows a use case. https://github.com/abiosoft/ishell/blob/master/example/main.go#L118.
I will try to find a middle ground and will also try to make it safe to have calls to Print
from multiple goroutines.
from ishell.
Hi, any progress on this? Do you have plans for resolving this?
It could benefit to my user case: a client that permanently receives some messages and print them to the screen. The fact that printing them with ctx.Println
messes up with the prompt make it uncomfortable to use when lots of messages are coming in.
from ishell.
I tried putting together a chat-style app and had real problems trying to print an incoming message without interrupting the prompt. Any in-progress input got printed multiple times in the terminal and it wasn't lining up. It seems there should be some way to print output that is independent of whatever input is happening.
from ishell.
I'm also running into this issue for printing background log lines, which now mess up the prompt.
I can see that repurposing the current Print/Prinln functions might not what is needed (though they are a bit weird now: AFAICS Print replaces the prompt content, but appends to the prompt on screen, while Println empties the prompt but not reshows the prompt).
Ideally, when printing a log line or similar, you would:
- Erase the current prompt
- Print the log line, with a newline
- Print the prompt again, including anything typed already
I guess this would warrant a new function, something like shell.PrintlnBeforePrompt()
? This is probably fairly easy to do as above for full lines.
Implementing something like shell.PrintBeforePrompt()
(so without a newline) would be more tricky, since that should (I guess) append to the existing line before the prompt, which probably requires keeping track of the current cursor position (or erasing the newline before the prompt, but I'm not sure if terminals can actually do this). In any case, just printing full lines, with a newline, are probably sufficient for most usecases?
from ishell.
You can fix this problem like this:
package main
import (
"time"
"github.com/abiosoft/readline"
"github.com/abiosoft/ishell"
)
func feed(c chan string) {
for i := 0; i<3; i++ {
c <- "Feedback"
time.Sleep(time.Second)
}
}
func main(){
rl, _ := readline.NewEx(&readline.Config{
Prompt: "\033[31m»\033[0m ",
InterruptPrompt: "^C",
EOFPrompt: "exit",
HistorySearchFold: true,
})
shell = ishell.NewWithReadline(rl)
c := make(chan string)
// listen
go func() {
for msg := range(c) {
rl.Write([]byte(msg))
}
}()
// this does output correctly
//feed(c)
this does not
go feed(c)
shell. Start()
}
from ishell.
Related Issues (20)
- sort is not supported for commands list for autocomplete
- support multiline for unclosed quotes
- Clear screen not working? HOT 1
- Support to deal with ctrl-z HOT 1
- Extraneous space for multiline args
- Run command automatically on startup
- No release version for the latest code
- Expose ReadlineWithDefault HOT 1
- context
- Export lifecycle
- ishell example requires package main as the first line
- QUESTION - How to print prompt back after getting async message HOT 3
- Subshell or previous context save HOT 1
- QUESTION - SSH Channel Print Content disorder
- Not friendly to non ascii characters HOT 1
- Keyboard interrupt on MultiChoice abruptly exits the shell HOT 2
- Example of multiple level subcommands HOT 1
- do not support auto logout ?
- Support for multi-lines based on opening/closing brakcets/braces
- Interrupt handler is not invoked when in ReadLine
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 ishell.