|
|
|
|
@@ -21,6 +21,7 @@
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
#include <wctype.h>
|
|
|
|
|
#include <termios.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
@@ -874,11 +875,13 @@ goto_line(void)
|
|
|
|
|
if (lineno < 1 || lineno >= editor.nrows) {
|
|
|
|
|
editor_set_status("Line number must be between 1 and %d.",
|
|
|
|
|
editor.nrows);
|
|
|
|
|
free(query);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
editor.cury = lineno - 1;
|
|
|
|
|
editor.rowoffs = editor.cury - (editor.rows / 2);
|
|
|
|
|
free(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1449,7 +1452,7 @@ editor_prompt(char *prompt, void (*cb)(char *, int16_t))
|
|
|
|
|
while (1) {
|
|
|
|
|
editor_set_status(prompt, buf);
|
|
|
|
|
display_refresh();
|
|
|
|
|
while ((c = get_keypress()) <= 0) ;
|
|
|
|
|
while ((c = get_keypress()) <= 0);
|
|
|
|
|
if (c == DEL_KEY || c == CTRL_KEY('h') || c == BACKSPACE) {
|
|
|
|
|
if (buflen != 0) {
|
|
|
|
|
buf[--buflen] = '\0';
|
|
|
|
|
@@ -1469,7 +1472,7 @@ editor_prompt(char *prompt, void (*cb)(char *, int16_t))
|
|
|
|
|
}
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
} else if ((c == TAB_KEY) || (c >= 0x20 && c != 0x7f)) {
|
|
|
|
|
} else if ((c == TAB_KEY) || (c >= 0x20 && c < 0x7f)) {
|
|
|
|
|
if (buflen == bufsz - 1) {
|
|
|
|
|
bufsz *= 2;
|
|
|
|
|
buf = realloc(buf, bufsz);
|
|
|
|
|
@@ -1587,6 +1590,41 @@ editor_openfile(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
first_nonwhitespace(struct erow *row)
|
|
|
|
|
{
|
|
|
|
|
int pos;
|
|
|
|
|
wchar_t wc;
|
|
|
|
|
mbstate_t state;
|
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
|
|
if (row == NULL) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof(state));
|
|
|
|
|
pos = 0;
|
|
|
|
|
while (pos < row->size) {
|
|
|
|
|
len = mbrtowc(&wc, &row->line[pos], row->size - pos, &state);
|
|
|
|
|
if (len == (size_t) -1 || len == (size_t) -2) {
|
|
|
|
|
/* Invalid or incomplete sequence, stop here */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (len == 0) {
|
|
|
|
|
/* Null character, stop here */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!iswspace(wc)) {
|
|
|
|
|
/* Found non-whitespace character */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pos += len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
move_cursor(int16_t c)
|
|
|
|
|
{
|
|
|
|
|
@@ -1600,12 +1638,20 @@ move_cursor(int16_t c)
|
|
|
|
|
case CTRL_KEY('p'):
|
|
|
|
|
if (editor.cury > 0) {
|
|
|
|
|
editor.cury--;
|
|
|
|
|
row = (editor.cury >= editor.nrows)
|
|
|
|
|
? NULL
|
|
|
|
|
: &editor.row[editor.cury];
|
|
|
|
|
editor.curx = first_nonwhitespace(row);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ARROW_DOWN:
|
|
|
|
|
case CTRL_KEY('n'):
|
|
|
|
|
if (editor.cury < editor.nrows) {
|
|
|
|
|
editor.cury++;
|
|
|
|
|
row = (editor.cury >= editor.nrows)
|
|
|
|
|
? NULL
|
|
|
|
|
: &editor.row[editor.cury];
|
|
|
|
|
editor.curx = first_nonwhitespace(row);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ARROW_RIGHT:
|
|
|
|
|
@@ -1620,7 +1666,10 @@ move_cursor(int16_t c)
|
|
|
|
|
}
|
|
|
|
|
} else if (row && editor.curx == row->size) {
|
|
|
|
|
editor.cury++;
|
|
|
|
|
editor.curx = 0;
|
|
|
|
|
row = (editor.cury >= editor.nrows)
|
|
|
|
|
? NULL
|
|
|
|
|
: &editor.row[editor.cury];
|
|
|
|
|
editor.curx = first_nonwhitespace(row);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ARROW_LEFT:
|
|
|
|
|
@@ -1752,13 +1801,11 @@ get_cloc_code_lines(const char* filename)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
|
|
|
|
// Remove trailing newline
|
|
|
|
|
len = strlen(buffer);
|
|
|
|
|
if (len > 0 && buffer[len - 1] == '\n') {
|
|
|
|
|
buffer[len - 1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Allocate and copy the string
|
|
|
|
|
result = malloc(strlen(buffer) + 1);
|
|
|
|
|
assert(result != NULL);
|
|
|
|
|
if (result) {
|
|
|
|
|
@@ -2312,7 +2359,6 @@ loop(void)
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
// Set locale for proper UTF-8 handling
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
|
|
|
|
|
setup_terminal();
|
|
|
|
|
|