Skip to content

Commit

Permalink
perf: add ssh terminal title
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc authored and ibuler committed Nov 25, 2020
1 parent d81378b commit fce6860
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/proxy/dbproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ func (p *DBProxyServer) Proxy() {
p.sendConnectErrorMsg(err)
return
}
title := fmt.Sprintf("%s://%s@%s",
p.SystemUser.Protocol,
p.SystemUser.Username,
p.Database.Attrs.Host)
utils.IgnoreErrWriteWindowTitle(p.UserConn, title)
logger.Infof("Conn[%s] get database conn success", p.UserConn.ID())
_ = sw.Bridge(p.UserConn, srvConn)
logger.Infof("Conn[%s] end database session %s bridge", p.UserConn.ID(), sw.ID)
Expand Down
4 changes: 4 additions & 0 deletions pkg/proxy/k8sproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func (p *K8sProxyServer) Proxy() {
p.sendConnectErrorMsg(err)
return
}
title := fmt.Sprintf("%s+%s",
p.SystemUser.Protocol,
p.Cluster.Attrs.Cluster)
utils.IgnoreErrWriteWindowTitle(p.UserConn, title)
logger.Infof("Conn[%s] get k8s conn success", p.UserConn.ID())
_ = sw.Bridge(p.UserConn, srvConn)
logger.Infof("Conn[%s] end k8s session %s bridge", p.UserConn.ID(), sw.ID)
Expand Down
5 changes: 5 additions & 0 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ func (p *ProxyServer) Proxy() {
p.sendConnectErrorMsg(err)
return
}
title := fmt.Sprintf("%s://%s@%s",
p.SystemUser.Protocol,
p.SystemUser.Username,
p.Asset.IP)
utils.IgnoreErrWriteWindowTitle(p.UserConn, title)
logger.Infof("Conn[%s] getting srv conn success", p.UserConn.ID())
_ = sw.Bridge(p.UserConn, srvConn)
logger.Infof("Conn[%s] end session %s bridge", p.UserConn.ID(), sw.ID)
Expand Down
7 changes: 7 additions & 0 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ func WrapperWarn(text string) string {
text += "\n\r"
return WrapperString(text, Red)
}

func IgnoreErrWriteWindowTitle(writer io.Writer, title string) {
// OSC Ps ; Pt BEL
// OSC Ps ; Pt ST
// Ps = 2 ⇒ Change Window Title to Pt.
_, _ = writer.Write([]byte(fmt.Sprintf("\x1b]2;%s\x07", title)))
}

0 comments on commit fce6860

Please sign in to comment.