! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: gadgets-panes USING: arrays gadgets gadgets-buttons gadgets-editors gadgets-labels gadgets-layouts gadgets-scrolling gadgets-theme generic hashtables io kernel line-editor math namespaces sequences strings styles threads ; ! A pane is an area that can display text. ! output: pile ! current: shelf ! input: editor TUPLE: pane output active current input prototype continuation scrolls? ; : add-output 2dup set-pane-output add-gadget ; : ( current input -- line ) [ 2array ] [ 1array ] if* make-shelf ; : init-line ( pane -- ) dup pane-prototype clone swap set-pane-current ; : prepare-line ( pane -- ) dup init-line dup pane-active unparent [ dup pane-current swap pane-input ] keep 2dup set-pane-active add-gadget ; : pop-continuation ( pane -- quot ) dup pane-continuation f rot set-pane-continuation ; : pane-eval ( string pane -- ) pop-continuation dup [ [ continue-with ] in-thread ] when 2drop ; SYMBOL: structured-input : pane-call ( quot pane -- ) "<< command >>" over stream-print >r structured-input set-global "\"structured-input\" \"gadgets-panes\" lookup global hash call" r> pane-eval ; : editor-commit ( editor -- line ) #! Add current line to the history, and clear the editor. [ commit-history line-text get line-clear ] with-editor ; : replace-input ( string pane -- ) pane-input set-editor-text ; : print-input ( string pane -- ) [ dup [ presented set bold font-style set ] make-hash format terpri ] with-stream* ; : pane-commit ( pane -- ) dup pane-input editor-commit swap 2dup print-input pane-eval ; : pane-clear ( pane -- ) dup pane-output clear-incremental pane-current clear-gadget ; : pane-actions ( line -- ) H{ { [ button-down ] [ pane-input click-editor ] } { [ "RETURN" ] [ pane-commit ] } { [ "UP" ] [ pane-input [ history-prev ] with-editor ] } { [ "DOWN" ] [ pane-input [ history-next ] with-editor ] } { [ "CTRL" "l" ] [ pane-clear ] } } add-actions ; C: pane ( -- pane ) over set-delegate over set-pane-prototype over add-output dup prepare-line ; : ( -- pane ) t over set-pane-scrolls? "" over set-pane-input dup pane-actions ; M: pane focusable-child* ( pane -- editor ) pane-input [ t ] unless* ; : prepare-print ( current -- gadget ) #! Optimization: if line has 1 child, add the child. dup gadget-children { { [ dup empty? ] [ 2drop ""