staging #28
@ -52,6 +52,7 @@ type Interaction struct {
|
|||||||
SlugManager slug.Manager
|
SlugManager slug.Manager
|
||||||
Forwarder Forwarder
|
Forwarder Forwarder
|
||||||
Lifecycle Lifecycle
|
Lifecycle Lifecycle
|
||||||
|
pendingExit bool
|
||||||
updateClientSlug func(oldSlug, newSlug string) bool
|
updateClientSlug func(oldSlug, newSlug string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +95,27 @@ func (i *Interaction) HandleUserInput() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if i.pendingExit {
|
||||||
|
if char != 3 {
|
||||||
|
i.pendingExit = false
|
||||||
|
i.SendMessage("Operation canceled.\r\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if char == 3 {
|
||||||
|
if i.pendingExit {
|
||||||
|
i.SendMessage("Closing connection...\r\n")
|
||||||
|
err = i.Lifecycle.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to close session: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
i.SendMessage("Please press Ctrl+C again to disconnect.\r\n")
|
||||||
|
i.pendingExit = true
|
||||||
|
}
|
||||||
|
|
||||||
i.SendMessage(string(buf[:n]))
|
i.SendMessage(string(buf[:n]))
|
||||||
|
|
||||||
if char == 8 || char == 127 {
|
if char == 8 || char == 127 {
|
||||||
@ -122,6 +144,11 @@ func (i *Interaction) HandleUserInput() {
|
|||||||
}
|
}
|
||||||
i.CommandBuffer.WriteByte(char)
|
i.CommandBuffer.WriteByte(char)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if char == 13 {
|
||||||
|
i.SendMessage("\033[K")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +156,7 @@ func (i *Interaction) HandleUserInput() {
|
|||||||
func (i *Interaction) HandleSlugEditMode(connection ssh.Channel, char byte) {
|
func (i *Interaction) HandleSlugEditMode(connection ssh.Channel, char byte) {
|
||||||
if char == 13 {
|
if char == 13 {
|
||||||
i.HandleSlugSave(connection)
|
i.HandleSlugSave(connection)
|
||||||
} else if char == 27 {
|
} else if char == 27 || char == 3 {
|
||||||
i.HandleSlugCancel(connection)
|
i.HandleSlugCancel(connection)
|
||||||
} else if char == 8 || char == 127 {
|
} else if char == 8 || char == 127 {
|
||||||
if len(i.EditSlug) > 0 {
|
if len(i.EditSlug) > 0 {
|
||||||
@ -310,7 +337,7 @@ func (i *Interaction) HandleSlugUpdateError() {
|
|||||||
func (i *Interaction) HandleCommand(command string) {
|
func (i *Interaction) HandleCommand(command string) {
|
||||||
switch command {
|
switch command {
|
||||||
case "/bye":
|
case "/bye":
|
||||||
i.SendMessage("\r\nClosing connection...")
|
i.SendMessage("Closing connection...\r\n")
|
||||||
err := i.Lifecycle.Close()
|
err := i.Lifecycle.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to close session: %v", err)
|
log.Printf("failed to close session: %v", err)
|
||||||
@ -343,7 +370,7 @@ func (i *Interaction) HandleCommand(command string) {
|
|||||||
i.SendMessage("➤ " + i.EditSlug + "." + utils.Getenv("domain"))
|
i.SendMessage("➤ " + i.EditSlug + "." + utils.Getenv("domain"))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
i.SendMessage("Unknown command")
|
i.SendMessage("Unknown command\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
i.CommandBuffer.Reset()
|
i.CommandBuffer.Reset()
|
||||||
|
|||||||
Reference in New Issue
Block a user