jcs
/wallops
/amendments
/70
chatter+irc: Implement /clear, make /quit actually quit and add /disco
jcs made amendment 70 2 months ago
--- chatter.c Sun Sep 8 17:08:17 2024
+++ chatter.c Sun Sep 8 21:51:58 2024
@@ -883,7 +883,6 @@ chatter_resize(struct focusable *focusable, EventRecor
DisposeRgn(savergn);
chatter_update(focusable, NULL);
-
ValidRect(&chatter->win->portRect);
}
@@ -1194,6 +1193,35 @@ chatter_autoscroll(struct chatter *chatter, TEHandle t
TEPinScroll(0, -INT_MAX, te);
SetCtlValue(scroller, GetCtlMax(scroller));
UpdateScrollbarForTE(chatter->win, scroller, te, false);
+}
+
+void
+chatter_clear_messages(struct chatter *chatter, struct chatter_tab *tab)
+{
+ RgnHandle savergn;
+
+ savergn = NewRgn();
+ GetClip(savergn);
+ ClipRect(&zerorect);
+
+ TESetSelect(0, SHRT_MAX, tab->messages_te);
+ TEDelete(tab->messages_te);
+
+ /* scroll up, causing a repaint */
+ TEPinScroll(0, INT_MAX, tab->messages_te);
+
+ /* then scroll back down to what it looked like before we did anything */
+ TEPinScroll(0, -INT_MAX, tab->messages_te);
+
+ chatter_autoscroll(chatter, tab->messages_te, tab->messages_scroller);
+
+ SetClip(savergn);
+ DisposeRgn(savergn);
+
+ if (tab == chatter->current_tab) {
+ chatter_update(chatter->focusable, NULL);
+ ValidRect(&chatter->win->portRect);
+ }
}
void
--- chatter.h Sun Sep 8 17:08:04 2024
+++ chatter.h Sun Sep 8 21:38:55 2024
@@ -97,6 +97,8 @@ void chatter_remove_from_nick_list(struct chatter *cha
struct irc_channel *channel, struct irc_channel_nick *nick, short pos);
void chatter_sync_nick_list(struct chatter *chatter,
struct irc_channel *channel);
+void chatter_clear_messages(struct chatter *chatter,
+ struct chatter_tab *tab);
struct chatter_tab * chatter_add_tab(struct chatter *chatter,
Rect *win_bounds, struct irc_connection *conn,
struct irc_channel *channel, char *query_nick);
--- irc.c Sun Sep 8 20:47:47 2024
+++ irc.c Sun Sep 8 22:01:55 2024
@@ -143,7 +143,6 @@ irc_close_connection(struct irc_connection *conn)
irc_quit_with_message(conn, NULL);
if (conn->stream) {
- _TCPClose(&conn->close_pb, conn->stream, nil, nil, false);
_TCPAbort(&conn->close_pb, conn->stream, nil, nil, false);
_TCPRelease(&conn->close_pb, conn->stream, nil, nil, false);
conn->stream = 0;
@@ -905,6 +904,10 @@ irc_process_input(struct irc_connection *conn, struct
arg0 = strsep(&str, " ");
+ if (strcasecmp(arg0, "clear") == 0) {
+ chatter_clear_messages(conn->chatter, conn->chatter->current_tab);
+ return;
+ }
if (strcasecmp(arg0, "close") == 0) {
if (conn->chatter->current_tab->query_nick[0])
chatter_close_tab(conn->chatter, conn->chatter->current_tab);
@@ -914,6 +917,14 @@ irc_process_input(struct irc_connection *conn, struct
arg0);
return;
}
+ if (strcasecmp(arg0, "disco") == 0 ||
+ strcasecmp(arg0, "discon") == 0 ||
+ strcasecmp(arg0, "disconnect") == 0) {
+ if (conn == NULL)
+ goto not_connected;
+ irc_quit_with_message(conn, str);
+ return;
+ }
if (strcasecmp(arg0, "join") == 0) {
if (conn == NULL)
goto not_connected;
@@ -987,7 +998,12 @@ irc_process_input(struct irc_connection *conn, struct
if (strcasecmp(arg0, "quit") == 0) {
if (conn == NULL)
goto not_connected;
- irc_quit_with_message(conn, str);
+ if (conn->state == IRC_STATE_CONNECTED) {
+ irc_quit_with_message(conn, str);
+ conn->state = IRC_STATE_DISCONNECTED;
+ }
+ if (focusables_quit())
+ ExitToShell();
return;
}
if (strcasecmp(arg0, "quote") == 0) {