| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | ! Copyright (C) 2008 William Schlieper | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | USING: accessors kernel threads combinators concurrency.mailboxes | 
					
						
							|  |  |  |        sequences strings hashtables splitting fry assocs hashtables | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |        ui ui.gadgets ui.gadgets.panes ui.gadgets.editors | 
					
						
							|  |  |  |        ui.gadgets.scrollers ui.commands ui.gadgets.frames ui.gestures | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |        ui.gadgets.tabs ui.gadgets.grids ui.gadgets.lists ui.gadgets.labels | 
					
						
							|  |  |  |        io io.styles namespaces calendar calendar.format models | 
					
						
							| 
									
										
										
										
											2008-07-16 00:02:04 -04:00
										 |  |  |        irc.client irc.client.private irc.messages irc.messages.private | 
					
						
							|  |  |  |        irc.ui.commandparser irc.ui.load ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | IN: irc.ui | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  | SYMBOL: listener | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | SYMBOL: client | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TUPLE: ui-window client tabs ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | TUPLE: irc-tab < frame listener client listmodel ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | : write-color ( str color -- )
 | 
					
						
							|  |  |  |     foreground associate format ;
 | 
					
						
							|  |  |  | : red { 0.5 0 0 1 } ;
 | 
					
						
							|  |  |  | : green { 0 0.5 0 1 } ;
 | 
					
						
							|  |  |  | : blue { 0 0 1 1 } ;
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | : black { 0 0 0 1 } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : colors H{ { +operator+ { 0 0.5 0 1 } } | 
					
						
							|  |  |  |             { +voice+ { 0 0 1 1 } } | 
					
						
							|  |  |  |             { +normal+ { 0 0 0 1 } } } ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  | : dot-or-parens ( string -- string )
 | 
					
						
							|  |  |  |     dup empty? [ drop "." ] | 
					
						
							|  |  |  |     [ "(" prepend ")" append ] if ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | GENERIC: write-irc ( irc-message -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: privmsg write-irc | 
					
						
							|  |  |  |     "<" blue write-color | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     [ prefix>> parse-name write ] keep
 | 
					
						
							| 
									
										
										
										
											2008-07-11 17:11:03 -04:00
										 |  |  |     "> " blue write-color | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |     trailing>> write ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-11 17:11:03 -04:00
										 |  |  | TUPLE: own-message message nick timestamp ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <own-message> ( message nick -- own-message )
 | 
					
						
							|  |  |  |     now own-message boa ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: own-message write-irc | 
					
						
							|  |  |  |     "<" blue write-color | 
					
						
							|  |  |  |     [ nick>> bold font-style associate format ] keep
 | 
					
						
							|  |  |  |     "> " blue write-color | 
					
						
							|  |  |  |     message>> write ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | M: join write-irc | 
					
						
							|  |  |  |     "* " green write-color | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     prefix>> parse-name write
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |     " has entered the channel." green write-color ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: part write-irc | 
					
						
							|  |  |  |     "* " red write-color | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     [ prefix>> parse-name write ] keep
 | 
					
						
							|  |  |  |     " has left the channel" red write-color | 
					
						
							|  |  |  |     trailing>> dot-or-parens red write-color ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: quit write-irc | 
					
						
							|  |  |  |     "* " red write-color | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     [ prefix>> parse-name write ] keep
 | 
					
						
							|  |  |  |     " has left IRC" red write-color | 
					
						
							|  |  |  |     trailing>> dot-or-parens red write-color ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | M: mode write-irc | 
					
						
							|  |  |  |     "* " blue write-color | 
					
						
							|  |  |  |     [ name>> write ] keep
 | 
					
						
							|  |  |  |     " has applied mode " blue write-color | 
					
						
							|  |  |  |     [ mode>> write ] keep
 | 
					
						
							|  |  |  |     " to " blue write-color | 
					
						
							|  |  |  |     channel>> write ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | M: irc-end write-irc | 
					
						
							|  |  |  |     drop "* You have left IRC" red write-color ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: irc-disconnected write-irc | 
					
						
							|  |  |  |     drop "* Disconnected" red write-color ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: irc-connected write-irc | 
					
						
							|  |  |  |     drop "* Connected" green write-color ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: irc-message write-irc | 
					
						
							|  |  |  |     drop ; ! catch all unimplemented writes, THIS WILL CHANGE     | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : print-irc ( irc-message -- )
 | 
					
						
							| 
									
										
										
										
											2008-07-11 17:11:03 -04:00
										 |  |  |     [ timestamp>> timestamp>hms write " " write ] | 
					
						
							|  |  |  |     [ write-irc nl ] bi ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  | : send-message ( message -- )
 | 
					
						
							|  |  |  |     [ print-irc ] | 
					
						
							|  |  |  |     [ listener get write-message ] bi ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | GENERIC: handle-inbox ( tab message -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : filter-participants ( assoc val -- alist )
 | 
					
						
							|  |  |  |     [ >alist ] dip
 | 
					
						
							|  |  |  |    '[ second , = ] filter ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : update-participants ( tab -- )
 | 
					
						
							|  |  |  |     [ listmodel>> ] [ listener>> participants>> ] bi
 | 
					
						
							|  |  |  |     [ +operator+ filter-participants ] | 
					
						
							|  |  |  |     [ +voice+ filter-participants ] | 
					
						
							|  |  |  |     [ +normal+ filter-participants ] tri
 | 
					
						
							|  |  |  |     append append swap set-model ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: participant-changed handle-inbox | 
					
						
							|  |  |  |     drop update-participants ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: object handle-inbox | 
					
						
							|  |  |  |     nip print-irc ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : display ( stream tab -- )
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |     '[ , [ [ t ] | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |            [ , dup listener>> read-message handle-inbox ] | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |            [  ] while ] with-output-stream ] "ircv" spawn drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | : <irc-pane> ( tab -- tab pane )
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |     <scrolling-pane> | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |     [ <pane-stream> swap display ] 2keep ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-11 16:31:35 -04:00
										 |  |  | TUPLE: irc-editor < editor outstream listener client ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | : <irc-editor> ( tab pane -- tab editor )
 | 
					
						
							|  |  |  |     over irc-editor new-editor | 
					
						
							|  |  |  |     swap listener>> >>listener swap <pane-stream> >>outstream | 
					
						
							| 
									
										
										
										
											2008-07-15 02:46:49 -04:00
										 |  |  |     over client>> >>client ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : editor-send ( irc-editor -- )
 | 
					
						
							|  |  |  |     { [ outstream>> ] | 
					
						
							|  |  |  |       [ listener>> ] | 
					
						
							|  |  |  |       [ client>> ] | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |       [ editor-string ] | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |       [ "" swap set-editor-string ] } cleave
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |      '[ , listener set , client set , parse-message ] with-output-stream ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | irc-editor "general" f { | 
					
						
							|  |  |  |     { T{ key-down f f "RET" } editor-send } | 
					
						
							|  |  |  |     { T{ key-down f f "ENTER" } editor-send } | 
					
						
							|  |  |  | } define-command-map | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | : <irc-list> ( -- gadget model )
 | 
					
						
							|  |  |  |     [ drop ] | 
					
						
							|  |  |  |     [ first2 [ <label> ] dip >>color ] | 
					
						
							|  |  |  |     { } <model> [ <list> ] keep ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <irc-tab> ( listener client -- irc-tab )
 | 
					
						
							|  |  |  |     irc-tab new-frame | 
					
						
							|  |  |  |     swap client>> >>client swap >>listener | 
					
						
							| 
									
										
										
										
											2008-07-25 13:34:41 -04:00
										 |  |  |     <irc-pane> [ <scroller> @center grid-add ] keep
 | 
					
						
							|  |  |  |     <irc-editor> <scroller> @bottom grid-add ;
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <irc-channel-tab> ( listener client -- irc-tab )
 | 
					
						
							|  |  |  |     <irc-tab> | 
					
						
							| 
									
										
										
										
											2008-07-25 13:34:41 -04:00
										 |  |  |     <irc-list> [ <scroller> @right grid-add ] dip >>listmodel | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |     [ update-participants ] keep ;
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | : <irc-server-tab> ( listener client -- irc-tab )
 | 
					
						
							|  |  |  |     <irc-tab> ;
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | M: irc-tab graft* | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     [ listener>> ] [ client>> ] bi
 | 
					
						
							|  |  |  |     add-listener ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  | M: irc-tab ungraft* | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     [ listener>> ] [ client>> ] bi
 | 
					
						
							|  |  |  |     remove-listener ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : join-channel ( name ui-window -- )
 | 
					
						
							|  |  |  |     [ dup <irc-channel-listener> ] dip
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |     [ <irc-channel-tab> swap ] keep
 | 
					
						
							| 
									
										
										
										
											2008-07-14 20:53:08 -04:00
										 |  |  |     tabs>> add-page ;
 | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : irc-window ( ui-window -- )
 | 
					
						
							|  |  |  |     [ tabs>> ] | 
					
						
							|  |  |  |     [ client>> profile>> server>> ] bi
 | 
					
						
							|  |  |  |     open-window ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ui-connect ( profile -- ui-window )
 | 
					
						
							|  |  |  |     <irc-client> ui-window new over >>client swap
 | 
					
						
							|  |  |  |     [ connect-irc ] | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |     [ listeners>> +server-listener+ swap at over <irc-tab> | 
					
						
							| 
									
										
										
										
											2008-07-10 02:38:48 -04:00
										 |  |  |       "Server" associate <tabbed> >>tabs ] bi ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-16 00:02:04 -04:00
										 |  |  | : server-open ( server port nick password channels -- )
 | 
					
						
							|  |  |  |     [ <irc-profile> ui-connect [ irc-window ] keep ] dip
 | 
					
						
							| 
									
										
										
										
											2008-07-16 19:33:33 -04:00
										 |  |  |     [ over join-channel ] each drop ;
 | 
					
						
							| 
									
										
										
										
											2008-07-16 00:02:04 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : main-run ( -- ) run-ircui ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MAIN: main-run |