12 void Input_FillSelect(int *nfds, fd_set *rfds);
13 void Input_HandleSelect(int nfds, const fd_set *rfds);
14 int ParseUserCommand(char *String);
17 tReadline *gpInput_ReadlineInfo;
20 void Input_FillSelect(int *nfds, fd_set *rfds)
22 if( !gpInput_ReadlineInfo ) {
23 gpInput_ReadlineInfo = Readline_Init(1);
31 void Input_HandleSelect(int nfds, const fd_set *rfds)
36 char *cmd = Readline_NonBlock(gpInput_ReadlineInfo);
41 ParseUserCommand(cmd);
45 SetCursorPos(giTerminal_Height, 1);
46 printf("\x1B[2K"); // Clear line
47 int prompt_len = printf("[%s] ", Window_GetName(NULL));
48 SetCursorPos(giTerminal_Height, prompt_len+1);
54 void Cmd_join(char *ArgString)
57 char *channel_name = GetValue(ArgString, &pos);
59 tServer *srv = Window_GetServer(NULL);
63 Windows_SwitchTo( Window_Create(srv, channel_name) );
65 Server_SendCommand(srv, "JOIN :%s", channel_name);
69 void Cmd_quit(char *ArgString)
71 const char *quit_message = ArgString;
72 if( quit_message == NULL || quit_message[0] == '\0' )
73 quit_message = "/quit - Acess2 IRC Client";
75 Servers_CloseAll(quit_message);
77 Exit(NULL); // NULL = user requested
80 void Cmd_window(char *ArgString)
83 char *window_id = GetValue(ArgString, &pos);
84 int window_num = atoi(window_id);
88 // Get `window_num`th window
89 tWindow *win = Windows_GetByIndex(window_num-1);
92 Windows_SwitchTo( win );
96 // Otherwise, silently ignore
102 for( tWindow *win; (win = Windows_GetByIndex(window_num-1)); window_num ++ )
104 Window_AppendMessage(WINDOW_STATUS, MSG_CLASS_CLIENT, NULL, "%i: %s", window_num, Window_GetName(win));
109 void Cmd_me(char *ArgString)
111 tServer *srv = Window_GetServer(NULL);
112 if( srv && Window_IsChat(NULL) ) {
113 Window_AppendMessage(NULL, MSG_CLASS_ACTION, Server_GetNick(srv), "%s", ArgString);
114 Server_SendCommand(srv, "PRIVMSG %s :\1ACTION %s\1\n", Window_GetName(NULL), ArgString);
120 void (*Fcn)(char *ArgString);
124 {"window", Cmd_window},
128 const int ciNumCommands = sizeof(caCommands)/sizeof(caCommands[0]);
131 * \brief Handle a line from the prompt
133 int ParseUserCommand(char *String)
135 if( String[0] == '/' )
140 command = GetValue(String, &pos)+1;
142 // TODO: Prefix matches
144 for( int i = 0; i < ciNumCommands; i ++ )
146 if( strcmp(command, caCommands[i].Name) == 0 ) {
152 caCommands[cmdIdx].Fcn(String+pos);
156 Window_AppendMessage(WINDOW_STATUS, MSG_CLASS_CLIENT, NULL, "Unknown command %s", command);
162 // - Only send if server is valid and window name is non-empty
163 tServer *srv = Window_GetServer(NULL);
164 if( srv && Window_IsChat(NULL) ) {
165 Window_AppendMessage(NULL, MSG_CLASS_MESSAGE, Server_GetNick(srv), "%s", String);
166 Server_SendCommand(srv, "PRIVMSG %s :%s\n", Window_GetName(NULL), String);