From f71af881d287c634941e3bc4b3ce0244479c82bd Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sat, 29 Jul 2017 16:44:05 +0200 Subject: Set correct id on all the lines of a message Instead of only updating the last line printed with the id of the message (ts.minor, set in the date_printed field), update all of the lines that is printed for that message. This is necessary for updating all of the lines on changes, instead of only the last. This will be implemented in the next commit. This assumes that the lines after the first in messages always has an empty prefix, and that the first line of a message always has a prefix. This holds for the messages I have seen (single-line, multi-line as well as me-messages and joins/quits). Other approaches I considered was to count the number of newlines in the message and update the same number of lines, or to check the existing date_printed field of the messages and update the ones that had 10 digits or more (since current timestamps has that, and the slack id currently has 6 digits). However, I dropped them in favor of the prefix solution which seems better. --- wee_slack.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 680ff6b..7fd6313 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2751,10 +2751,17 @@ def modify_print_time(buffer, new_id, time): struct_hdata_line = w.hdata_get('line') struct_hdata_line_data = w.hdata_get('line_data') - # get a pointer to the data in line_pointer via layout of struct_hdata_line - data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data') - if data: - w.hdata_update(struct_hdata_line_data, data, {"date_printed": new_id}) + prefix = '' + while not prefix and line_pointer: + # get a pointer to the data in line_pointer via layout of struct_hdata_line + data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data') + if data: + prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix') + w.hdata_update(struct_hdata_line_data, data, {"date_printed": new_id}) + # move backwards one line and repeat, so all the lines of the message are set + # exit when you reach a prefix, which means you have reached the + # first line of the message, or if you hit the end + line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1) return w.WEECHAT_RC_OK -- cgit From 1cf43894a55ef7c765a573d393a180120b6efa51 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sat, 29 Jul 2017 16:56:32 +0200 Subject: Improve rendering of changes in multiline messages Previously, if a multiline message was edited or reacted to, all of the new message would be crammed into the last line of the already printed message. This change updates each line separately, so if the number of lines in the message doesn't change, the message will still be rendered correctly after edits or reactions. If the number of lines change, the rendering is still improved, however I don't know if it is possible to insert or delete lines in a weechat buffer without re-rendering the whole buffer, so it won't be perfect. If the number of lines of a message decreases after an edit, the extra lines will still be present, but they will be blanked. If the number of lines increases, the first lines will be set as normally, but the last line will contain all of the rest of the lines. --- wee_slack.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 7fd6313..ad196e6 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2716,6 +2716,8 @@ def modify_buffer_line(buffer, new_line, timestamp, time_id): # hold the structure of a line and of line data struct_hdata_line = w.hdata_get('line') struct_hdata_line_data = w.hdata_get('line_data') + # keep track of the number of lines with the matching time and id + number_of_matching_lines = 0 while line_pointer: # get a pointer to the data in line_pointer via layout of struct_hdata_line @@ -2726,13 +2728,25 @@ def modify_buffer_line(buffer, new_line, timestamp, time_id): # prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix') if timestamp == int(line_timestamp) and int(time_id) == line_time_id: - # w.prnt("", "found matching time date is {}, time is {} ".format(timestamp, line_timestamp)) - w.hdata_update(struct_hdata_line_data, data, {"message": new_line}) + number_of_matching_lines += 1 + elif number_of_matching_lines > 0: + # since number_of_matching_lines is non-zero, we have + # already reached the message and can stop traversing break - else: - pass # move backwards one line and try again - exit the while if you hit the end line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1) + + # split the message into at most the number of existing lines + lines = new_line.split('\n', number_of_matching_lines - 1) + # pad the list with empty strings until the number of elements equals + # number_of_matching_lines + lines += [''] * (number_of_matching_lines - len(lines)) + + if line_pointer: + for line in lines: + line_pointer = w.hdata_move(struct_hdata_line, line_pointer, 1) + data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data') + w.hdata_update(struct_hdata_line_data, data, {"message": line}) return w.WEECHAT_RC_OK -- cgit From d2531a9bf46c18fab76d8f9029263b3d3ebbe30b Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sun, 30 Jul 2017 00:59:33 +0200 Subject: Abort modification of message if encountering line without data Not sure if this can happen. The weechat documentation doesn't state that it can, but since the if condition was there, maybe it can. If it can and does happen, abort the modification, which is better than something unexpected happening. --- wee_slack.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index ad196e6..dd8a00d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2733,6 +2733,10 @@ def modify_buffer_line(buffer, new_line, timestamp, time_id): # since number_of_matching_lines is non-zero, we have # already reached the message and can stop traversing break + else: + dbg(('Encountered line without any data while trying to modify ' + 'line. This is not handled, so aborting modification.')) + return w.WEECHAT_RC_ERROR # move backwards one line and try again - exit the while if you hit the end line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1) @@ -2772,6 +2776,9 @@ def modify_print_time(buffer, new_id, time): if data: prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix') w.hdata_update(struct_hdata_line_data, data, {"date_printed": new_id}) + else: + dbg('Encountered line without any data while setting message id.') + return w.WEECHAT_RC_ERROR # move backwards one line and repeat, so all the lines of the message are set # exit when you reach a prefix, which means you have reached the # first line of the message, or if you hit the end -- cgit From 87cc5427814765418c074349e6e40b73349eb863 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Tue, 1 Aug 2017 17:23:07 +0200 Subject: Prevent lines being broken in bare display mode If you update a line with hdata_update and pass a string containing newlines, the buffer will become a bit broken when bare display mode is activated (alt+l). It seems that the newlines are printed in bare mode, but extra lines are not inserted, so the lines are overlapping with each other. Fixes #306 --- wee_slack.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index dd8a00d..7bfa4a9 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2742,6 +2742,9 @@ def modify_buffer_line(buffer, new_line, timestamp, time_id): # split the message into at most the number of existing lines lines = new_line.split('\n', number_of_matching_lines - 1) + # updating a line with a string containing newlines causes the lines to + # be broken when viewed in bare display mode + lines = [line.replace('\n', ' | ') for line in lines] # pad the list with empty strings until the number of elements equals # number_of_matching_lines lines += [''] * (number_of_matching_lines - len(lines)) -- cgit