1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 22:23:03 +01:00

Corrected wrap-around

This should allow wrap-around and allow proper execution.
This commit is contained in:
Nominate 2013-08-06 11:16:17 +01:00
parent 1701ed7023
commit dfff1e3cc4

View File

@ -41,7 +41,17 @@ unsigned char * hex_string_to_bin(char hex_string[])
static char prompt_buf[256] = {0};
static int prompt_buf_pos=0;
static void execute(ToxWindow* self, char* cmd) {
static void execute(ToxWindow* self, char* u_cmd) {
int i;
int newlines = 0;
char cmd[256] = {0};
for(i = 0; i < strlen(prompt_buf); i++)
{
if (u_cmd[i] == '\n')
++newlines;
else
cmd[i - newlines] = u_cmd[i];
}
if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
endwin();
@ -266,8 +276,16 @@ static void execute(ToxWindow* self, char* cmd) {
static void prompt_onKey(ToxWindow* self, int key) {
// PRINTABLE characters: Add to line.
if(isprint(key)) {
if(prompt_buf_pos == (COLS - 3)) {
return;
if (prompt_buf_pos == 255){
wprintw(self->window, "\nToo Long.\n");
prompt_buf_pos = 0;
prompt_buf[0] = 0;
}
else if(!(prompt_buf_pos == 0) && (prompt_buf_pos < COLS) && (prompt_buf_pos % (COLS - 3) == 0)) {
prompt_buf[prompt_buf_pos++] = '\n';
}
else if(!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS) && ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) {
prompt_buf[prompt_buf_pos++] = '\n';
}
prompt_buf[prompt_buf_pos++] = key;
prompt_buf[prompt_buf_pos] = 0;
@ -292,17 +310,19 @@ static void prompt_onKey(ToxWindow* self, int key) {
static void prompt_onDraw(ToxWindow* self) {
curs_set(1);
int x, y;
getyx(self->window, y, x);
(void) x;
int i;
for (i = 0; i < (strlen(prompt_buf)); i++)
{
if ((prompt_buf[i] == '\n') && (y != 0))
--y;
}
wattron(self->window, COLOR_PAIR(1));
mvwprintw(self->window, y, 0, "# ");
wattroff(self->window, COLOR_PAIR(1));
mvwprintw(self->window, y, 2, "%s", prompt_buf);
wclrtoeol(self->window);
wrefresh(self->window);
}