Add beginnings of input handling
This commit is contained in:
		
							parent
							
								
									26e9dd9adf
								
							
						
					
					
						commit
						43845c6115
					
				
							
								
								
									
										12
									
								
								chat.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								chat.c
									
									
									
									
									
								
							| @ -15,7 +15,9 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <err.h> | #include <err.h> | ||||||
|  | #include <errno.h> | ||||||
| #include <locale.h> | #include <locale.h> | ||||||
|  | #include <poll.h> | ||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| @ -98,8 +100,16 @@ int main(int argc, char *argv[]) { | |||||||
| 	ircFormat("NICK :%s\r\n", nick); | 	ircFormat("NICK :%s\r\n", nick); | ||||||
| 	ircFormat("USER %s 0 * :%s\r\n", user, real); | 	ircFormat("USER %s 0 * :%s\r\n", user, real); | ||||||
| 
 | 
 | ||||||
|  | 	struct pollfd fds[2] = { | ||||||
|  | 		{ .events = POLLIN, .fd = STDIN_FILENO }, | ||||||
|  | 		{ .events = POLLIN, .fd = irc }, | ||||||
|  | 	}; | ||||||
| 	for (;;) { | 	for (;;) { | ||||||
|  | 		int nfds = poll(fds, 2, -1); | ||||||
|  | 		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll"); | ||||||
|  | 
 | ||||||
|  | 		if (fds[0].revents) uiRead(); | ||||||
|  | 		if (fds[1].revents) ircRecv(); | ||||||
| 		uiDraw(); | 		uiDraw(); | ||||||
| 		ircRecv(); |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								chat.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								chat.h
									
									
									
									
									
								
							| @ -115,6 +115,7 @@ void uiShow(void); | |||||||
| void uiHide(void); | void uiHide(void); | ||||||
| void uiDraw(void); | void uiDraw(void); | ||||||
| void uiShowID(size_t id); | void uiShowID(size_t id); | ||||||
|  | void uiRead(void); | ||||||
| void uiWrite(size_t id, enum Heat heat, const time_t *time, const char *str); | void uiWrite(size_t id, enum Heat heat, const time_t *time, const char *str); | ||||||
| void uiFormat( | void uiFormat( | ||||||
| 	size_t id, enum Heat heat, const time_t *time, const char *format, ... | 	size_t id, enum Heat heat, const time_t *time, const char *format, ... | ||||||
|  | |||||||
							
								
								
									
										45
									
								
								ui.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								ui.c
									
									
									
									
									
								
							| @ -14,6 +14,8 @@ | |||||||
|  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 |  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | #define _XOPEN_SOURCE_EXTENDED | ||||||
|  | 
 | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| #include <curses.h> | #include <curses.h> | ||||||
| @ -192,7 +194,7 @@ void uiInit(void) { | |||||||
| 	keypad(input, true); | 	keypad(input, true); | ||||||
| 	nodelay(input, true); | 	nodelay(input, true); | ||||||
| 	windows.active = windowFor(Network); | 	windows.active = windowFor(Network); | ||||||
| 	//uiShow();
 | 	uiShow(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void uiDraw(void) { | void uiDraw(void) { | ||||||
| @ -397,3 +399,44 @@ void uiFormat( | |||||||
| 	assert((size_t)len < sizeof(buf)); | 	assert((size_t)len < sizeof(buf)); | ||||||
| 	uiWrite(id, heat, time, buf); | 	uiWrite(id, heat, time, buf); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | static void keyCode(int code) { | ||||||
|  | 	switch (code) { | ||||||
|  | 		break; case KEY_RESIZE:; // TODO
 | ||||||
|  | 		break; case KeyFocusIn:; // TODO
 | ||||||
|  | 		break; case KeyFocusOut: windows.active->mark = true; | ||||||
|  | 		break; case KeyPasteOn:; // TODO
 | ||||||
|  | 		break; case KeyPasteOff:; // TODO
 | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void keyMeta(wchar_t ch) { | ||||||
|  | 	switch (ch) { | ||||||
|  | 		break; case L'm': uiWrite(windows.active->id, Cold, NULL, ""); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void keyChar(wchar_t ch) { | ||||||
|  | 	switch (ch) { | ||||||
|  | 		break; case CTRL(L'L'): clearok(curscr, true); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void uiRead(void) { | ||||||
|  | 	int ret; | ||||||
|  | 	wint_t ch; | ||||||
|  | 	static bool meta; | ||||||
|  | 	while (ERR != (ret = wget_wch(input, &ch))) { | ||||||
|  | 		if (ret == KEY_CODE_YES) { | ||||||
|  | 			keyCode(ch); | ||||||
|  | 		} else if (ch == '\33') { | ||||||
|  | 			meta = true; | ||||||
|  | 			continue; | ||||||
|  | 		} else if (meta) { | ||||||
|  | 			keyMeta(ch); | ||||||
|  | 		} else { | ||||||
|  | 			keyChar(ch); | ||||||
|  | 		} | ||||||
|  | 		meta = false; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user