Adding prompt for the client
This commit is contained in:
parent
0f365c8a15
commit
dae792a0f5
1 changed files with 16 additions and 0 deletions
|
@ -66,6 +66,13 @@ func HandleConnection(client Client) {
|
|||
|
||||
// Process input
|
||||
input := bufio.NewScanner(client.Connection())
|
||||
|
||||
stack, ok := client.Stack().(*StringStack)
|
||||
if ok == false {
|
||||
panic("Cannot cast client.Stack() to *StringStack!")
|
||||
}
|
||||
|
||||
prompt(client, stack)
|
||||
for input.Scan() {
|
||||
log.Println(client.Connection().RemoteAddr(), ":", input.Text())
|
||||
|
||||
|
@ -74,8 +81,17 @@ func HandleConnection(client Client) {
|
|||
log.Println(err)
|
||||
io.WriteString(client.Connection(), err.Error()+"\n")
|
||||
}
|
||||
prompt(client, stack)
|
||||
}
|
||||
|
||||
// Client has left.
|
||||
log.Println(client.Connection().RemoteAddr(), "has disconnected.")
|
||||
}
|
||||
|
||||
func prompt(client Client, stack *StringStack) (int, error) {
|
||||
var str string
|
||||
if !stack.IsEmpty() {
|
||||
str = stack.Top().(string) + " "
|
||||
}
|
||||
return io.WriteString(client.Connection(), str+"ftp> ")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue