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, 1);
46 printf("\x1B[2K"); // Clear line
47 printf("[%s]", Window_GetName(NULL));
52 void Cmd_join(char *ArgString)
55 char *channel_name = GetValue(ArgString, &pos);
57 tServer *srv = Window_GetServer(NULL);
61 Windows_SwitchTo( Window_Create(srv, channel_name) );
63 Server_SendCommand(srv, "JOIN :%s", channel_name);
67 void Cmd_quit(char *ArgString)
69 const char *quit_message = ArgString;
70 if( quit_message == NULL || quit_message[0] == '\0' )
71 quit_message = "/quit - Acess2 IRC Client";
73 Servers_CloseAll(quit_message);
75 Exit(NULL); // NULL = user requested
78 void Cmd_window(char *ArgString)
81 char *window_id = GetValue(ArgString, &pos);
82 int window_num = atoi(window_id);
86 // Get `window_num`th window
87 tWindow *win = Windows_GetByIndex(window_num-1);
90 Windows_SwitchTo( win );
94 // Otherwise, silently ignore
100 for( tWindow *win; (win = Windows_GetByIndex(window_num-1)); window_num ++ )
102 Window_AppendMessage(WINDOW_STATUS, MSG_CLASS_CLIENT, NULL, "%i: %s", window_num, Window_GetName(win));
109 void (*Fcn)(char *ArgString);
113 {"window", Cmd_window},
117 const int ciNumCommands = sizeof(caCommands)/sizeof(caCommands[0]);
120 * \brief Handle a line from the prompt
122 int ParseUserCommand(char *String)
124 if( String[0] == '/' )
129 command = GetValue(String, &pos)+1;
131 // TODO: Prefix matches
133 for( int i = 0; i < ciNumCommands; i ++ )
135 if( strcmp(command, caCommands[i].Name) == 0 ) {
141 caCommands[cmdIdx].Fcn(String+pos);
145 Window_AppendMessage(WINDOW_STATUS, MSG_CLASS_CLIENT, NULL, "Unknown command %s", command);
151 // - Only send if server is valid and window name is non-empty
152 tServer *srv = Window_GetServer(NULL);
153 if( srv && Window_IsChat(NULL) ) {
154 Window_AppendMessage(NULL, MSG_CLASS_MESSAGE, Server_GetNick(srv), "%s", String);
155 Server_SendCommand(srv, "PRIVMSG %s :%s\n", Window_GetName(NULL), String);