From a997f22131a7c98505cebcc88f3badd67a50518d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku <kaz@kylheku.com> Date: Thu, 1 Nov 2018 07:01:18 -0700 Subject: linenoise: move modulo operation into function. * linenoise/linenoise.c (col_offset_in_str): Take a cols parameter and wrap the return value into the number of columns. (refresh_multiline): No need to do the % cols operation on the return value of col_offset_in_str any more; just pass cols down into it. --- linenoise/linenoise.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index f3784597..62a2c31e 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1121,12 +1121,12 @@ static struct row_values screen_rows(const wchar_t *str, int pos, int cols) return out; } -static int col_offset_in_str(const wchar_t *str, int pos) +static int col_offset_in_str(const wchar_t *str, int pos, int cols) { int offs = 0; while (pos > 0 && str[--pos] != '\n') offs++; - return offs; + return offs % cols; } /* Multi line low level line refresh. @@ -1199,7 +1199,7 @@ static void refresh_multiline(lino_t *l) { /* Move cursor to the correct column */ { - int ccol = col_offset_in_str(l->buf, l->pos) % l->cols; + int ccol = col_offset_in_str(l->buf, l->pos, l->cols); /* Go up till we reach the expected positon. */ if (rows - nrow > 0) { -- cgit v1.2.3