mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 01:13:02 +01:00
fixed prompt input
This commit is contained in:
parent
3d7fb13847
commit
b9b3487581
@ -360,6 +360,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
int x, y, y2, x2;
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
/* BACKSPACE key: Remove one character from line */
|
||||
if (key == 0x107 || key == 0x8 || key == 0x7f) {
|
||||
if (ctx->pos > 0) {
|
||||
@ -377,7 +378,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
#else
|
||||
if (isprint(key)) {
|
||||
#endif
|
||||
if (ctx->pos < (MAX_STR_SIZE-1)) {
|
||||
if (ctx->pos <= MAX_STR_SIZE) {
|
||||
mvwaddstr(self->window, y, x, wc_to_char(key));
|
||||
ctx->line[ctx->pos++] = key;
|
||||
ctx->line[ctx->pos] = L'\0';
|
||||
@ -390,6 +391,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||
wclrtobot(self->window);
|
||||
bool close_win = false;
|
||||
|
||||
if (line[0] == '/') {
|
||||
if (close_win = !strncmp(line, "/close", strlen("/close"))) {
|
||||
int f_num = self->num;
|
||||
|
@ -367,7 +367,6 @@ void execute(WINDOW *window, ToxWindow *prompt, Tox *m, char *cmd)
|
||||
|
||||
char args[MAX_NUM_ARGS][MAX_STR_SIZE] = {0};
|
||||
int num_args = 0;
|
||||
int i = 0;
|
||||
bool cmd_end = false; // flags when we get to the end of cmd
|
||||
char *end; // points to the end of the current arg
|
||||
|
||||
@ -377,7 +376,7 @@ void execute(WINDOW *window, ToxWindow *prompt, Tox *m, char *cmd)
|
||||
end = strchr(cmd+1, '\"');
|
||||
|
||||
if (end++ == NULL) { /* Increment past the end quote */
|
||||
wprintw(window, "Invalid command. Did you forget a closing \"?\n");
|
||||
wprintw(window, "Invalid argument. Did you forget a closing \"?\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -395,6 +394,8 @@ void execute(WINDOW *window, ToxWindow *prompt, Tox *m, char *cmd)
|
||||
cmd = end;
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
/* match input to command list */
|
||||
for (i = 0; i < NUM_COMMANDS; ++i) {
|
||||
if (strcmp(args[0], commands[i].name) == 0) {
|
||||
|
@ -60,7 +60,7 @@ int string_is_empty(char *string)
|
||||
uint8_t *wcs_to_char(wchar_t *string)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *ret = NULL;
|
||||
uint8_t *ret = NULL;
|
||||
|
||||
len = wcstombs(NULL, string, 0);
|
||||
if (len != (size_t) -1) {
|
||||
|
47
src/prompt.c
47
src/prompt.c
@ -118,22 +118,29 @@ static void print_prompt_help(ToxWindow *self)
|
||||
|
||||
static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
/* Add printable characters to line */
|
||||
if (isprint(key)) {
|
||||
if (prompt_buf_pos == (sizeof(prompt_buf) - 1)) {
|
||||
return;
|
||||
} else if (!(prompt_buf_pos == 0) && (prompt_buf_pos < COLS)
|
||||
&& (prompt_buf_pos % (COLS - 3) == 0)) {
|
||||
wprintw(self->window, "\n");
|
||||
prompt_buf[prompt_buf_pos++] = '\n';
|
||||
} else if (!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS)
|
||||
&& ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) {
|
||||
wprintw(self->window, "\n");
|
||||
prompt_buf[prompt_buf_pos++] = '\n';
|
||||
}
|
||||
int x, y, y2, x2;
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
prompt_buf[prompt_buf_pos++] = key;
|
||||
prompt_buf[prompt_buf_pos] = 0;
|
||||
/* BACKSPACE key: Remove one character from line */
|
||||
if (key == 0x107 || key == 0x8 || key == 0x7f) {
|
||||
if (prompt_buf_pos != 0) {
|
||||
prompt_buf[--prompt_buf_pos] = '\0';
|
||||
|
||||
if (x == 0)
|
||||
mvwdelch(self->window, y - 1, x2 - 1);
|
||||
else
|
||||
mvwdelch(self->window, y, x - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add printable characters to line */
|
||||
else if (isprint(key)) {
|
||||
if (prompt_buf_pos < (MAX_STR_SIZE-1)) {
|
||||
mvwaddch(self->window, y, x, key);
|
||||
prompt_buf[prompt_buf_pos++] = key;
|
||||
prompt_buf[prompt_buf_pos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* RETURN key: execute command */
|
||||
@ -146,14 +153,9 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
execute(self->window, self, m, prompt_buf);
|
||||
|
||||
prompt_buf_pos = 0;
|
||||
prompt_buf[0] = 0;
|
||||
prompt_buf[0] = '\0';
|
||||
}
|
||||
|
||||
/* BACKSPACE key: Remove one character from line */
|
||||
else if (key == 0x107 || key == 0x8 || key == 0x7f) {
|
||||
if (prompt_buf_pos != 0)
|
||||
prompt_buf[--prompt_buf_pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
@ -164,10 +166,11 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
/* Someone please fix this disgusting hack */
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < prompt_buf_pos; ++i) {
|
||||
if ((prompt_buf[i] == '\n') && (y != 0))
|
||||
if ((prompt_buf_pos + 3) >= x2)
|
||||
--y;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user