 M: participant-changed handle-inbox
     drop update-participants ;
 
-M: object handle-inbox
-    nip print-irc ;
-
-: display ( stream tab -- )
-    '[ , [ [ t ]
-           [ , dup listener>> read-message handle-inbox ]
-           [  ] while ] with-output-stream ] "ircv" spawn drop ;
-
-: <irc-pane> ( tab -- tab pane )
-    <scrolling-pane>
-    [ <pane-stream> swap display ] 2keep ;
-
-TUPLE: irc-editor < editor outstream tab ;
-
-: <irc-editor> ( tab pane -- tab editor )
-    irc-editor new-editor
-    swap <pane-stream> >>outstream ;
-
-: editor-send ( irc-editor -- )
-    { [ outstream>> ]
-      [ [ irc-tab? ] find-parent ]
-      [ editor-string ]
-      [ "" swap set-editor-string ] } cleave
-     '[ , irc-tab set , parse-message ] with-output-stream ;
-
-irc-editor "general" f {
-    { T{ key-down f f "RET" } editor-send }
-    { T{ key-down f f "ENTER" } editor-send }
-} define-command-map
-
-: new-irc-tab ( listener ui-window class -- irc-tab )
-    new-frame
-    swap >>window
-    swap >>listener
-    <irc-pane> [ <scroller> @center grid-add ] keep
-    <irc-editor> <scroller> @bottom grid-add ;
-
-M: irc-tab graft*
-    [ listener>> ] [ window>> client>> ] bi add-listener ;
-
-M: irc-tab ungraft*
-    [ listener>> ] [ window>> client>> ] bi remove-listener ;
-
-TUPLE: irc-channel-tab < irc-tab userlist ;
-
-: <irc-channel-tab> ( listener ui-window -- irc-tab )
-    irc-tab new-irc-tab
-    <pile> [ <scroller> @right grid-add ] keep >>userlist ;
-
 TUPLE: irc-server-tab < irc-tab ;
 
 : <irc-server-tab> ( listener -- irc-tab )
     f irc-server-tab new-irc-tab ;
-
-M: irc-server-tab ungraft*
-    [ window>> client>> terminate-irc ]
-    [ listener>> ] [ window>> client>> ] tri remove-listener ;
 
 : <irc-nick-tab> ( listener ui-window -- irc-tab )
     irc-tab new-irc-tab ;


TUPLE: ui-window < tabbed client ;

TUPLE: irc-tab < frame listener client window ;

: write-color ( str color -- )


: add-gadget-color ( pack seq color -- pack )
    '[ , >>color add-gadget ] each ;

M: object handle-inbox
    nip print-irc ;

: display ( stream tab -- )
    '[ , [ [ t ]
           [ , dup listener>> read-message handle-inbox ]
           [  ] while ] with-output-stream ] "ircv" spawn drop ;

: <irc-pane> ( tab -- tab pane )
    <scrolling-pane>
    [ <pane-stream> swap display ] 2keep ;

TUPLE: irc-editor < editor outstream tab ;

: <irc-editor> ( tab pane -- tab editor )
    irc-editor new-editor
    swap <pane-stream> >>outstream ;

: editor-send ( irc-editor -- )
    { [ outstream>> ]
      [ [ irc-tab? ] find-parent ]
      [ editor-string ]
      [ "" swap set-editor-string ] } cleave
     '[ , irc-tab set , parse-message ] with-output-stream ;

irc-editor "general" f {
    { T{ key-down f f "RET" } editor-send }
    { T{ key-down f f "ENTER" } editor-send }
} define-command-map

: new-irc-tab ( listener ui-window class -- irc-tab )
    new-frame
    swap >>window
    swap >>listener
    <irc-pane> [ <scroller> @center grid-add ] keep
    <irc-editor> <scroller> @bottom grid-add ;

M: irc-tab graft*
    [ listener>> ] [ window>> client>> ] bi add-listener ;

M: irc-tab ungraft*
    [ listener>> ] [ window>> client>> ] bi remove-listener ;

TUPLE: irc-channel-tab < irc-tab userlist ;

: <irc-channel-tab> ( listener ui-window -- irc-tab )
    irc-tab new-irc-tab
    <pile> [ <scroller> @right grid-add ] keep >>userlist ;

: update-participants ( tab -- )
    [ userlist>> [ clear-gadget ] keep ]
