summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-11-01 07:01:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-11-01 07:01:18 -0700
commita997f22131a7c98505cebcc88f3badd67a50518d (patch)
treeb3094e7df08962db3db06af5a7222d7949f61df4
parentb8e093dbaae99d2dc12157fcce1bb12ba26b8d3e (diff)
downloadtxr-a997f22131a7c98505cebcc88f3badd67a50518d.tar.gz
txr-a997f22131a7c98505cebcc88f3badd67a50518d.tar.bz2
txr-a997f22131a7c98505cebcc88f3badd67a50518d.zip
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.
-rw-r--r--linenoise/linenoise.c6
1 files 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) {