     [ current>> clear-gadget ]
     bi ;
 
+: init-prototype ( pane -- pane )
+    <shelf> +baseline+ >>align >>prototype ; inline
+
+: init-output ( pane -- pane )
+    <incremental> [ >>output ] [ f track-add ] bi ; inline
+
+: pane-theme ( pane -- pane )
+    1 >>fill
+    selection-color >>selection-color ; inline
+
+: init-last-line ( pane -- pane )
+    horizontal <track> [ >>last-line ] [ 1 track-add ] bi ; inline
+
 : new-pane ( input class -- pane )
     [ vertical ] dip new-track
         swap >>input
-        1 >>fill
-        <shelf> +baseline+ >>align >>prototype
-        <incremental> [ >>output ] [ f track-add ] bi
-        dup prepare-last-line
-        selection-color >>selection-color ; inline
+        pane-theme
+        init-prototype
+        init-output
+        init-current
+        init-last-line ; inline
 
 : <pane> ( -- pane ) f pane new-pane ;
 

    f >>caret f >>mark ; inline

: prepare-last-line ( pane -- )
    clear-selection
    [ last-line>> unparent ]
    [
        [ horizontal <track> ] dip
        dup prototype>> clone >>current
        [ current>> f track-add ]
        [ input>> [ 1 track-add ] when* ]
        [ swap [ >>last-line ] [ 1 track-add ] bi drop ]
        tri
    ]
    [ input>> [ request-focus ] when* ] tri ;

: pane-caret&mark ( pane -- caret mark )

    [
        [ current>> [ unparent ] [ smash-line ] bi ] [ output>> ] bi
        add-incremental
    ] [ next-line ] bi ;

: pane-write ( seq pane -- )
    [ pane-nl ] [ current>> stream-write ]
