Skip to content

Commit

Permalink
Add "/run" to autocompleter and fix example Python script.
Browse files Browse the repository at this point in the history
  • Loading branch information
TsarFox committed May 23, 2017
1 parent 4f60d54 commit 22ea522
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apidoc/python/source/fortune.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def send_fortune(args):
count = int(args[0])
except ValueError:
toxic_api.display("Argument must be a number!")
return

if count < 0 or count > 20:
toxic_api.display("Argument is too large!")

name = toxic_api.get_nick()

Expand Down
3 changes: 3 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "misc_tools.h"
#include "python_api.h"
#include "settings.h"
#include "toxic_strings.h"
#include "windows.h"

Tox *user_tox;
Expand Down Expand Up @@ -100,6 +101,8 @@ void api_send(const char *msg)
self_window = get_active_window();
get_time_str(timefrmt, sizeof(timefrmt));

strncpy((char *) self_window->chatwin->line, msg, sizeof(self_window->chatwin->line));
add_line_to_hist(self_window->chatwin);
line_info_add(self_window, timefrmt, name, NULL, OUT_MSG, 0, 0, "%s", msg);
cqueue_add(self_window->chatwin->cqueue, msg, strlen(msg), OUT_MSG,
self_window->chatwin->hst->line_end->id + 1);
Expand Down
4 changes: 4 additions & 0 deletions src/autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
bool dir_search = !strncmp(ubuf, "/sendfile", strlen("/sendfile"))
|| !strncmp(ubuf, "/avatar", strlen("/avatar"));

#ifdef PYTHON
dir_search = dir_search || !strncmp(ubuf, "/run", strlen("/run"));
#endif

/* isolate substring from space behind pos to pos */
char tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", ubuf);
Expand Down
22 changes: 20 additions & 2 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ static void init_infobox(ToxWindow *self);
static void kill_infobox(ToxWindow *self);
#endif /* AUDIO */

#ifdef AUDIO
#if defined(AUDIO) && defined(PYTHON)
#define AC_NUM_CHAT_COMMANDS 31
#elif AUDIO
#define AC_NUM_CHAT_COMMANDS 30
#elif PYTHON
#define AC_NUM_CHAT_COMMANDS 23
#else
#define AC_NUM_CHAT_COMMANDS 22
#endif /* AUDIO */
Expand Down Expand Up @@ -108,6 +112,12 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/video" },

#endif /* AUDIO */

#ifdef PYTHON

{ "/run" },

#endif /* PYTHON */
};

static void set_self_typingstatus(ToxWindow *self, Tox *m, bool is_typing)
Expand Down Expand Up @@ -931,7 +941,15 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
diff = dir_match(self, m, ctx->line, L"/sendfile");
} else if (wcsncmp(ctx->line, L"/avatar \"", wcslen(L"/avatar \"")) == 0) {
diff = dir_match(self, m, ctx->line, L"/avatar");
} else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) {
}

#ifdef PYTHON
else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run \"")) == 0) {
diff = dir_match(self, m, ctx->line, L"/run");
}
#endif

else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) {
const char status_cmd_list[3][8] = {
{"online"},
{"away"},
Expand Down
22 changes: 20 additions & 2 deletions src/groupchat.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ static int max_groupchat_index = 0;
extern struct user_settings *user_settings;
extern struct Winthread Winthread;

#ifdef AUDIO
#if defined(AUDIO) && defined(PYTHON)
#define AC_NUM_GROUP_COMMANDS 25
#elif AUDIO
#define AC_NUM_GROUP_COMMANDS 24
#elif PYTHON
#define AC_NUM_GROUP_COMMANDS 21
#else
#define AC_NUM_GROUP_COMMANDS 20
#endif /* AUDIO */
Expand All @@ -97,6 +101,12 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/requests" },
{ "/status" },
{ "/title" },

#ifdef PYTHON

{ "/run" },

#endif /* PYTHON */
};

int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type)
Expand Down Expand Up @@ -543,7 +553,15 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
TOX_MAX_NAME_LENGTH);
} else if (wcsncmp(ctx->line, L"/avatar \"", wcslen(L"/avatar \"")) == 0) {
diff = dir_match(self, m, ctx->line, L"/avatar");
} else {
}

#ifdef PYTHON
else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run \"")) == 0) {
diff = dir_match(self, m, ctx->line, L"/run");
}
#endif

else {
diff = complete_line(self, group_cmd_list, AC_NUM_GROUP_COMMANDS, MAX_CMDNAME_SIZE);
}

Expand Down
20 changes: 19 additions & 1 deletion src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ extern struct Winthread Winthread;

extern FriendsList Friends;
FriendRequests FrndRequests;
#ifdef VIDEO
#if defined(PYTHON) && defined(VIDEO)
#define AC_NUM_GLOB_COMMANDS 23
#elif defined(PYTHON) && defined(AUDIO)
#define AC_NUM_GLOB_COMMANDS 21
#elif VIDEO
#define AC_NUM_GLOB_COMMANDS 22
#elif AUDIO
#define AC_NUM_GLOB_COMMANDS 20
#elif PYTHON
#define AC_NUM_GLOB_COMMANDS 19
#else
#define AC_NUM_GLOB_COMMANDS 18
#endif
Expand Down Expand Up @@ -92,6 +98,12 @@ static const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {

#endif /* VIDEO */

#ifdef PYTHON

{ "/run" },

#endif /* PYTHON */

};

void kill_prompt_window(ToxWindow *self)
Expand Down Expand Up @@ -214,6 +226,12 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)

if (wcsncmp(ctx->line, L"/avatar \"", wcslen(L"/avatar \"")) == 0)
diff = dir_match(self, m, ctx->line, L"/avatar");

#ifdef PYTHON
else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run \"")) == 0)
diff = dir_match(self, m, ctx->line, L"/run");
#endif

else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) {
const char status_cmd_list[3][8] = {
{"online"},
Expand Down

0 comments on commit 22ea522

Please sign in to comment.