completion is now sorted by last_talked. fixed #1712
This commit is contained in:
parent
eb36e08e11
commit
05928d592f
4 changed files with 21 additions and 30 deletions
23
src/gui.py
23
src/gui.py
|
@ -264,29 +264,18 @@ class Gui(object):
|
||||||
"""
|
"""
|
||||||
def compare_users(a, b):
|
def compare_users(a, b):
|
||||||
"""
|
"""
|
||||||
Used to sort users by their availability
|
Used to sort users by their last_talked
|
||||||
"""
|
"""
|
||||||
if a.show == b.show:
|
if not a.last_talked and b.last_talked:
|
||||||
return 0
|
return 0
|
||||||
if a.show is None:
|
elif not b.last_talked and a.last_talked:
|
||||||
return -1
|
return 1
|
||||||
|
if a.last_talked < b.last_talked:
|
||||||
return 1
|
return 1
|
||||||
if len(self.window.input.text) == 0:
|
|
||||||
self.last_talked_completion()
|
|
||||||
else:
|
else:
|
||||||
|
return -1
|
||||||
self.window.input.auto_completion([user.nick for user in sorted(self.current_room().users, compare_users)])
|
self.window.input.auto_completion([user.nick for user in sorted(self.current_room().users, compare_users)])
|
||||||
|
|
||||||
def last_talked_completion(self):
|
|
||||||
"""
|
|
||||||
If tab is used while the input is empty, insert the nickname
|
|
||||||
of the last person who spoke
|
|
||||||
"""
|
|
||||||
for msg in self.current_room().messages[::-1]:
|
|
||||||
if msg.nickname is not None and msg.nickname != self.current_room().own_nick:
|
|
||||||
self.window.input.text = msg.nickname+config.get('after_completion', ',')+" "
|
|
||||||
self.window.input.key_end()
|
|
||||||
return
|
|
||||||
|
|
||||||
def last_words_completion(self):
|
def last_words_completion(self):
|
||||||
"""
|
"""
|
||||||
Complete the input with words recently said
|
Complete the input with words recently said
|
||||||
|
|
|
@ -23,8 +23,6 @@ of the time ONE char, but may be longer if it's a keyboard
|
||||||
shortcut, like ^A, M-a or KEY_RESIZE)
|
shortcut, like ^A, M-a or KEY_RESIZE)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from common import debug
|
|
||||||
|
|
||||||
def get_next_byte(s):
|
def get_next_byte(s):
|
||||||
"""
|
"""
|
||||||
Read the next byte of the utf-8 char
|
Read the next byte of the utf-8 char
|
||||||
|
@ -54,15 +52,12 @@ def read_char(s):
|
||||||
(first, c) = get_next_byte(s)
|
(first, c) = get_next_byte(s)
|
||||||
char = "M-"+c
|
char = "M-"+c
|
||||||
if 194 <= first:
|
if 194 <= first:
|
||||||
debug('1\n')
|
|
||||||
(code, c) = get_next_byte(s) # 2 bytes char
|
(code, c) = get_next_byte(s) # 2 bytes char
|
||||||
char += c
|
char += c
|
||||||
if 224 <= first:
|
if 224 <= first:
|
||||||
debug('2\n')
|
|
||||||
(code, c) = get_next_byte(s) # 3 bytes char
|
(code, c) = get_next_byte(s) # 3 bytes char
|
||||||
char += c
|
char += c
|
||||||
if 240 <= first:
|
if 240 <= first:
|
||||||
debug('3\n')
|
|
||||||
(code, c) = get_next_byte(s) # 4 bytes char
|
(code, c) = get_next_byte(s) # 4 bytes char
|
||||||
char += c
|
char += c
|
||||||
return char
|
return char
|
||||||
|
|
|
@ -59,5 +59,6 @@ class User(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<user.User object nick:%s show:%s(%s) status:%s affiliation:%s>"\
|
return ">%s<" % (self.nick.decode('utf-8'))
|
||||||
% (self.nick, self.show, type(self.show), self.status, self.affiliation)
|
# return "<user.User object nick:%s show:%s(%s) status:%s affiliation:%s>"\
|
||||||
|
# % (self.nick.decode('utf-8'), self.show, type(self.show), self.status, self.affiliation)
|
||||||
|
|
|
@ -541,10 +541,10 @@ class Input(Win):
|
||||||
"""
|
"""
|
||||||
Complete the nickname
|
Complete the nickname
|
||||||
"""
|
"""
|
||||||
if self.pos+self.line_pos != len(self.text) or len(self.text) == 0:
|
if self.pos+self.line_pos != len(self.text): # or len(self.text) == 0
|
||||||
return # we don't complete if cursor is not at the end of line
|
return # we don't complete if cursor is not at the end of line
|
||||||
completion_type = config.get('completion', 'normal')
|
completion_type = config.get('completion', 'normal')
|
||||||
if completion_type == 'shell':
|
if completion_type == 'shell' and self.text != '':
|
||||||
self.shell_completion(user_list)
|
self.shell_completion(user_list)
|
||||||
else:
|
else:
|
||||||
self.normal_completion(user_list)
|
self.normal_completion(user_list)
|
||||||
|
@ -567,7 +567,10 @@ class Input(Win):
|
||||||
(y, x) = self.win.getyx()
|
(y, x) = self.win.getyx()
|
||||||
if not self.last_key_tab:
|
if not self.last_key_tab:
|
||||||
# begin is the begining of the nick we want to complete
|
# begin is the begining of the nick we want to complete
|
||||||
|
if self.text != '':
|
||||||
begin = self.text.split()[-1].encode('utf-8').lower()
|
begin = self.text.split()[-1].encode('utf-8').lower()
|
||||||
|
else:
|
||||||
|
begin = ''
|
||||||
hit_list = [] # list of matching nicks
|
hit_list = [] # list of matching nicks
|
||||||
for user in user_list:
|
for user in user_list:
|
||||||
if user.lower().startswith(begin):
|
if user.lower().startswith(begin):
|
||||||
|
@ -595,7 +598,10 @@ class Input(Win):
|
||||||
else:
|
else:
|
||||||
after = config.get('after_completion', ',')+" "
|
after = config.get('after_completion', ',')+" "
|
||||||
(y, x) = self.win.getyx()
|
(y, x) = self.win.getyx()
|
||||||
|
if self.text != '':
|
||||||
begin = self.text.split()[-1].encode('utf-8').lower()
|
begin = self.text.split()[-1].encode('utf-8').lower()
|
||||||
|
else:
|
||||||
|
begin = ''
|
||||||
hit_list = [] # list of matching nicks
|
hit_list = [] # list of matching nicks
|
||||||
for user in user_list:
|
for user in user_list:
|
||||||
if user.lower().startswith(begin):
|
if user.lower().startswith(begin):
|
||||||
|
|
Loading…
Reference in a new issue