Adding prompt for the client

This commit is contained in:
Denis-Cosmin Nutiu 2017-11-09 23:03:00 +02:00
parent 0f365c8a15
commit dae792a0f5

View file

@ -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> ")
}