mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 22:13:02 +01:00
Corrected wrap-around
This should allow wrap-around and allow proper execution.
This commit is contained in:
parent
1701ed7023
commit
dfff1e3cc4
80
prompt.c
80
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();
|
||||||
@ -158,7 +168,7 @@ static void execute(ToxWindow* self, char* cmd) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!strcmp(cmd, "clear")) {
|
else if(!strcmp(cmd, "clear")) {
|
||||||
wclear(self->window);
|
wclear(self->window);
|
||||||
}
|
}
|
||||||
else if(!strcmp(cmd, "help")) {
|
else if(!strcmp(cmd, "help")) {
|
||||||
@ -197,7 +207,7 @@ static void execute(ToxWindow* self, char* cmd) {
|
|||||||
|
|
||||||
for(i=0; i<32; i++) {
|
for(i=0; i<32; i++) {
|
||||||
char xx[3];
|
char xx[3];
|
||||||
snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
|
snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
|
||||||
strcat(id, xx);
|
strcat(id, xx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
@ -290,20 +308,22 @@ 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++)
|
||||||
wattron(self->window, COLOR_PAIR(1));
|
{
|
||||||
mvwprintw(self->window, y, 0, "# ");
|
if ((prompt_buf[i] == '\n') && (y != 0))
|
||||||
wattroff(self->window, COLOR_PAIR(1));
|
--y;
|
||||||
|
}
|
||||||
mvwprintw(self->window, y, 2, "%s", prompt_buf);
|
wattron(self->window, COLOR_PAIR(1));
|
||||||
wclrtoeol(self->window);
|
mvwprintw(self->window, y, 0, "# ");
|
||||||
|
wattroff(self->window, COLOR_PAIR(1));
|
||||||
wrefresh(self->window);
|
mvwprintw(self->window, y, 2, "%s", prompt_buf);
|
||||||
|
wclrtoeol(self->window);
|
||||||
|
wrefresh(self->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_usage(ToxWindow* self) {
|
static void print_usage(ToxWindow* self) {
|
||||||
@ -311,15 +331,15 @@ static void print_usage(ToxWindow* self) {
|
|||||||
wprintw(self->window, "Commands:\n");
|
wprintw(self->window, "Commands:\n");
|
||||||
wattroff(self->window, A_BOLD);
|
wattroff(self->window, A_BOLD);
|
||||||
|
|
||||||
wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
|
wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
|
||||||
wprintw(self->window, " add <id> <message> : Add friend\n");
|
wprintw(self->window, " add <id> <message> : Add friend\n");
|
||||||
wprintw(self->window, " status <message> : Set your status\n");
|
wprintw(self->window, " status <message> : Set your status\n");
|
||||||
wprintw(self->window, " nick <nickname> : Set your nickname\n");
|
wprintw(self->window, " nick <nickname> : Set your nickname\n");
|
||||||
wprintw(self->window, " accept <number> : Accept friend request\n");
|
wprintw(self->window, " accept <number> : Accept friend request\n");
|
||||||
wprintw(self->window, " myid : Print your ID\n");
|
wprintw(self->window, " myid : Print your ID\n");
|
||||||
wprintw(self->window, " quit/exit : Exit program\n");
|
wprintw(self->window, " quit/exit : Exit program\n");
|
||||||
wprintw(self->window, " help : Print this message again\n");
|
wprintw(self->window, " help : Print this message again\n");
|
||||||
wprintw(self->window, " clear : Clear this window\n");
|
wprintw(self->window, " clear : Clear this window\n");
|
||||||
|
|
||||||
wattron(self->window, A_BOLD);
|
wattron(self->window, A_BOLD);
|
||||||
wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");
|
wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user