interactor


Vocabulary
ui.tools.listener

Class description
An interactor is an editor intended to be used as the input component of a UI listener.

Interactors are created by calling <interactor>.

Interactors implement the stream-readln, stream-read and stream-read-quot generic words.

Definition
USING: ui.gadgets.editors ;

IN: ui.tools.listener

TUPLE: interactor < source-editor
output history flag mailbox thread waiting token-model
word-model popup ;


Methods
USING: destructors kernel ui.tools.listener ;

M: interactor dispose drop ;


USING: accessors generic kernel models ui.gadgets
ui.tools.listener ;

M: interactor graft*
[ M\ interactor graft* (call-next-method) ]
[ dup word-model>> add-connection ] bi ;


USING: accessors combinators combinators.short-circuit generic
kernel ui.gadgets.glass ui.gestures ui.tools.listener ;

M: interactor handle-gesture
{
{
[ over key-gesture? not ]
[ M\ interactor handle-gesture (call-next-method) ]
}
{
[ dup popup>> ]
[
{
[ pass-to-popup ]
[
M\ interactor handle-gesture
(call-next-method)
]
} 2&&
]
}
{
[ dup token-model>> value>> ]
[
{
[ interactor-operation ]
[
M\ interactor handle-gesture
(call-next-method)
]
} 2&&
]
}
[ M\ interactor handle-gesture (call-next-method) ]
} cond ;


USING: accessors generic kernel models ui.gadgets.status-bar
ui.tools.listener ;

M: interactor model-changed
2dup word-model>> eq? [
dup popup>>
[ 2drop ] [ [ value>> ] dip show-summary ] if
] [ M\ interactor model-changed (call-next-method) ] if ;


USING: io kernel ui.tools.listener ;

M: interactor stream-element-type drop +character+ ;


USING: combinators kernel listener quotations ui.tools.listener
;

M: interactor stream-read-quot
[ interactor-yield ] keep {
{ [ over not ] [ drop ] }
{ [ over callable? ] [ drop ] }
[
[ handle-interactive ] keep swap
[ interactor-finish ] [ nip stream-read-quot ] if
]
} cond ;


USING: io kernel locals math sequences ui.tools.listener ;

M:: interactor stream-read-unsafe
( n buf interactor -- count )
n
[ 0 ] [
drop interactor interactor-read dup [ "\n" join ] when
n short [ head-slice 0 buf copy ] keep
] if-zero ;


USING: io kernel sequences ui.tools.listener ;

M: interactor stream-read-until
swap [ member? ] curry [ [ "\n" join 10 suffix ] ] dip
[ dupd find [ [ head ] when* ] dip dup not ] curry compose
[ [ interactor-read ] curry ] dip [ [ f f f ] if* ] curry
compose [ drop ] produce swap [ concat "" prepend-as ] dip
;


USING: combinators io kernel sequences ui.tools.listener ;

M: interactor stream-read1
dup interactor-read {
{ [ dup not ] [ 2drop f ] }
{ [ dup empty? ] [ drop stream-read1 ] }
{ [ dup first empty? ] [ 2drop 10 ] }
[ nip first first ]
} cond ;


USING: io kernel sequences ui.tools.listener ;

M: interactor stream-readln
interactor-read dup [ first ] when ;


USING: accessors generic kernel models ui.gadgets
ui.tools.listener ;

M: interactor ungraft*
[ dup word-model>> remove-connection ]
[ M\ interactor ungraft* (call-next-method) ] bi ;