2013-07-30 07:32:39 +08:00
|
|
|
/*
|
2013-08-06 18:16:17 +08:00
|
|
|
* Toxic -- Tox Curses Client
|
|
|
|
*/
|
2013-07-30 07:32:39 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <curses.h>
|
|
|
|
|
|
|
|
#include "../../core/Messenger.h"
|
|
|
|
#include "../../core/network.h"
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
|
2013-08-08 16:51:58 +08:00
|
|
|
uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX
|
2013-07-30 07:32:39 +08:00
|
|
|
uint8_t num_requests=0; // XXX
|
|
|
|
|
2013-07-31 03:47:40 +08:00
|
|
|
extern void on_friendadded(int friendnumber);
|
2013-08-07 06:27:51 +08:00
|
|
|
static void print_usage(ToxWindow *self);
|
2013-08-08 16:51:58 +08:00
|
|
|
static char prompt_buf[MAX_STR_SIZE] = {0};
|
2013-08-07 06:27:51 +08:00
|
|
|
static int prompt_buf_pos = 0;
|
2013-07-31 03:47:40 +08:00
|
|
|
|
2013-07-30 07:32:39 +08:00
|
|
|
// XXX:
|
2013-08-07 06:27:51 +08:00
|
|
|
int add_req(uint8_t *public_key)
|
|
|
|
{
|
2013-07-30 07:32:39 +08:00
|
|
|
memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
|
|
|
|
++num_requests;
|
|
|
|
return num_requests-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: FIX
|
2013-08-07 06:27:51 +08:00
|
|
|
unsigned char *hex_string_to_bin(char hex_string[])
|
2013-07-30 07:32:39 +08:00
|
|
|
{
|
2013-08-07 06:27:51 +08:00
|
|
|
size_t len = strlen(hex_string);
|
|
|
|
unsigned char *val = malloc(len);
|
|
|
|
char *pos = hex_string;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; ++i, pos+=2)
|
|
|
|
sscanf(pos,"%2hhx",&val[i]);
|
|
|
|
return val;
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
static void execute(ToxWindow *self, char *u_cmd)
|
|
|
|
{
|
|
|
|
int newlines = 0;
|
2013-08-08 16:51:58 +08:00
|
|
|
char cmd[MAX_STR_SIZE] = {0};
|
2013-08-07 06:27:51 +08:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < strlen(prompt_buf); ++i) {
|
2013-08-06 18:16:17 +08:00
|
|
|
if (u_cmd[i] == '\n')
|
2013-08-07 06:27:51 +08:00
|
|
|
++newlines;
|
|
|
|
else
|
|
|
|
cmd[i - newlines] = u_cmd[i];
|
|
|
|
}
|
2013-07-30 07:32:39 +08:00
|
|
|
|
2013-08-07 14:10:46 +08:00
|
|
|
int leading_spc = 0;
|
2013-08-08 16:51:58 +08:00
|
|
|
for (i = 0; i < MAX_STR_SIZE && isspace(cmd[i]); ++i)
|
2013-08-07 14:10:46 +08:00
|
|
|
leading_spc++;
|
2013-08-08 16:51:58 +08:00
|
|
|
memmove(cmd, cmd + leading_spc, MAX_STR_SIZE - leading_spc);
|
2013-08-07 14:10:46 +08:00
|
|
|
|
2013-08-07 14:25:20 +08:00
|
|
|
int cmd_end = strlen(cmd);
|
|
|
|
while (cmd_end > 0 && cmd_end--)
|
|
|
|
if (!isspace(cmd[cmd_end]))
|
|
|
|
break;
|
|
|
|
cmd[cmd_end + 1] = '\0';
|
2013-08-08 06:20:36 +08:00
|
|
|
|
|
|
|
/* What is this supposed to do?
|
2013-08-07 15:24:37 +08:00
|
|
|
if (cmd[0] == '/') {
|
2013-08-08 01:57:17 +08:00
|
|
|
wprintw(self->window,"Warning: Run your command without the /, this may not work\n");
|
2013-08-07 15:24:37 +08:00
|
|
|
int i;
|
2013-08-08 01:57:17 +08:00
|
|
|
for (i = 1; i < strlen(cmd); i++) { //This doesn't work when it doesn't end with a space and another word
|
2013-08-07 15:24:37 +08:00
|
|
|
cmd[i - 1] = cmd[i]; //Still working on why
|
|
|
|
}
|
|
|
|
}
|
2013-08-08 06:20:36 +08:00
|
|
|
*/
|
2013-08-07 14:25:20 +08:00
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
|
2013-07-30 07:32:39 +08:00
|
|
|
endwin();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
else if (!strncmp(cmd, "connect ", strlen("connect "))) {
|
|
|
|
IP_Port dht;
|
|
|
|
char *ip = strchr(cmd, ' ');
|
|
|
|
if (ip == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ip++;
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
char *port = strchr(ip, ' ');
|
|
|
|
if (port == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
port[0] = 0;
|
|
|
|
port++;
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
char *key = strchr(port, ' ');
|
|
|
|
if (key == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
key[0] = 0;
|
|
|
|
key++;
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
if (atoi(port) == 0) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dht.port = htons(atoi(port));
|
2013-08-08 16:51:58 +08:00
|
|
|
uintKEY_SIZE_BYTES_t resolved_address = resolve_addr(ip);
|
2013-08-02 02:52:13 +08:00
|
|
|
if (resolved_address == 0) {
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dht.ip.i = resolved_address;
|
2013-08-04 18:52:24 +08:00
|
|
|
unsigned char *binary_string = hex_string_to_bin(key);
|
|
|
|
DHT_bootstrap(dht, binary_string);
|
2013-08-06 03:30:40 +08:00
|
|
|
free(binary_string);
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
|
|
|
|
else if (!strncmp(cmd, "add ", strlen("add "))) {
|
2013-08-08 16:51:58 +08:00
|
|
|
uint8_t id_bin[KEY_SIZE_BYTES];
|
2013-07-31 03:47:40 +08:00
|
|
|
char xx[3];
|
2013-08-08 16:51:58 +08:00
|
|
|
uintKEY_SIZE_BYTES_t x;
|
2013-08-07 06:27:51 +08:00
|
|
|
char *id = strchr(cmd, ' ');
|
|
|
|
if (id == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
id++;
|
2013-08-07 06:27:51 +08:00
|
|
|
char *msg = strchr(id, ' ');
|
|
|
|
if (msg != NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
msg[0] = 0;
|
|
|
|
msg++;
|
|
|
|
}
|
|
|
|
else msg = "";
|
2013-08-08 16:51:58 +08:00
|
|
|
if (strlen(id) != 2*KEY_SIZE_BYTES) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid ID length.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
int i;
|
2013-08-08 16:51:58 +08:00
|
|
|
for (i = 0; i < KEY_SIZE_BYTES; ++i) {
|
2013-07-31 03:47:40 +08:00
|
|
|
xx[0] = id[2*i];
|
|
|
|
xx[1] = id[2*i+1];
|
|
|
|
xx[2] = '\0';
|
2013-08-07 06:27:51 +08:00
|
|
|
if (sscanf(xx, "%02x", &x) != 1) {
|
2013-07-31 16:36:02 +08:00
|
|
|
wprintw(self->window, "Invalid ID.\n");
|
|
|
|
return;
|
2013-07-31 03:47:40 +08:00
|
|
|
}
|
|
|
|
id_bin[i] = x;
|
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
int num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1);
|
2013-08-01 09:44:57 +08:00
|
|
|
switch (num) {
|
2013-08-06 03:30:40 +08:00
|
|
|
case -1:
|
2013-08-01 09:44:57 +08:00
|
|
|
wprintw(self->window, "Message is too long.\n");
|
|
|
|
break;
|
|
|
|
case -2:
|
2013-08-02 03:27:08 +08:00
|
|
|
wprintw(self->window, "Please add a message to your request.\n");
|
2013-08-03 15:59:46 +08:00
|
|
|
break;
|
2013-08-02 03:27:08 +08:00
|
|
|
case -3:
|
2013-08-01 09:44:57 +08:00
|
|
|
wprintw(self->window, "That appears to be your own ID.\n");
|
|
|
|
break;
|
2013-08-02 03:27:08 +08:00
|
|
|
case -4:
|
2013-08-01 09:44:57 +08:00
|
|
|
wprintw(self->window, "Friend request already sent.\n");
|
|
|
|
break;
|
2013-08-02 03:27:08 +08:00
|
|
|
case -5:
|
2013-08-04 16:42:17 +08:00
|
|
|
wprintw(self->window, "Undefined error when adding friend.\n");
|
2013-08-06 03:30:40 +08:00
|
|
|
break;
|
2013-08-01 09:44:57 +08:00
|
|
|
default:
|
|
|
|
wprintw(self->window, "Friend added as %d.\n", num);
|
|
|
|
on_friendadded(num);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
|
|
|
|
else if (!strcmp(cmd, "clear")) {
|
|
|
|
wclear(self->window);
|
2013-08-06 01:33:16 +08:00
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
|
|
|
|
else if (!strcmp(cmd, "help")) {
|
|
|
|
wclear(self->window);
|
|
|
|
print_usage(self);
|
2013-08-01 08:23:15 +08:00
|
|
|
}
|
2013-07-30 07:32:39 +08:00
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
else if (!strncmp(cmd, "status ", strlen("status "))) {
|
2013-08-07 15:14:10 +08:00
|
|
|
char *status = strchr(cmd, ' ');
|
|
|
|
char *msg;
|
|
|
|
char *status_text;
|
|
|
|
if (status == NULL) {
|
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
status++;
|
2013-08-08 06:12:59 +08:00
|
|
|
USERSTATUS status_kind;
|
2013-08-07 15:14:10 +08:00
|
|
|
if (!strncmp(status, "online", strlen("online"))) {
|
2013-08-08 06:12:59 +08:00
|
|
|
status_kind = USERSTATUS_NONE;
|
2013-08-07 15:14:10 +08:00
|
|
|
status_text = "ONLINE";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strncmp(status, "away", strlen("away"))) {
|
2013-08-08 06:12:59 +08:00
|
|
|
status_kind = USERSTATUS_AWAY;
|
2013-08-07 15:14:10 +08:00
|
|
|
status_text = "AWAY";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strncmp(status, "busy", strlen("busy"))) {
|
2013-08-08 06:12:59 +08:00
|
|
|
status_kind = USERSTATUS_BUSY;
|
2013-08-07 15:14:10 +08:00
|
|
|
status_text = "BUSY";
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wprintw(self->window, "Invalid status.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = strchr(status, ' ');
|
|
|
|
if (msg == NULL) {
|
2013-08-08 06:12:59 +08:00
|
|
|
m_set_userstatus(status_kind);
|
2013-08-07 15:14:10 +08:00
|
|
|
wprintw(self->window, "Status set to: %s\n", status_text);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
msg++;
|
2013-08-08 06:12:59 +08:00
|
|
|
m_set_userstatus(status_kind);
|
|
|
|
m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
|
2013-08-07 15:14:10 +08:00
|
|
|
wprintw(self->window, "Status set to: %s, %s\n", status_text, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) {
|
2013-08-07 06:27:51 +08:00
|
|
|
char *msg = strchr(cmd, ' ');
|
|
|
|
if (msg == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg++;
|
2013-08-08 06:12:59 +08:00
|
|
|
m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
|
2013-08-01 07:02:06 +08:00
|
|
|
wprintw(self->window, "Status set to: %s\n", msg);
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
else if (!strncmp(cmd, "nick ", strlen("nick "))) {
|
|
|
|
char *nick = strchr(cmd, ' ');
|
|
|
|
if (nick == NULL) {
|
2013-08-04 16:42:17 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nick++;
|
|
|
|
setname((uint8_t*) nick, strlen(nick)+1);
|
2013-08-04 16:42:17 +08:00
|
|
|
wprintw(self->window, "Nickname set to: %s\n", nick);
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
|
|
|
|
else if (!strcmp(cmd, "myid")) {
|
2013-08-08 16:51:58 +08:00
|
|
|
char id[KEY_SIZE_BYTES*2 + 1] = {0};
|
2013-07-31 03:47:40 +08:00
|
|
|
size_t i;
|
2013-08-08 16:51:58 +08:00
|
|
|
for (i = 0; i < KEY_SIZE_BYTES; ++i) {
|
2013-07-31 03:47:40 +08:00
|
|
|
char xx[3];
|
2013-08-06 18:16:17 +08:00
|
|
|
snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
|
2013-07-31 03:47:40 +08:00
|
|
|
strcat(id, xx);
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
2013-08-04 16:42:17 +08:00
|
|
|
wprintw(self->window, "Your ID: %s\n", id);
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
else if (!strncmp(cmd, "accept ", strlen("accept "))) {
|
|
|
|
char *id = strchr(cmd, ' ');
|
|
|
|
if (id == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
id++;
|
2013-07-31 03:47:40 +08:00
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
int num = atoi(id);
|
|
|
|
if (num >= num_requests) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
num = m_addfriend_norequest(pending_requests[num]);
|
2013-08-07 06:27:51 +08:00
|
|
|
if (num == -1)
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Failed to add friend.\n");
|
|
|
|
else {
|
|
|
|
wprintw(self->window, "Friend accepted as: %d.\n", num);
|
|
|
|
on_friendadded(num);
|
|
|
|
}
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
else if (!strncmp(cmd, "msg ", strlen("msg "))) {
|
|
|
|
char *id = strchr(cmd, ' ');
|
|
|
|
if (id == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
char *msg = strchr(++id, ' ');
|
|
|
|
if (msg == NULL) {
|
2013-07-31 03:47:40 +08:00
|
|
|
wprintw(self->window, "Invalid syntax.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg[0] = 0;
|
|
|
|
msg++;
|
2013-08-08 01:51:58 +08:00
|
|
|
if (m_sendmessage(atoi(id), (uint8_t*) msg, strlen(msg)+1) == 0)
|
2013-07-30 07:32:39 +08:00
|
|
|
wprintw(self->window, "Error occurred while sending message.\n");
|
2013-08-07 06:27:51 +08:00
|
|
|
else
|
2013-07-30 07:32:39 +08:00
|
|
|
wprintw(self->window, "Message successfully sent.\n");
|
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
else
|
2013-08-04 16:42:17 +08:00
|
|
|
wprintw(self->window, "Invalid command.\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
static void prompt_onKey(ToxWindow *self, int key)
|
|
|
|
{
|
|
|
|
/* Add printable characters to line */
|
|
|
|
if (isprint(key)) {
|
|
|
|
if (prompt_buf_pos == (sizeof(prompt_buf) - 1)) {
|
|
|
|
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';
|
2013-08-06 18:16:17 +08:00
|
|
|
}
|
2013-08-07 06:27:51 +08:00
|
|
|
else if (!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS)
|
|
|
|
&& ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) {
|
|
|
|
prompt_buf[prompt_buf_pos++] = '\n';
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
prompt_buf[prompt_buf_pos++] = key;
|
|
|
|
prompt_buf[prompt_buf_pos] = 0;
|
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
/* RETURN key: execute command */
|
|
|
|
else if (key == '\n') {
|
2013-07-30 07:32:39 +08:00
|
|
|
wprintw(self->window, "\n");
|
|
|
|
execute(self, prompt_buf);
|
|
|
|
prompt_buf_pos = 0;
|
|
|
|
prompt_buf[0] = 0;
|
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
/* BACKSPACE key: Remove one character from line */
|
|
|
|
else if (key == 0x107 || key == 0x8 || key == 0x7f) {
|
|
|
|
if (prompt_buf_pos != 0) {
|
2013-07-30 07:32:39 +08:00
|
|
|
prompt_buf[--prompt_buf_pos] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
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);
|
2013-07-30 07:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
static void print_usage(ToxWindow *self)
|
|
|
|
{
|
2013-07-30 07:32:39 +08:00
|
|
|
wattron(self->window, COLOR_PAIR(2) | A_BOLD);
|
2013-08-01 02:20:16 +08:00
|
|
|
wprintw(self->window, "Commands:\n");
|
2013-07-30 07:32:39 +08:00
|
|
|
wattroff(self->window, A_BOLD);
|
2013-07-31 03:47:40 +08:00
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
|
|
|
|
wprintw(self->window, " add <id> <message> : Add friend\n");
|
2013-08-07 15:14:10 +08:00
|
|
|
wprintw(self->window, " status <type> <message> : Set your status\n");
|
|
|
|
wprintw(self->window, " statusmsg <message> : Set your status\n");
|
2013-08-07 06:27:51 +08:00
|
|
|
wprintw(self->window, " nick <nickname> : Set your nickname\n");
|
|
|
|
wprintw(self->window, " accept <number> : Accept friend request\n");
|
|
|
|
wprintw(self->window, " myid : Print your ID\n");
|
|
|
|
wprintw(self->window, " quit/exit : Exit program\n");
|
|
|
|
wprintw(self->window, " help : Print this message again\n");
|
2013-08-08 01:51:58 +08:00
|
|
|
wprintw(self->window, " clear : Clear this window\n");
|
2013-08-07 06:27:51 +08:00
|
|
|
|
2013-07-31 03:47:40 +08:00
|
|
|
wattron(self->window, A_BOLD);
|
2013-08-01 02:20:16 +08:00
|
|
|
wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");
|
2013-07-31 03:47:40 +08:00
|
|
|
wattroff(self->window, A_BOLD);
|
|
|
|
|
2013-07-30 07:32:39 +08:00
|
|
|
wattroff(self->window, COLOR_PAIR(2));
|
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
static void prompt_onInit(ToxWindow *self)
|
|
|
|
{
|
2013-07-30 07:32:39 +08:00
|
|
|
scrollok(self->window, 1);
|
|
|
|
print_usage(self);
|
|
|
|
wclrtoeol(self->window);
|
|
|
|
}
|
|
|
|
|
2013-08-07 06:27:51 +08:00
|
|
|
ToxWindow new_prompt()
|
|
|
|
{
|
2013-07-30 07:32:39 +08:00
|
|
|
ToxWindow ret;
|
2013-08-01 01:20:03 +08:00
|
|
|
memset(&ret, 0, sizeof(ret));
|
2013-07-30 07:32:39 +08:00
|
|
|
ret.onKey = &prompt_onKey;
|
|
|
|
ret.onDraw = &prompt_onDraw;
|
|
|
|
ret.onInit = &prompt_onInit;
|
|
|
|
strcpy(ret.title, "[prompt]");
|
|
|
|
return ret;
|
|
|
|
}
|