diff options
-rw-r--r-- | data/default_config.cfg | 24 | ||||
-rw-r--r-- | src/client.py | 4 | ||||
-rw-r--r-- | src/gui.py | 4 | ||||
-rw-r--r-- | src/window.py | 97 |
4 files changed, 126 insertions, 3 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg index 72470335..3b01ed0c 100644 --- a/data/default_config.cfg +++ b/data/default_config.cfg @@ -1,7 +1,29 @@ [Poezio] +# the server. Make sure the server you're using accepts anonymous authentification server = louiz.org + +# the port you'll use to connect port = 5222 + +# the resource you will use resource = poezio + +# the nick you will use when joining a room with no associated nick default_nick = poezio -rooms = poezio@conference.codingteam.net:discussion@chat.jabberfr.org + +# the rooms you will join automatically on startup, with associated nickname or not +rooms = poezio@conference.codingteam.net:discussion@kikoo.louiz.org + +# the completion type you will use to complete nicknames +# if "normal", complete the entire name to the first available completion +# and then cycle through the possible completion with the next TABs +# if "shell", if there's more than one nick for this completion, complete +# only the part that all then nicks have in common (like in a shell) +completion = normal + +# what will be put after the name, when using autocompletion +# a SPACE will always be added after that +after_completion = , + +# the file where logs are saved (useless for the moment) logfile = logs diff --git a/src/client.py b/src/client.py index 9840d259..d3561a86 100644 --- a/src/client.py +++ b/src/client.py @@ -20,8 +20,8 @@ import sys # disable any printout (this would mess the display) stderr = sys.stderr -sys.stdout = open('/dev/null', 'w') -sys.stderr = open('/dev/null', 'w') +# sys.stdout = open('/dev/null', 'w') +# sys.stderr = open('/dev/null', 'w') from connection import Connection from multiuserchat import MultiUserChat @@ -201,6 +201,7 @@ class Gui(object): "KEY_F(6)": self.rotate_rooms_right, "kLFT5": self.rotate_rooms_left, "kRIT5": self.rotate_rooms_right, + "\t": self.auto_completion, "KEY_BACKSPACE": self.window.input.key_backspace } @@ -301,6 +302,9 @@ class Gui(object): self.window.new_room(r) self.window.refresh(self.rooms) + def auto_completion(self): + self.window.input.auto_completion(self.current_room().users) + def rotate_rooms_right(self, args=None): self.current_room().set_color_state(11) self.rooms.append(self.rooms.pop(0)) diff --git a/src/window.py b/src/window.py index 93daa87c..e697a495 100644 --- a/src/window.py +++ b/src/window.py @@ -18,6 +18,7 @@ # along with Poezio. If not, see <http://www.gnu.org/licenses/>. import curses +from config import config class Win(object): def __init__(self, height, width, y, x, parent_win): @@ -213,6 +214,8 @@ class Input(Win): self.text = u'' self.pos = 0 self.histo_pos = 0 + self.hit_list = [] # current possible completion (normal) + self.last_key_tab = False # True if we are cycling through possible completion def resize(self, height, width, y, x, stdscr, visible): self.visible = visible @@ -226,6 +229,7 @@ class Input(Win): """delete char""" if self.pos == len(self.text): return + self.reset_completion() (y, x) = self.win.getyx() self.text = self.text[:self.pos]+self.text[self.pos+1:] self.win.delch(y, x) @@ -234,6 +238,7 @@ class Input(Win): def key_up(self): if not len(self.history): return + self.reset_completion() self.win.clear() if self.histo_pos >= 0: self.histo_pos -= 1 @@ -248,6 +253,7 @@ class Input(Win): def key_down(self): if not len(self.history): return + self.reset_completion() self.win.clear() if self.histo_pos < len(self.history)-1: self.histo_pos += 1 @@ -264,6 +270,7 @@ class Input(Win): self.refresh() def key_home(self): + self.reset_completion() self.pos = 0 if len(self.text) >= self.width-1: txt = self.text[:self.width-1] @@ -273,6 +280,7 @@ class Input(Win): self.refresh() def key_end(self): + self.reset_completion() self.pos = len(self.text) if len(self.text) >= self.width-1: txt = self.text[-(self.width-1):] @@ -284,6 +292,7 @@ class Input(Win): self.refresh() def key_left(self): + self.reset_completion() (y, x) = self.win.getyx() if self.pos > 0: self.pos -= 1 @@ -297,6 +306,7 @@ class Input(Win): self.refresh() def key_right(self): + self.reset_completion() (y, x) = self.win.getyx() if self.pos < len(self.text): self.pos += 1 @@ -311,6 +321,7 @@ class Input(Win): self.refresh() def key_backspace(self): + self.reset_completion() (y, x) = self.win.getyx() if len(self.text) > 0 and self.pos != 0: self.text = self.text[:self.pos-1]+self.text[self.pos:] @@ -318,7 +329,93 @@ class Input(Win): self.win.delch(y, x-1) self.refresh() + def auto_completion(self, user_list): + if self.pos != len(self.text) or len(self.text) == 0: + return # we don't complete if cursos is not at the end of line + completion_type = config.get('completion', 'normal') + if completion_type == 'shell': + self.shell_completion(user_list) + else: + self.normal_completion(user_list) + + def reset_completion(self): + self.hit_list = [] + self.last_key_tab = False + + def normal_completion(self, user_list): + after = config.get('after_completion', ',')+" " + (y, x) = self.win.getyx() + if not self.last_key_tab: + # begin is the begining of the nick we want to complete + begin = self.text.split()[-1].encode('utf-8').lower() + hit_list = [] # list of matching nicks + for user in user_list: + if user.nick.lower().startswith(begin): + hit_list.append(user.nick) + if len(hit_list) == 0: + return + self.last_key_tab = True + self.hit_list = hit_list + end = len(begin) + else: + begin = self.text[:-len(after)].split()[-1].encode('utf-8').lower() + self.hit_list.append(self.hit_list.pop(0)) # rotate list + end = len(begin) + len(after) + x -= end + self.win.move(y, x) + # remove begin from the line + self.win.clrtoeol() + self.text = self.text[:-end] + nick = self.hit_list[0] # take the first hit + self.text += nick+after + self.pos = len(self.text) + self.win.addstr(nick+after) + self.refresh() + + def shell_completion(self, user_list): + after = config.get('after_completion', ',')+" " + (y, x) = self.win.getyx() + begin = self.text.split()[-1].encode('utf-8').lower() + hit_list = [] # list of matching nicks + for user in user_list: + if user.nick.lower().startswith(begin): + hit_list.append(user.nick) + if len(hit_list) == 0: + return + end = False + nick = '' + last_key_tab = self.last_key_tab + self.last_key_tab = True + if len(hit_list) == 1: + nick = hit_list[0] + after + self.last_key_tab = False + elif last_key_tab: + for n in hit_list: + if begin.lower() == n.lower(): + nick = n+after # user DO want this completion (tabbed twice on it) + self.last_key_tab = False + if nick == '': + while not end and len(nick) < len(hit_list[0]): + nick = hit_list[0][:len(nick)+1] + for hit in hit_list: + if not hit.lower().startswith(nick.lower()): + end = True + break + if end: + nick = nick[:-1] + x -= len(begin) + self.win.move(y, x) + # remove begin from the line + self.win.clrtoeol() + self.text = self.text[:-len(begin)] + self.text += nick + self.pos = len(self.text) + self.win.addstr(nick) + self.refresh() + + def do_command(self, key): + self.reset_completion() (y, x) = self.win.getyx() if x == self.width-1: self.win.delch(0, 0) |