anchor.diff:  	% text from clipboard
   	% wxEvtHandler:connect(TextInput,command_text_paste,[{skip,false}]),
   	wxEvtHandler:connect(TextInput,key_down,[{callback,fun input/2},{userData,{TextInput,?PROMPT}}]),
  -	wxloop(TextDisplay,TextInput,?PROMPT).
  -
  -wxloop(Disp,Input,Prompt) ->
  +	wxloop(#wc{wx = Wx, dlg = Dlg, input = TextInput, disp = TextDisplay}),
  +	wx:destroy(Wx).
  +
  +wxloop(P) ->
   	receive
   		{prompt,Str} ->
  -			wxTextCtrl:setValue(Input,Str),
  -			wxTextCtrl:setInsertionPoint(Input,length(Str)),
  -			wxEvtHandler:disconnect(Input,key_down),
  -			wxEvtHandler:connect(Input,key_down,[{callback,fun input/2},{userData,{Input,Str}}]),
  -			wxloop(Disp,Input,Str);
  +			wxTextCtrl:setValue(P#wc.input,Str),
  +			wxTextCtrl:setInsertionPoint(P#wc.input,length(Str)),
  +			wxEvtHandler:disconnect(P#wc.input,key_down),
  +			wxEvtHandler:connect(P#wc.input,key_down,[{callback,fun input/2},{userData,{P#wc.input,Str}}]),
  +			self() ! {print,""},
  +			wxloop(P#wc{prompt = Str});
   		{print,Str} ->
  -			wxTextCtrl:writeText(Disp,Str),
  -			wxTextCtrl:writeText(Disp,"\n"),
  -			wxloop(Disp,Input,Prompt);
  +			wxTextCtrl:writeText(P#wc.disp,Str),
  +			wxTextCtrl:writeText(P#wc.disp,"\n"),
  +			wxloop(P);
  +		up ->
  +			case P#wc.history_pos of
  +				0 ->
  +					Str = wxTextCtrl:getValue(P#wc.input),
  +					Cur = lists:sublist(Str,length(P#wc.prompt)+1,length(Str));
  +				_ ->
  +					Cur = P#wc.current
  +			end,
  +			case catch lists:nth(P#wc.history_pos+1,P#wc.history) of
  +				{'EXIT',_} ->
  +					wxloop(P);
  +				NewStr ->
  +					wxTextCtrl:setValue(P#wc.input,P#wc.prompt++NewStr),
  +					wxTextCtrl:setInsertionPoint(P#wc.input,length(NewStr)+length(P#wc.prompt)),
  +					wxloop(P#wc{current = Cur, history_pos = P#wc.history_pos+1})
  +			end;
   		down ->
  -			wxloop(Disp,Input,Prompt);
  -		up ->
  -			wxloop(Disp,Input,Prompt);
  -		Wx when Wx#wx.obj == Input ->
  +			case P#wc.history_pos > 0 of
  +				true ->
  +					case P#wc.history_pos > 1 of
  +						true ->
  +							Str = lists:nth(P#wc.history_pos-1,P#wc.history);
  +						false ->
  +							Str = P#wc.current
  +					end,
  +					wxTextCtrl:setValue(P#wc.input,P#wc.prompt++Str),
  +					wxTextCtrl:setInsertionPoint(P#wc.input,length(Str)+length(P#wc.prompt)),
  +					wxloop(P#wc{history_pos = P#wc.history_pos-1});
  +				false ->
  +					wxloop(P)
  +			end;
  +		stop ->
  +			ok;
  +		Wx when Wx#wx.obj == P#wc.input ->
   			Cmd = Wx#wx.event,
   			case Cmd of
   				#wxMouse{} ->
   					% self() ! {print,"MOUSE!"},
  -					wxloop(Disp,Input,Prompt);
  +					wxloop(P);
   				% #wxClipboardText{} ->
   				% 	Clip = wxClipboard:get(),
   				% 	self() ! {print,io_lib:fwrite("~p~n",[get(clip)])},
   				% 	wxloop(Disp,Input,Prompt);
   				_ ->
  -					wxTextCtrl:setValue(Input,Prompt),
  -					wxTextCtrl:setInsertionPoint(Input,length(Prompt)),
  +					wxTextCtrl:setValue(P#wc.input,P#wc.prompt),
  +					wxTextCtrl:setInsertionPoint(P#wc.input,length(P#wc.prompt)),
   					Str = Cmd#wxCommand.cmdString,
  -					wxTextCtrl:writeText(Disp,Str),
  -					wxTextCtrl:writeText(Disp,"\n"),
  -					Print = lists:sublist(Str,length(Prompt)+1,length(Str)),
  -					home ! {exec, unicode:characters_to_binary(Print)},
  -					wxloop(Disp,Input,Prompt)
  +					Print = lists:sublist(Str,length(P#wc.prompt)+1,length(Str)),
  +					case Print of
  +						"open" ->
  +							% spawn(fun() ->
  +							% {wildCard,"*.sql"}
  +							File = wxFileDialog:new(P#wc.dlg,[{defaultDir,"."}]),
  +							case wxDialog:showModal(File) == ?wxID_OK of
  +								true ->
  +									home ! {dofile,wxFileDialog:getPath(File)};
  +								_ ->
  +									ok
  +							end,
  +							wxFileDialog:destroy(File),
  +							wxWindow:setFocus(P#wc.input);
  +							% end);
  +						_ ->
  +							self() ! {print,Str},
  +							home ! {exec, unicode:characters_to_binary(Print)}
  +					end,
  +					wxloop(P#wc{history = [Print|P#wc.history]})
   			end;
   		Wx ->
   			Cmd = Wx#wx.event,
  
positive.code: 			io:format("Received ~p~n",[X])
  	end.
  
  wxrun() ->
  	register(wxproc,self()),
  	Wx = wx:new(),
  
negative.code: 				#wxClose{} ->
  					halt(1);
  				_ ->
  					wxloop(P)
  			end
  	end.
  
  