diff options
author | Madhur Garg <madhurgarg96@gmail.com> | 2019-06-06 03:50:34 +0530 |
---|---|---|
committer | Madhur Garg <madhurgarg96@gmail.com> | 2019-06-20 03:09:30 +0530 |
commit | b2c38497d499017c31d1d27538569afc9a4562cd (patch) | |
tree | 661e5058334a45c3bd7e080ffa3e1c50de405ac8 | |
parent | d8f53e82662fb2d9e445605b4552538e3ef4187c (diff) | |
download | poezio-b2c38497d499017c31d1d27538569afc9a4562cd.tar.gz poezio-b2c38497d499017c31d1d27538569afc9a4562cd.tar.bz2 poezio-b2c38497d499017c31d1d27538569afc9a4562cd.tar.xz poezio-b2c38497d499017c31d1d27538569afc9a4562cd.zip |
Code work for /sb goto <+|-linecount>|<linenum>|<timestamp>
-rw-r--r-- | poezio/tabs/basetabs.py | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index bf2ef9d9..f90f1a2b 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -809,19 +809,47 @@ class ChatTab(Tab): self.text_win.rebuild_everything(self._text_buffer) self.core.refresh_window() elif args[0] == 'status': - self.core.information('Total %s lines in this tab.' %len(self.text_win.built_lines), 'Info') + self.core.information('Total %s lines in this tab.' % len(self.text_win.built_lines), 'Info') elif len(args) == 2 and args[0] == 'goto': - try: - datetime.strptime(args[1], '%Y-%m-%d %H:%M:%S') - except ValueError: - if '+' in args[1]: - scroll_len = args[1].strip('+') + for fmt in ('%d %H:%M', '%d %H:%M:%S', '%d:%m %H:%M', '%d:%m %H:%M:%S', '%H:%M', '%H:%M:%S'): + try: + new_date = datetime.strptime(args[1], fmt) + if 'm' and 'd' in fmt: + new_date = new_date.replace(year=datetime.now().year) + elif 'd' in fmt: + new_date = new_date.replace(year=datetime.now().year, month=datetime.now().month) + else: + new_date = new_date.replace(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day) + except ValueError: + pass + if '-' in args[1]: + if ' ' in args[1]: + new_args = args[1].split(' ') + new_args[0] = new_args[0].strip('-') + new_date = datetime.now() + if new_args[0].isdigit(): + new_date = new_date.replace(day=new_date.day - int(new_args[0])) + for fmt in ('%H:%M', '%H:%M:%S'): + try: + arg_date = datetime.strptime(new_args[1], fmt) + new_date = new_date.replace(hour=arg_date.hour, minute=arg_date.minute, second=arg_date.second) + except ValueError: + pass + else: + scroll_len = args[1].strip('-') + if scroll_len.isdigit(): + self.text_win.scroll_down(int(scroll_len)) + self.core.refresh_window() + return + elif '+' in args[1]: + scroll_len = args[1].strip('+') + if scroll_len.isdigit(): self.text_win.scroll_up(int(scroll_len)) self.core.refresh_window() return - elif '-' in args[1]: - scroll_len = args[1].strip('-') - self.text_win.scroll_down(int(scroll_len)) + elif args[1].isdigit(): + if len(self.text_win.built_lines) - self.text_win.height >= int(args[1]): + self.text_win.pos = len(self.text_win.built_lines) - self.text_win.height - int(args[1]) self.core.refresh_window() return else: |