mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added colour functions for API window print line
This commit is contained in:
parent
b8d0f36684
commit
cc7fb03603
@ -29,6 +29,7 @@
|
||||
#include "profanity.h"
|
||||
#include "ui/windows.h"
|
||||
#include "ui/ui.h"
|
||||
#include "config/theme.h"
|
||||
|
||||
void
|
||||
api_cons_alert(void)
|
||||
@ -166,8 +167,46 @@ void
|
||||
api_win_show(const char *tag, const char *line)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(tag);
|
||||
win_print_time(window, '-');
|
||||
wprintw(window->win, "%s\n", line);
|
||||
win_print_line(window, '-', 0, line);
|
||||
|
||||
// refresh if current
|
||||
if (wins_is_current(window)) {
|
||||
int num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
api_win_show_green(const char *tag, const char *line)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(tag);
|
||||
win_print_line(window, '-', COLOUR_ONLINE, line);
|
||||
|
||||
// refresh if current
|
||||
if (wins_is_current(window)) {
|
||||
int num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
api_win_show_red(const char *tag, const char *line)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(tag);
|
||||
win_print_line(window, '-', COLOUR_OFFLINE, line);
|
||||
|
||||
// refresh if current
|
||||
if (wins_is_current(window)) {
|
||||
int num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
api_win_show_cyan(const char *tag, const char *line)
|
||||
{
|
||||
ProfWin *window = wins_get_by_recipient(tag);
|
||||
win_print_line(window, '-', COLOUR_AWAY, line);
|
||||
|
||||
// refresh if current
|
||||
if (wins_is_current(window)) {
|
||||
|
@ -48,5 +48,8 @@ void api_win_create(const char *tag, void *callback,
|
||||
void api_win_focus(const char *tag);
|
||||
void api_win_process_line(const char *tag, const char * const line);
|
||||
void api_win_show(const char *tag, const char *line);
|
||||
void api_win_show_green(const char *tag, const char *line);
|
||||
void api_win_show_red(const char *tag, const char *line);
|
||||
void api_win_show_cyan(const char *tag, const char *line);
|
||||
|
||||
#endif
|
||||
|
@ -147,6 +147,24 @@ c_api_win_show(char *tag, char *line)
|
||||
api_win_show(tag, line);
|
||||
}
|
||||
|
||||
void
|
||||
c_api_win_show_green(char *tag, char *line)
|
||||
{
|
||||
api_win_show_green(tag, line);
|
||||
}
|
||||
|
||||
void
|
||||
c_api_win_show_red(char *tag, char *line)
|
||||
{
|
||||
api_win_show_red(tag, line);
|
||||
}
|
||||
|
||||
void
|
||||
c_api_win_show_cyan(char *tag, char *line)
|
||||
{
|
||||
api_win_show_cyan(tag, line);
|
||||
}
|
||||
|
||||
void
|
||||
c_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@ -190,4 +208,7 @@ c_api_init(void)
|
||||
prof_win_focus = c_api_win_focus;
|
||||
prof_win_process_line = c_api_win_process_line;
|
||||
prof_win_show = c_api_win_show;
|
||||
prof_win_show_green = c_api_win_show_green;
|
||||
prof_win_show_red = c_api_win_show_red;
|
||||
prof_win_show_cyan = c_api_win_show_cyan;
|
||||
}
|
||||
|
@ -201,6 +201,34 @@ lua_api_win_show(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_api_win_show_green(lua_State *L)
|
||||
{
|
||||
const char *tag = lua_tostring(L, -2);
|
||||
const char *line = lua_tostring(L, -1);
|
||||
api_win_show_green(tag, line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_api_win_show_red(lua_State *L)
|
||||
{
|
||||
const char *tag = lua_tostring(L, -2);
|
||||
const char *line = lua_tostring(L, -1);
|
||||
api_win_show_red(tag, line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_api_win_show_cyan(lua_State *L)
|
||||
{
|
||||
const char *tag = lua_tostring(L, -2);
|
||||
const char *line = lua_tostring(L, -1);
|
||||
api_win_show_cyan(tag, line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
lua_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@ -304,6 +332,12 @@ lua_api_init(lua_State *L)
|
||||
lua_setglobal(L, "prof_win_focus");
|
||||
lua_pushcfunction(L, lua_api_win_show);
|
||||
lua_setglobal(L, "prof_win_show");
|
||||
lua_pushcfunction(L, lua_api_win_show_green);
|
||||
lua_setglobal(L, "prof_win_show_green");
|
||||
lua_pushcfunction(L, lua_api_win_show_red);
|
||||
lua_setglobal(L, "prof_win_show_red");
|
||||
lua_pushcfunction(L, lua_api_win_show_cyan);
|
||||
lua_setglobal(L, "prof_win_show_cyan");
|
||||
lua_pushcfunction(L, lua_api_win_process_line);
|
||||
lua_setglobal(L, "prof_win_process_line");
|
||||
}
|
||||
|
@ -50,3 +50,6 @@ void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win,
|
||||
void (*prof_win_focus)(PROF_WIN_TAG win) = NULL;
|
||||
void (*prof_win_process_line)(PROF_WIN_TAG win, char *line) = NULL;
|
||||
void (*prof_win_show)(PROF_WIN_TAG win, char *line) = NULL;
|
||||
void (*prof_win_show_green)(PROF_WIN_TAG win, char *line) = NULL;
|
||||
void (*prof_win_show_red)(PROF_WIN_TAG win, char *line) = NULL;
|
||||
void (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line) = NULL;
|
||||
|
@ -50,5 +50,8 @@ void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win,
|
||||
void (*prof_win_focus)(PROF_WIN_TAG win);
|
||||
void (*prof_win_process_line)(PROF_WIN_TAG win, char *line);
|
||||
void (*prof_win_show)(PROF_WIN_TAG win, char *line);
|
||||
void (*prof_win_show_green)(PROF_WIN_TAG win, char *line);
|
||||
void (*prof_win_show_red)(PROF_WIN_TAG win, char *line);
|
||||
void (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line);
|
||||
|
||||
#endif
|
||||
|
@ -244,6 +244,48 @@ python_api_win_show(PyObject *self, PyObject *args)
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_api_win_show_green(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *tag = NULL;
|
||||
char *line = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &tag, &line)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
api_win_show_green(tag, line);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_api_win_show_red(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *tag = NULL;
|
||||
char *line = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &tag, &line)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
api_win_show_red(tag, line);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_api_win_show_cyan(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *tag = NULL;
|
||||
char *line = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &tag, &line)) {
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
api_win_show_cyan(tag, line);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
void
|
||||
python_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@ -321,6 +363,9 @@ static PyMethodDef apiMethods[] = {
|
||||
{ "win_create", python_api_win_create, METH_VARARGS, "Create a new window." },
|
||||
{ "win_focus", python_api_win_focus, METH_VARARGS, "Focus a window." },
|
||||
{ "win_show", python_api_win_show, METH_VARARGS, "Show text in the window." },
|
||||
{ "win_show_green", python_api_win_show_green, METH_VARARGS, "Show green text in the window." },
|
||||
{ "win_show_red", python_api_win_show_red, METH_VARARGS, "Show red text in the window." },
|
||||
{ "win_show_cyan", python_api_win_show_cyan, METH_VARARGS, "Show cyan text in the window." },
|
||||
{ "win_process_line", python_api_win_process_line, METH_VARARGS, "Send a line of input to a window." },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
@ -202,6 +202,36 @@ ruby_api_win_show(VALUE self, VALUE v_tag, VALUE v_line)
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ruby_api_win_show_green(VALUE self, VALUE v_tag, VALUE v_line)
|
||||
{
|
||||
char *tag = STR2CSTR(v_tag);
|
||||
char *line = STR2CSTR(v_line);
|
||||
|
||||
api_win_show_green(tag, line);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ruby_api_win_show_red(VALUE self, VALUE v_tag, VALUE v_line)
|
||||
{
|
||||
char *tag = STR2CSTR(v_tag);
|
||||
char *line = STR2CSTR(v_line);
|
||||
|
||||
api_win_show_red(tag, line);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ruby_api_win_show_cyan(VALUE self, VALUE v_tag, VALUE v_line)
|
||||
{
|
||||
char *tag = STR2CSTR(v_tag);
|
||||
char *line = STR2CSTR(v_line);
|
||||
|
||||
api_win_show_cyan(tag, line);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void
|
||||
ruby_command_callback(PluginCommand *command, gchar **args)
|
||||
{
|
||||
@ -245,7 +275,6 @@ ruby_window_callback(PluginWindowCallback *window_callback, char *tag, char *lin
|
||||
rb_str_new2(tag), rb_str_new2(line));
|
||||
}
|
||||
|
||||
|
||||
static VALUE prof_module;
|
||||
|
||||
void
|
||||
@ -269,4 +298,7 @@ ruby_api_init(void)
|
||||
rb_define_module_function(prof_module, "win_focus", RUBY_METHOD_FUNC(ruby_api_win_focus), 1);
|
||||
rb_define_module_function(prof_module, "win_process_line", RUBY_METHOD_FUNC(ruby_api_win_process_line), 2);
|
||||
rb_define_module_function(prof_module, "win_show", RUBY_METHOD_FUNC(ruby_api_win_show), 2);
|
||||
rb_define_module_function(prof_module, "win_show_green", RUBY_METHOD_FUNC(ruby_api_win_show_green), 2);
|
||||
rb_define_module_function(prof_module, "win_show_red", RUBY_METHOD_FUNC(ruby_api_win_show_red), 2);
|
||||
rb_define_module_function(prof_module, "win_show_cyan", RUBY_METHOD_FUNC(ruby_api_win_show_cyan), 2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user