frontend: fix all compiler warnings
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "line-ed.h"
|
#include "line-ed.h"
|
||||||
|
|
||||||
const char *line_start(struct line_ed *ed, unsigned int y)
|
const char *line_start(struct line_ed *ed, size_t y)
|
||||||
{
|
{
|
||||||
const char *line = ed->l_buf;
|
const char *line = ed->l_buf;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < y; i++) {
|
for (size_t i = 0; i < y; i++) {
|
||||||
line += strcspn(line, "\n");
|
line += strcspn(line, "\n");
|
||||||
|
|
||||||
if (*line == '\n') {
|
if (*line == '\n') {
|
||||||
@@ -16,11 +16,11 @@ const char *line_start(struct line_ed *ed, unsigned int y)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int line_length(struct line_ed *ed, unsigned int y)
|
size_t line_length(struct line_ed *ed, size_t y)
|
||||||
{
|
{
|
||||||
const char *line = ed->l_buf;
|
const char *line = ed->l_buf;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < y; i++) {
|
for (size_t i = 0; i < y; i++) {
|
||||||
line += strcspn(line, "\n");
|
line += strcspn(line, "\n");
|
||||||
if (*line == '\n') {
|
if (*line == '\n') {
|
||||||
line++;
|
line++;
|
||||||
@@ -31,7 +31,7 @@ unsigned int line_length(struct line_ed *ed, unsigned int y)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int len = strcspn(line, "\n");
|
size_t len = strcspn(line, "\n");
|
||||||
if (line[len] == '\n') {
|
if (line[len] == '\n') {
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
#ifndef LINE_ED_BUFFER_H_
|
#ifndef LINE_ED_BUFFER_H_
|
||||||
#define LINE_ED_BUFFER_H_
|
#define LINE_ED_BUFFER_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
struct line_ed;
|
struct line_ed;
|
||||||
|
|
||||||
/* returns a pointer to the start of the line based on the given `y`
|
/* returns a pointer to the start of the line based on the given `y`
|
||||||
* coordinate */
|
* coordinate */
|
||||||
extern const char *line_start(struct line_ed *ed, unsigned int y);
|
extern const char *line_start(struct line_ed *ed, size_t y);
|
||||||
/* returns the length of the line based on the given `y` coordinate.
|
/* returns the length of the line based on the given `y` coordinate.
|
||||||
* for any line other than the last line in the buffer, this length
|
* for any line other than the last line in the buffer, this length
|
||||||
* INCLUDES the trailing linefeed. */
|
* INCLUDES the trailing linefeed. */
|
||||||
extern unsigned int line_length(struct line_ed *ed, unsigned int y);
|
extern size_t line_length(struct line_ed *ed, size_t y);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
|
|
||||||
void line_ed_coords_to_physical_coords(struct line_ed *ed,
|
void line_ed_coords_to_physical_coords(
|
||||||
unsigned int x, unsigned int y,
|
struct line_ed *ed, size_t x, size_t y, size_t *out_x, size_t *out_y)
|
||||||
unsigned int *out_x, unsigned int *out_y)
|
|
||||||
{
|
{
|
||||||
unsigned int prompt_len = 0;
|
size_t prompt_len = 0;
|
||||||
if (ed->l_cursor_y == 0) {
|
if (ed->l_cursor_y == 0) {
|
||||||
prompt_len = prompt_length(ed, PROMPT_MAIN);
|
prompt_len = prompt_length(ed, PROMPT_MAIN);
|
||||||
} else if (ed->l_cursor_y <= ed->l_continuations) {
|
} else if (ed->l_cursor_y <= ed->l_continuations) {
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
struct line_ed;
|
struct line_ed;
|
||||||
|
|
||||||
extern void line_ed_coords_to_physical_coords(struct line_ed *ed,
|
extern void line_ed_coords_to_physical_coords(
|
||||||
unsigned int x, unsigned int y,
|
struct line_ed *ed, size_t x, size_t y, size_t *out_x, size_t *out_y);
|
||||||
unsigned int *out_x, unsigned int *out_y);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void load_buf_from_history(struct line_ed *ed)
|
|||||||
{
|
{
|
||||||
b_string *cur = (b_string *)b_array_at(ed->l_history, ed->l_history_pos);
|
b_string *cur = (b_string *)b_array_at(ed->l_history, ed->l_history_pos);
|
||||||
size_t len
|
size_t len
|
||||||
= MIN(ed->l_buf_end - ed->l_buf - 1,
|
= MIN((size_t)(ed->l_buf_end - ed->l_buf - 1),
|
||||||
b_string_get_size(cur, B_STRLEN_NORMAL));
|
b_string_get_size(cur, B_STRLEN_NORMAL));
|
||||||
|
|
||||||
memcpy(ed->l_buf, b_string_ptr(cur), len);
|
memcpy(ed->l_buf, b_string_ptr(cur), len);
|
||||||
@@ -57,7 +57,7 @@ void load_buf_from_history(struct line_ed *ed)
|
|||||||
|
|
||||||
const char *last_history_line(struct line_ed *ed)
|
const char *last_history_line(struct line_ed *ed)
|
||||||
{
|
{
|
||||||
unsigned long nlines = b_array_size(ed->l_history);
|
size_t nlines = b_array_size(ed->l_history);
|
||||||
if (nlines < 2) {
|
if (nlines < 2) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int compare_coords(
|
int compare_coords(size_t ax, size_t ay, size_t bx, size_t by)
|
||||||
unsigned int ax, unsigned int ay, unsigned int bx, unsigned int by)
|
|
||||||
{
|
{
|
||||||
if (ay > by) {
|
if (ay > by) {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -29,7 +28,7 @@ int compare_coords(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hl_range *get_hl_range(struct line_ed *ed, unsigned int x, unsigned int y)
|
struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y)
|
||||||
{
|
{
|
||||||
if (b_queue_empty(&ed->l_hl_ranges)) {
|
if (b_queue_empty(&ed->l_hl_ranges)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -64,7 +63,7 @@ struct hl_range *get_next_hl_range(struct hl_range *range)
|
|||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
int apply_hl_range(struct hl_range *range, b_tty *tty, unsigned int x, unsigned int y)
|
int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
|
||||||
{
|
{
|
||||||
if (!range) {
|
if (!range) {
|
||||||
b_tty_reset_vmode(tty);
|
b_tty_reset_vmode(tty);
|
||||||
@@ -90,8 +89,8 @@ int apply_hl_range(struct hl_range *range, b_tty *tty, unsigned int x, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct hl_range *create_highlight(
|
struct hl_range *create_highlight(
|
||||||
unsigned long start_x, unsigned long start_y, unsigned long end_x,
|
size_t start_x, size_t start_y, size_t end_x, size_t end_y,
|
||||||
unsigned long end_y, const b_tty_vmode *vmode)
|
const b_tty_vmode *vmode)
|
||||||
{
|
{
|
||||||
struct hl_range *out = malloc(sizeof *out);
|
struct hl_range *out = malloc(sizeof *out);
|
||||||
if (!out) {
|
if (!out) {
|
||||||
@@ -280,7 +279,7 @@ void line_ed_print_highlights(struct line_ed *ed)
|
|||||||
b_queue_iterator it;
|
b_queue_iterator it;
|
||||||
b_queue_foreach (&it, &ed->l_hl_ranges) {
|
b_queue_foreach (&it, &ed->l_hl_ranges) {
|
||||||
struct hl_range *h = b_unbox(struct hl_range, it.entry, h_entry);
|
struct hl_range *h = b_unbox(struct hl_range, it.entry, h_entry);
|
||||||
printf("(%u, %u) -> (%u, %u)\n", h->h_start_x, h->h_start_y,
|
printf("(%zu, %zu) -> (%zu, %zu)\n", h->h_start_x, h->h_start_y,
|
||||||
h->h_end_x, h->h_end_y);
|
h->h_end_x, h->h_end_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,23 +18,20 @@ enum hl_range_comparison {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct hl_range {
|
struct hl_range {
|
||||||
unsigned int h_start_x, h_start_y;
|
size_t h_start_x, h_start_y;
|
||||||
unsigned int h_end_x, h_end_y;
|
size_t h_end_x, h_end_y;
|
||||||
b_tty_vmode h_vmode;
|
b_tty_vmode h_vmode;
|
||||||
b_queue_entry h_entry;
|
b_queue_entry h_entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int compare_coords(
|
extern int compare_coords(size_t ax, size_t ay, size_t bx, size_t by);
|
||||||
unsigned int ax, unsigned int ay, unsigned int bx, unsigned int by);
|
extern struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y);
|
||||||
extern struct hl_range *get_hl_range(
|
|
||||||
struct line_ed *ed, unsigned int x, unsigned int y);
|
|
||||||
extern struct hl_range *get_next_hl_range(struct hl_range *range);
|
extern struct hl_range *get_next_hl_range(struct hl_range *range);
|
||||||
extern int apply_hl_range(
|
extern int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y);
|
||||||
struct hl_range *range, b_tty *tty, unsigned int x, unsigned int y);
|
|
||||||
|
|
||||||
extern struct hl_range *create_highlight(
|
extern struct hl_range *create_highlight(
|
||||||
unsigned long start_x, unsigned long start_y, unsigned long end_x,
|
size_t start_x, size_t start_y, size_t end_x, size_t end_y,
|
||||||
unsigned long end_y, const struct b_tty_vmode *vmode);
|
const struct b_tty_vmode *vmode);
|
||||||
extern enum hl_range_comparison compare_hl_ranges(
|
extern enum hl_range_comparison compare_hl_ranges(
|
||||||
const struct hl_range *a, const struct hl_range *b);
|
const struct hl_range *a, const struct hl_range *b);
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ void put_char(struct line_ed *ed, char c)
|
|||||||
.r_prev_cursor_y = ed->l_cursor_y,
|
.r_prev_cursor_y = ed->l_cursor_y,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int prev_cursor = ed->l_buf_ptr - ed->l_buf;
|
size_t prev_cursor = ed->l_buf_ptr - ed->l_buf;
|
||||||
|
|
||||||
char *dest = ed->l_buf_ptr;
|
char *dest = ed->l_buf_ptr;
|
||||||
unsigned int len = ed->l_line_end - ed->l_buf_ptr + 1;
|
size_t len = ed->l_line_end - ed->l_buf_ptr + 1;
|
||||||
|
|
||||||
if (dest < ed->l_line_end) {
|
if (dest < ed->l_line_end) {
|
||||||
memmove(dest + 1, dest, len);
|
memmove(dest + 1, dest, len);
|
||||||
@@ -53,10 +53,10 @@ static void backspace_simple(struct line_ed *ed)
|
|||||||
.r_prev_cursor_y = ed->l_cursor_y,
|
.r_prev_cursor_y = ed->l_cursor_y,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int prev_cursor = ed->l_buf_ptr - ed->l_buf;
|
size_t prev_cursor = ed->l_buf_ptr - ed->l_buf;
|
||||||
|
|
||||||
char *dest = ed->l_buf_ptr;
|
char *dest = ed->l_buf_ptr;
|
||||||
unsigned int len = ed->l_line_end - ed->l_buf_ptr + 1;
|
size_t len = ed->l_line_end - ed->l_buf_ptr + 1;
|
||||||
memmove(dest - 1, dest, len);
|
memmove(dest - 1, dest, len);
|
||||||
|
|
||||||
ed->l_cursor_x--;
|
ed->l_cursor_x--;
|
||||||
@@ -70,7 +70,7 @@ static void backspace_simple(struct line_ed *ed)
|
|||||||
|
|
||||||
static void backspace_nl(struct line_ed *ed)
|
static void backspace_nl(struct line_ed *ed)
|
||||||
{
|
{
|
||||||
unsigned int prev_line_len = line_length(ed, ed->l_cursor_y - 1);
|
size_t prev_line_len = line_length(ed, ed->l_cursor_y - 1);
|
||||||
|
|
||||||
struct refresh_state state = {
|
struct refresh_state state = {
|
||||||
.r_prev_cursor_x = ed->l_cursor_x,
|
.r_prev_cursor_x = ed->l_cursor_x,
|
||||||
@@ -79,7 +79,7 @@ static void backspace_nl(struct line_ed *ed)
|
|||||||
};
|
};
|
||||||
|
|
||||||
char *dest = ed->l_buf_ptr;
|
char *dest = ed->l_buf_ptr;
|
||||||
unsigned int len = ed->l_line_end - ed->l_buf_ptr + 1;
|
size_t len = ed->l_line_end - ed->l_buf_ptr + 1;
|
||||||
memmove(dest - 1, dest, len);
|
memmove(dest - 1, dest, len);
|
||||||
|
|
||||||
ed->l_cursor_x = prev_line_len - 1;
|
ed->l_cursor_x = prev_line_len - 1;
|
||||||
@@ -126,17 +126,17 @@ void cursor_left(struct line_ed *ed)
|
|||||||
|
|
||||||
ed->l_cursor_y--;
|
ed->l_cursor_y--;
|
||||||
ed->l_buf_ptr--;
|
ed->l_buf_ptr--;
|
||||||
unsigned int prompt_len = 0;
|
size_t prompt_len = 0;
|
||||||
if (ed->l_cursor_y == 0) {
|
if (ed->l_cursor_y == 0) {
|
||||||
prompt_len = prompt_length(ed, PROMPT_MAIN);
|
prompt_len = prompt_length(ed, PROMPT_MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int len = line_length(ed, ed->l_cursor_y);
|
size_t len = line_length(ed, ed->l_cursor_y);
|
||||||
ed->l_cursor_x = len - 1;
|
ed->l_cursor_x = len - 1;
|
||||||
|
|
||||||
//printf("\033[A\033[%dG", len + prompt_len);
|
//printf("\033[A\033[%dG", len + prompt_len);
|
||||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, len + prompt_len);
|
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, (int)(len + prompt_len));
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
@@ -178,12 +178,12 @@ void arrow_up(struct line_ed *ed)
|
|||||||
|
|
||||||
if (ed->l_cursor_y > 0) {
|
if (ed->l_cursor_y > 0) {
|
||||||
//printf("\033[%uA", ed->l_cursor_y);
|
//printf("\033[%uA", ed->l_cursor_y);
|
||||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, ed->l_cursor_y);
|
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, (long long)ed->l_cursor_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
|
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
|
||||||
b_tty_move_cursor_x(
|
b_tty_move_cursor_x(
|
||||||
ed->l_tty, B_TTY_POS_START, prompt_length(ed, PROMPT_MAIN));
|
ed->l_tty, B_TTY_POS_START, (long long)prompt_length(ed, PROMPT_MAIN));
|
||||||
b_tty_clear(ed->l_tty, B_TTY_CLEAR_SCREEN | B_TTY_CLEAR_FROM_CURSOR);
|
b_tty_clear(ed->l_tty, B_TTY_CLEAR_SCREEN | B_TTY_CLEAR_FROM_CURSOR);
|
||||||
|
|
||||||
save_buf_to_history(ed);
|
save_buf_to_history(ed);
|
||||||
@@ -202,7 +202,7 @@ void arrow_down(struct line_ed *ed)
|
|||||||
|
|
||||||
if (ed->l_cursor_y > 0) {
|
if (ed->l_cursor_y > 0) {
|
||||||
//printf("\033[%uA", ed->l_cursor_y);
|
//printf("\033[%uA", ed->l_cursor_y);
|
||||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, ed->l_cursor_y);
|
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, (int)ed->l_cursor_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
|
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ static enum ivy_status readline(
|
|||||||
struct line_ed *ed = LINE_ED_FROM_LEX_SOURCE(src);
|
struct line_ed *ed = LINE_ED_FROM_LEX_SOURCE(src);
|
||||||
|
|
||||||
line_ed_set_scope_type(ed, scope_type);
|
line_ed_set_scope_type(ed, scope_type);
|
||||||
long r = line_ed_readline(ed, out, max);
|
size_t r = line_ed_readline(ed, out, max);
|
||||||
line_ed_set_scope_type(ed, NULL);
|
line_ed_set_scope_type(ed, NULL);
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
@@ -102,10 +102,10 @@ static void clear_buffer(struct line_ed *ed)
|
|||||||
static void convert_continuation_feeds(char *s, size_t max)
|
static void convert_continuation_feeds(char *s, size_t max)
|
||||||
{
|
{
|
||||||
char *end = s + max;
|
char *end = s + max;
|
||||||
unsigned int len = strlen(s);
|
size_t len = strlen(s);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int r = strcspn(s, "\\");
|
size_t r = strcspn(s, "\\");
|
||||||
if (s + r > end) {
|
if (s + r > end) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -130,10 +130,10 @@ static void convert_continuation_feeds(char *s, size_t max)
|
|||||||
static void remove_continuation_feeds(char *s, size_t max)
|
static void remove_continuation_feeds(char *s, size_t max)
|
||||||
{
|
{
|
||||||
char *end = s + max;
|
char *end = s + max;
|
||||||
unsigned int len = strlen(s);
|
size_t len = strlen(s);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int r = strcspn(s, "\\");
|
size_t r = strcspn(s, "\\");
|
||||||
if (s + r > end) {
|
if (s + r > end) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -167,12 +167,12 @@ static bool input_is_empty(struct line_ed *ed)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
long line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
|
||||||
{
|
{
|
||||||
clear_buffer(ed);
|
clear_buffer(ed);
|
||||||
|
|
||||||
bool append_history = false;
|
bool append_history = false;
|
||||||
unsigned int append_to_index = (unsigned int)-1;
|
size_t append_to_index = (size_t)-1;
|
||||||
if (!ed->l_scope_type) {
|
if (!ed->l_scope_type) {
|
||||||
alloc_empty_history_entry(ed);
|
alloc_empty_history_entry(ed);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ struct line_ed {
|
|||||||
char *l_line_end;
|
char *l_line_end;
|
||||||
/* 2-dimensional coordinates of the current cursor position.
|
/* 2-dimensional coordinates of the current cursor position.
|
||||||
* this does NOT include any prompts that are visible on the terminal */
|
* this does NOT include any prompts that are visible on the terminal */
|
||||||
unsigned int l_cursor_x, l_cursor_y;
|
size_t l_cursor_x, l_cursor_y;
|
||||||
/* the number of line continuations that have been inputted */
|
/* the number of line continuations that have been inputted */
|
||||||
unsigned int l_continuations;
|
unsigned int l_continuations;
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ struct line_ed {
|
|||||||
/* array of previously entered commands */
|
/* array of previously entered commands */
|
||||||
b_array *l_history;
|
b_array *l_history;
|
||||||
/* index of the currently selected history entry */
|
/* index of the currently selected history entry */
|
||||||
unsigned int l_history_pos;
|
size_t l_history_pos;
|
||||||
|
|
||||||
/* list of defined highlight ranges */
|
/* list of defined highlight ranges */
|
||||||
b_queue l_hl_ranges;
|
b_queue l_hl_ranges;
|
||||||
@@ -89,7 +89,7 @@ extern void line_ed_print_highlights(struct line_ed *ed);
|
|||||||
extern void line_ed_add_hook(struct line_ed *ed, struct line_ed_hook *hook);
|
extern void line_ed_add_hook(struct line_ed *ed, struct line_ed_hook *hook);
|
||||||
extern void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook);
|
extern void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook);
|
||||||
|
|
||||||
extern long line_ed_readline(struct line_ed *ed, char *out, size_t max);
|
extern size_t line_ed_readline(struct line_ed *ed, char *out, size_t max);
|
||||||
|
|
||||||
static inline struct ivy_line_source *line_ed_to_line_source(struct line_ed *ed)
|
static inline struct ivy_line_source *line_ed_to_line_source(struct line_ed *ed)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void show_prompt(struct line_ed *ed)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long prompt_length(struct line_ed *ed, int prompt_id)
|
size_t prompt_length(struct line_ed *ed, int prompt_id)
|
||||||
{
|
{
|
||||||
return strlen(ed->l_prompt[prompt_id]);
|
return strlen(ed->l_prompt[prompt_id]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
struct line_ed;
|
struct line_ed;
|
||||||
|
|
||||||
extern void show_prompt(struct line_ed *ed);
|
extern void show_prompt(struct line_ed *ed);
|
||||||
extern unsigned long prompt_length(struct line_ed *ed, int prompt_id);
|
extern size_t prompt_length(struct line_ed *ed, int prompt_id);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,12 +14,12 @@
|
|||||||
* the (x, y) coordinates provided should be the data coordinates of the
|
* the (x, y) coordinates provided should be the data coordinates of the
|
||||||
* first character in `s`.
|
* first character in `s`.
|
||||||
*/
|
*/
|
||||||
void print_text(struct line_ed *ed, unsigned int x, unsigned int y, const char *s)
|
void print_text(struct line_ed *ed, size_t x, size_t y, const char *s)
|
||||||
{
|
{
|
||||||
b_tty *tty = ed->l_tty;
|
b_tty *tty = ed->l_tty;
|
||||||
struct hl_range *cur_range = get_hl_range(ed, x, y);
|
struct hl_range *cur_range = get_hl_range(ed, x, y);
|
||||||
|
|
||||||
for (unsigned int i = 0; s[i] != '\n' && s[i] != '\0'; i++) {
|
for (size_t i = 0; s[i] != '\n' && s[i] != '\0'; i++) {
|
||||||
if (!cur_range) {
|
if (!cur_range) {
|
||||||
b_tty_reset_vmode(tty);
|
b_tty_reset_vmode(tty);
|
||||||
fputc(s[i], stdout);
|
fputc(s[i], stdout);
|
||||||
@@ -96,18 +96,18 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
|
|||||||
size_t line_len = strcspn(line_buf, "\n");
|
size_t line_len = strcspn(line_buf, "\n");
|
||||||
|
|
||||||
/* the index of the first char in line_buf that needs to be reprinted */
|
/* the index of the first char in line_buf that needs to be reprinted */
|
||||||
int start_x = state->r_prev_cursor_x;
|
size_t start_x = state->r_prev_cursor_x;
|
||||||
|
|
||||||
/* the distance between the first char to be reprinted and the end
|
/* the distance between the first char to be reprinted and the end
|
||||||
* of the line.
|
* of the line.
|
||||||
* the physical cursor will be moved back by this amount after the
|
* the physical cursor will be moved back by this amount after the
|
||||||
* line is reprinted. */
|
* line is reprinted. */
|
||||||
int cursor_rdelta = (int)(line_len - start_x);
|
long cursor_rdelta = (long)(line_len - start_x);
|
||||||
|
|
||||||
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
||||||
if (start_x) {
|
if (start_x) {
|
||||||
//fprintf(stdout, "\033[%uD", start_x);
|
//fprintf(stdout, "\033[%uD", start_x);
|
||||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -start_x);
|
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -(long long)start_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
start_x = 0;
|
start_x = 0;
|
||||||
@@ -148,14 +148,14 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
|
|||||||
|
|
||||||
/* the index of the first char in line_buf that needs to be reprinted.
|
/* the index of the first char in line_buf that needs to be reprinted.
|
||||||
* subtract one to account for the linefeed that has since been deleted. */
|
* subtract one to account for the linefeed that has since been deleted. */
|
||||||
unsigned int start_x = state->r_prev_line_len - 1;
|
size_t start_x = state->r_prev_line_len - 1;
|
||||||
|
|
||||||
/* the column to move the physical cursor to after it has been moved
|
/* the column to move the physical cursor to after it has been moved
|
||||||
* to the previous line.
|
* to the previous line.
|
||||||
* NOTE that this number includes the length of the prompt!
|
* NOTE that this number includes the length of the prompt!
|
||||||
* we add 1 to start_x to ensure that the cursor is moved to the cell
|
* we add 1 to start_x to ensure that the cursor is moved to the cell
|
||||||
* AFTER the last char of the line. */
|
* AFTER the last char of the line. */
|
||||||
unsigned int new_x;
|
size_t new_x;
|
||||||
line_ed_coords_to_physical_coords(ed, start_x + 1, ed->l_cursor_y, &new_x, NULL);
|
line_ed_coords_to_physical_coords(ed, start_x + 1, ed->l_cursor_y, &new_x, NULL);
|
||||||
|
|
||||||
/* the physical cursor is currently at the beginning of the line that
|
/* the physical cursor is currently at the beginning of the line that
|
||||||
@@ -166,7 +166,7 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
|
|||||||
|
|
||||||
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
||||||
/* next, move the physical cursor up and to the beginning of the previous line */
|
/* next, move the physical cursor up and to the beginning of the previous line */
|
||||||
unsigned int tmp_x;
|
size_t tmp_x;
|
||||||
line_ed_coords_to_physical_coords(ed, 0, ed->l_cursor_y, &tmp_x, NULL);
|
line_ed_coords_to_physical_coords(ed, 0, ed->l_cursor_y, &tmp_x, NULL);
|
||||||
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
|
||||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, tmp_x);
|
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, tmp_x);
|
||||||
@@ -181,7 +181,7 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
|
|||||||
|
|
||||||
/* now reprint all of the buffer lines, starting with the first of the
|
/* now reprint all of the buffer lines, starting with the first of the
|
||||||
* two lines that were concatenated. */
|
* two lines that were concatenated. */
|
||||||
unsigned int ydiff = 0;
|
size_t ydiff = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
print_text(ed, start_x, ed->l_cursor_y + ydiff, line_buf + start_x);
|
print_text(ed, start_x, ed->l_cursor_y + ydiff, line_buf + start_x);
|
||||||
|
|
||||||
@@ -220,19 +220,19 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
|
|||||||
size_t line_len = strcspn(line_buf, "\n");
|
size_t line_len = strcspn(line_buf, "\n");
|
||||||
|
|
||||||
/* the index of the first char in line_buf that needs to be reprinted */
|
/* the index of the first char in line_buf that needs to be reprinted */
|
||||||
int start_x = ed->l_cursor_x;
|
size_t start_x = ed->l_cursor_x;
|
||||||
//get_data_cursor_position(ed, &start_x, NULL);
|
//get_data_cursor_position(ed, &start_x, NULL);
|
||||||
|
|
||||||
/* the distance between the first char to be reprinted and the end
|
/* the distance between the first char to be reprinted and the end
|
||||||
* of the line.
|
* of the line.
|
||||||
* the physical cursor will be moved back by this amount after the
|
* the physical cursor will be moved back by this amount after the
|
||||||
* line is reprinted. */
|
* line is reprinted. */
|
||||||
int cursor_rdelta = (int)(line_len - start_x);
|
long long cursor_rdelta = (long long)(line_len - start_x);
|
||||||
|
|
||||||
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
|
||||||
if (start_x) {
|
if (start_x) {
|
||||||
//fprintf(stdout, "\033[%uD", start_x);
|
//fprintf(stdout, "\033[%uD", start_x);
|
||||||
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -start_x);
|
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -(long long)start_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
start_x = 0;
|
start_x = 0;
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ struct line_ed;
|
|||||||
|
|
||||||
struct refresh_state {
|
struct refresh_state {
|
||||||
/* cursor position before the update was performed (excluding the prompt) */
|
/* cursor position before the update was performed (excluding the prompt) */
|
||||||
unsigned int r_prev_cursor_x, r_prev_cursor_y;
|
size_t r_prev_cursor_x, r_prev_cursor_y;
|
||||||
/* when a backspace results in two separate lines being combined,
|
/* when a backspace results in two separate lines being combined,
|
||||||
* this property contains the length of the first of the two combined
|
* this property contains the length of the first of the two combined
|
||||||
* lines BEFORE the concotenation was performed */
|
* lines BEFORE the concotenation was performed */
|
||||||
unsigned int r_prev_line_len;
|
size_t r_prev_line_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void print_text(struct line_ed *ed, unsigned int x, unsigned int y, const char *s);
|
extern void print_text(struct line_ed *ed, size_t x, size_t y, const char *s);
|
||||||
extern void print_buffer(struct line_ed *ed);
|
extern void print_buffer(struct line_ed *ed);
|
||||||
extern void put_refresh(struct line_ed *ed, struct refresh_state *state);
|
extern void put_refresh(struct line_ed *ed, struct refresh_state *state);
|
||||||
extern void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state);
|
extern void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state);
|
||||||
|
|||||||
Reference in New Issue
Block a user