mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:33:02 +01:00
Corrected wrap-around
This should allow wrap-around and allow proper execution.
This commit is contained in:
parent
1701ed7023
commit
dfff1e3cc4
38
prompt.c
38
prompt.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Toxic -- Tox Curses Client
|
* Toxic -- Tox Curses Client
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -41,7 +41,17 @@ unsigned char * hex_string_to_bin(char hex_string[])
|
|||||||
static char prompt_buf[256] = {0};
|
static char prompt_buf[256] = {0};
|
||||||
static int prompt_buf_pos=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")) {
|
if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
|
||||||
endwin();
|
endwin();
|
||||||
@ -266,8 +276,16 @@ static void execute(ToxWindow* self, char* cmd) {
|
|||||||
static void prompt_onKey(ToxWindow* self, int key) {
|
static void prompt_onKey(ToxWindow* self, int key) {
|
||||||
// PRINTABLE characters: Add to line.
|
// PRINTABLE characters: Add to line.
|
||||||
if(isprint(key)) {
|
if(isprint(key)) {
|
||||||
if(prompt_buf_pos == (COLS - 3)) {
|
if (prompt_buf_pos == 255){
|
||||||
return;
|
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++] = key;
|
||||||
prompt_buf[prompt_buf_pos] = 0;
|
prompt_buf[prompt_buf_pos] = 0;
|
||||||
@ -292,17 +310,19 @@ static void prompt_onKey(ToxWindow* self, int key) {
|
|||||||
static void prompt_onDraw(ToxWindow* self) {
|
static void prompt_onDraw(ToxWindow* self) {
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
getyx(self->window, y, x);
|
getyx(self->window, y, x);
|
||||||
(void) 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));
|
wattron(self->window, COLOR_PAIR(1));
|
||||||
mvwprintw(self->window, y, 0, "# ");
|
mvwprintw(self->window, y, 0, "# ");
|
||||||
wattroff(self->window, COLOR_PAIR(1));
|
wattroff(self->window, COLOR_PAIR(1));
|
||||||
|
|
||||||
mvwprintw(self->window, y, 2, "%s", prompt_buf);
|
mvwprintw(self->window, y, 2, "%s", prompt_buf);
|
||||||
wclrtoeol(self->window);
|
wclrtoeol(self->window);
|
||||||
|
|
||||||
wrefresh(self->window);
|
wrefresh(self->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user