degesch: printing to buffers etc.
This commit is contained in:
parent
511c56d2fc
commit
583262ae67
99
degesch.c
99
degesch.c
|
@ -1416,10 +1416,8 @@ on_readline_previous_buffer (int count, int key)
|
||||||
(void) key;
|
(void) key;
|
||||||
|
|
||||||
struct app_context *ctx = g_ctx;
|
struct app_context *ctx = g_ctx;
|
||||||
if (!ctx->current_buffer)
|
if (ctx->current_buffer)
|
||||||
return 0;
|
buffer_activate (ctx, buffer_previous (ctx, count));
|
||||||
|
|
||||||
buffer_activate (ctx, buffer_previous (ctx, count));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1429,10 +1427,8 @@ on_readline_next_buffer (int count, int key)
|
||||||
(void) key;
|
(void) key;
|
||||||
|
|
||||||
struct app_context *ctx = g_ctx;
|
struct app_context *ctx = g_ctx;
|
||||||
if (!ctx->current_buffer)
|
if (ctx->current_buffer)
|
||||||
return 0;
|
buffer_activate (ctx, buffer_next (ctx, count));
|
||||||
|
|
||||||
buffer_activate (ctx, buffer_next (ctx, count));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1649,9 +1645,8 @@ try_handle_buffer_goto (struct app_context *ctx, const char *word)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (n > INT_MAX || !buffer_goto (ctx, n))
|
if (n > INT_MAX || !buffer_goto (ctx, n))
|
||||||
{
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
// TODO: print a "no such buffer" error message
|
"%s: %s", "no such buffer", word);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1678,10 +1673,16 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||||
struct buffer *buffer = NULL;
|
struct buffer *buffer = NULL;
|
||||||
|
|
||||||
// XXX: also build a prefix map?
|
// XXX: also build a prefix map?
|
||||||
|
// It looks like we'll want to split this into functions anyway.
|
||||||
// TODO: some subcommand to print N last lines from the buffer
|
// TODO: some subcommand to print N last lines from the buffer
|
||||||
if (!strcasecmp_ascii (action, "list"))
|
if (!strcasecmp_ascii (action, "list"))
|
||||||
{
|
{
|
||||||
// TODO: print a list of "%d: %s", index, name
|
buffer_send_status (ctx, ctx->global_buffer, "Buffers list:");
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
|
||||||
|
buffer_send_status (ctx, ctx->global_buffer,
|
||||||
|
" [%d] %s", i++, iter->name);
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_ascii (action, "clear"))
|
else if (!strcasecmp_ascii (action, "clear"))
|
||||||
{
|
{
|
||||||
|
@ -1702,17 +1703,20 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||||
|
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
// TODO: print a "no such buffer: %s" message
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
|
"%s: %s", "no such buffer", which);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (buffer == ctx->global_buffer)
|
if (buffer == ctx->global_buffer)
|
||||||
{
|
{
|
||||||
// TODO: print a "can't close the global buffer" message
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
|
"can't close the global buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (buffer == ctx->server_buffer)
|
if (buffer == ctx->server_buffer)
|
||||||
{
|
{
|
||||||
// TODO: print a "can't close the server buffer" message
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
|
"can't close the server buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1739,6 +1743,12 @@ handle_command_quit (struct app_context *ctx, char *arguments)
|
||||||
initiate_quit (ctx);
|
initiate_quit (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_command_quote (struct app_context *ctx, char *arguments)
|
||||||
|
{
|
||||||
|
irc_send (ctx, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
static struct command_handler
|
static struct command_handler
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -1775,8 +1785,8 @@ g_command_handlers[] =
|
||||||
|
|
||||||
{ "motd", NULL },
|
{ "motd", NULL },
|
||||||
{ "away", NULL },
|
{ "away", NULL },
|
||||||
{ "quote", NULL },
|
|
||||||
#endif
|
#endif
|
||||||
|
{ "quote", handle_command_quote },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1796,6 +1806,7 @@ command_handler_cmp_by_length (const void *a, const void *b)
|
||||||
static void
|
static void
|
||||||
init_partial_matching_user_command_map (struct str_map *partial)
|
init_partial_matching_user_command_map (struct str_map *partial)
|
||||||
{
|
{
|
||||||
|
// Trivially create a partial matching map
|
||||||
str_map_init (partial);
|
str_map_init (partial);
|
||||||
partial->key_xfrm = tolower_ascii_strxfrm;
|
partial->key_xfrm = tolower_ascii_strxfrm;
|
||||||
|
|
||||||
|
@ -1822,7 +1833,6 @@ init_partial_matching_user_command_map (struct str_map *partial)
|
||||||
static void
|
static void
|
||||||
process_user_command (struct app_context *ctx, char *command)
|
process_user_command (struct app_context *ctx, char *command)
|
||||||
{
|
{
|
||||||
// Trivially create a partial matching map
|
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
struct str_map partial;
|
struct str_map partial;
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
|
@ -1839,36 +1849,28 @@ process_user_command (struct app_context *ctx, char *command)
|
||||||
if (handler)
|
if (handler)
|
||||||
handler->handler (ctx, command);
|
handler->handler (ctx, command);
|
||||||
else
|
else
|
||||||
{
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
// TODO: print a "no such command" error message
|
"%s: %s", "no such command", name);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_message_to_current_buffer (struct app_context *ctx, char *message)
|
send_message_to_current_buffer (struct app_context *ctx, char *message)
|
||||||
{
|
{
|
||||||
struct buffer *buffer = ctx->current_buffer;
|
struct buffer *buffer = ctx->current_buffer;
|
||||||
if (!buffer)
|
hard_assert (buffer != NULL);
|
||||||
{
|
|
||||||
// TODO: print an error message to the global buffer
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (buffer->type)
|
switch (buffer->type)
|
||||||
{
|
{
|
||||||
case BUFFER_GLOBAL:
|
case BUFFER_GLOBAL:
|
||||||
case BUFFER_SERVER:
|
case BUFFER_SERVER:
|
||||||
// TODO: print a message to the buffer that it's not a channel
|
buffer_send_error (ctx, buffer, "this buffer is not a channel");
|
||||||
break;
|
break;
|
||||||
case BUFFER_CHANNEL:
|
case BUFFER_CHANNEL:
|
||||||
// TODO: print a message to the buffer
|
|
||||||
// TODO: autosplit
|
|
||||||
irc_send (ctx, "PRIVMSG %s :%s", buffer->name, message);
|
|
||||||
break;
|
|
||||||
case BUFFER_PM:
|
case BUFFER_PM:
|
||||||
// TODO: print a message to the buffer
|
|
||||||
// TODO: autosplit
|
// TODO: autosplit
|
||||||
irc_send (ctx, "PRIVMSG %s :%s", buffer->name, message);
|
irc_send (ctx, "PRIVMSG %s :%s", buffer->name, message);
|
||||||
|
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
|
||||||
|
ctx->irc_nickname, NULL, "%s", message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1980,8 +1982,7 @@ on_irc_reconnect_timeout (void *user_data)
|
||||||
if (irc_connect (ctx, &e))
|
if (irc_connect (ctx, &e))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FIXME: print to the server buffer
|
buffer_send_error (ctx, ctx->server_buffer, "%s", e->message);
|
||||||
print_error ("%s", e->message);
|
|
||||||
error_free (e);
|
error_free (e);
|
||||||
irc_queue_reconnect (ctx);
|
irc_queue_reconnect (ctx);
|
||||||
}
|
}
|
||||||
|
@ -1990,9 +1991,8 @@ static void
|
||||||
irc_queue_reconnect (struct app_context *ctx)
|
irc_queue_reconnect (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
hard_assert (ctx->irc_fd == -1);
|
hard_assert (ctx->irc_fd == -1);
|
||||||
// FIXME: print to the server buffer
|
buffer_send_status (ctx, ctx->server_buffer,
|
||||||
print_status ("trying to reconnect in %ld seconds...",
|
"trying to reconnect in %ld seconds...", ctx->reconnect_delay);
|
||||||
ctx->reconnect_delay);
|
|
||||||
poller_timer_set (&ctx->reconnect_tmr, ctx->reconnect_delay * 1000);
|
poller_timer_set (&ctx->reconnect_tmr, ctx->reconnect_delay * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2030,8 +2030,7 @@ static void
|
||||||
on_irc_ping_timeout (void *user_data)
|
on_irc_ping_timeout (void *user_data)
|
||||||
{
|
{
|
||||||
struct app_context *ctx = user_data;
|
struct app_context *ctx = user_data;
|
||||||
// FIXME: print to the server buffer
|
buffer_send_error (ctx, ctx->server_buffer, "connection timeout");
|
||||||
print_error ("connection timeout");
|
|
||||||
on_irc_disconnected (ctx);
|
on_irc_disconnected (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2074,13 +2073,13 @@ on_irc_readable (const struct pollfd *fd, struct app_context *ctx)
|
||||||
case IRC_READ_AGAIN:
|
case IRC_READ_AGAIN:
|
||||||
goto end;
|
goto end;
|
||||||
case IRC_READ_ERROR:
|
case IRC_READ_ERROR:
|
||||||
// FIXME: print to the server buffer
|
buffer_send_error (ctx, ctx->server_buffer,
|
||||||
print_error ("reading from the IRC server failed");
|
"reading from the IRC server failed");
|
||||||
disconnected = true;
|
disconnected = true;
|
||||||
goto end;
|
goto end;
|
||||||
case IRC_READ_EOF:
|
case IRC_READ_EOF:
|
||||||
// FIXME: print to the server buffer
|
buffer_send_error (ctx, ctx->server_buffer,
|
||||||
print_status ("the IRC server closed the connection");
|
"the IRC server closed the connection");
|
||||||
disconnected = true;
|
disconnected = true;
|
||||||
goto end;
|
goto end;
|
||||||
case IRC_READ_OK:
|
case IRC_READ_OK:
|
||||||
|
@ -2089,8 +2088,8 @@ on_irc_readable (const struct pollfd *fd, struct app_context *ctx)
|
||||||
|
|
||||||
if (buf->len >= (1 << 20))
|
if (buf->len >= (1 << 20))
|
||||||
{
|
{
|
||||||
// FIXME: print to the server buffer
|
buffer_send_error (ctx, ctx->server_buffer,
|
||||||
print_error ("the IRC server seems to spew out data frantically");
|
"the IRC server seems to spew out data frantically");
|
||||||
irc_shutdown (ctx);
|
irc_shutdown (ctx);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -2142,8 +2141,8 @@ irc_connect (struct app_context *ctx, struct error **e)
|
||||||
{
|
{
|
||||||
char *address = format_host_port_pair (irc_host, irc_port);
|
char *address = format_host_port_pair (irc_host, irc_port);
|
||||||
char *socks_address = format_host_port_pair (socks_host, socks_port);
|
char *socks_address = format_host_port_pair (socks_host, socks_port);
|
||||||
// FIXME: print to the server buffer
|
buffer_send_status (ctx, ctx->server_buffer,
|
||||||
print_status ("connecting to %s via %s...", address, socks_address);
|
"connecting to %s via %s...", address, socks_address);
|
||||||
free (socks_address);
|
free (socks_address);
|
||||||
free (address);
|
free (address);
|
||||||
|
|
||||||
|
@ -2167,8 +2166,7 @@ irc_connect (struct app_context *ctx, struct error **e)
|
||||||
ctx->irc_fd = -1;
|
ctx->irc_fd = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// FIXME: print to the server buffer
|
buffer_send_status (ctx, ctx->server_buffer, "connection established");
|
||||||
print_status ("connection established");
|
|
||||||
|
|
||||||
poller_fd_init (&ctx->irc_event, &ctx->poller, ctx->irc_fd);
|
poller_fd_init (&ctx->irc_event, &ctx->poller, ctx->irc_fd);
|
||||||
ctx->irc_event.dispatcher = (poller_fd_fn) on_irc_readable;
|
ctx->irc_event.dispatcher = (poller_fd_fn) on_irc_readable;
|
||||||
|
@ -2354,7 +2352,7 @@ autofill_user_info (struct app_context *ctx, struct error **e)
|
||||||
if (nickname && username && realname)
|
if (nickname && username && realname)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// TODO: read POSIX user info and fill the configuration if needed
|
// Read POSIX user info and fill the configuration if needed
|
||||||
struct passwd *pwd = getpwuid (geteuid ());
|
struct passwd *pwd = getpwuid (geteuid ());
|
||||||
if (!pwd)
|
if (!pwd)
|
||||||
FAIL ("cannot retrieve user information: %s", strerror (errno));
|
FAIL ("cannot retrieve user information: %s", strerror (errno));
|
||||||
|
@ -2538,8 +2536,7 @@ main (int argc, char *argv[])
|
||||||
if (!load_config (&ctx, &e)
|
if (!load_config (&ctx, &e)
|
||||||
|| !irc_connect (&ctx, &e))
|
|| !irc_connect (&ctx, &e))
|
||||||
{
|
{
|
||||||
// FIXME: print to the global buffer
|
buffer_send_error (&ctx, ctx.global_buffer, "%s", e->message);
|
||||||
print_error ("%s", e->message);
|
|
||||||
error_free (e);
|
error_free (e);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue