The store program prepared above is a solution in search of a purpose.
It can become a more useful program if the text that is stored is written to the clipboard when recalled.
This is done by making a new clipStore class that extends the store class.
-- clipStore.roo shared clipboard clipStore : class extends store initialize : method clipboard = ^^ clipboard return '' remember : method select when arg() = 2 then -- ADD an association return 'base' ~ remember( arg(1), arg(2) ) when arg() = 1 then do -- RECALL association v = 'base' ~ remember( arg(1) ) if v <> '' then clipboard ~ setText( v ) return v end otherwise return 'base' ~ remember() end
Now the store.rooProgram needs to create an instance of a clipStore class instead of a store class.
No other changes are required.
-- store2.rooProgram store = ^^ clipStore -- prepare the 'clipStore' object call showUsage signal on halt do forever parse linein request +1 key '=' value key = strip( key ) value = strip( value ) select when request = '' then nop when request = '+' then store ~ remember( key, value ) when request = '?' then say store ~ remember( key ) when request = '-' then store ~ forget( key ) when request = 'k' then say store ~ listKeys when request = '!' then say store ~ listAll when translate( request ) = 'Q' then exit 0 otherwise call showUsage end end halt : exit 0 showUsage : procedure say 'Usage:' say ' + key = value -- adds a value' say ' ? key -- locates value associated with key' say ' - key -- forgets value associated with key' say ' k -- lists all keys' say ' ! -- lists all associations' say ' Q -- terminates' return