mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-23 04:00:31 +03:00
commit
ca580264f0
@ -71,7 +71,7 @@ things up with `make run`.
|
||||
* [x] set term width properly
|
||||
* [x] client map rather than list
|
||||
* [x] backfill chat history
|
||||
* [ ] tab completion
|
||||
* [x] tab completion
|
||||
* [x] /ban
|
||||
* [ ] /ban by ip
|
||||
* [x] /help
|
||||
@ -88,7 +88,7 @@ things up with `make run`.
|
||||
* [ ] More tests.
|
||||
* [ ] Even more tests.
|
||||
* [ ] Lots of refactoring
|
||||
* [ ] Pull out the chat-related stuff into isolation from the ssh serving
|
||||
* [ ] Pull out the chat-related stuff into isolation from the ssh serving
|
||||
stuff
|
||||
|
||||
|
||||
|
@ -29,7 +29,6 @@ const ABOUT_TEXT string = `-> ssh-chat is made by @shazow.
|
||||
|
||||
For more, visit shazow.net or follow at twitter.com/shazow
|
||||
`
|
||||
|
||||
type Client struct {
|
||||
Server *Server
|
||||
Conn *ssh.ServerConn
|
||||
@ -56,7 +55,7 @@ func NewClient(server *Server, conn *ssh.ServerConn) *Client {
|
||||
}
|
||||
|
||||
func (c *Client) ColoredName() string {
|
||||
return ColorString(c.Color, c.Name)
|
||||
return ColorString(c.Color, c.Name)
|
||||
}
|
||||
|
||||
func (c *Client) Write(msg string) {
|
||||
@ -257,6 +256,8 @@ func (c *Client) handleChannels(channels <-chan ssh.NewChannel) {
|
||||
defer channel.Close()
|
||||
|
||||
c.term = terminal.NewTerminal(channel, prompt)
|
||||
c.term.AutoCompleteCallback = c.Server.AutoCompleteFunction
|
||||
|
||||
for req := range requests {
|
||||
var width, height int
|
||||
var ok bool
|
||||
|
22
server.go
22
server.go
@ -273,6 +273,28 @@ func (s *Server) Start(laddr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) AutoCompleteFunction(line string, pos int, key rune) (newLine string, newPos int, ok bool) {
|
||||
if key == 9 {
|
||||
shortLine := strings.Split(line[:pos], " ")
|
||||
partialNick := shortLine[len(shortLine)-1]
|
||||
|
||||
nicks := s.List(&partialNick)
|
||||
if len(nicks) > 0 {
|
||||
nick := nicks[len(nicks)-1]
|
||||
posPartialNick := pos - len(partialNick)
|
||||
|
||||
newLine = strings.Replace(line[posPartialNick:],
|
||||
partialNick, nick, 1)
|
||||
newLine = line[:posPartialNick] + newLine
|
||||
newPos = pos + (len(nick) - len(partialNick))
|
||||
ok = true
|
||||
}
|
||||
} else {
|
||||
ok = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Server) Stop() {
|
||||
for _, client := range s.clients {
|
||||
client.Conn.Close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user