From 510f68e9ad65c5c76a29dad03ef1361032df615f Mon Sep 17 00:00:00 2001 From: James Crook Date: Sun, 11 Feb 2018 09:00:23 +0000 Subject: [PATCH] Fix \n shenanigans in command output. --- scripts/piped-work/docimages_tracks.py | 23 +++++++---------------- scripts/piped-work/pipe_test.py | 12 ++++++------ src/commands/Command.cpp | 3 ++- src/commands/CommandTargets.h | 12 ++++++++++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/scripts/piped-work/docimages_tracks.py b/scripts/piped-work/docimages_tracks.py index d1c523b5b..0888dbd20 100644 --- a/scripts/piped-work/docimages_tracks.py +++ b/scripts/piped-work/docimages_tracks.py @@ -39,7 +39,7 @@ print( "-- File to read from has now been opened too\r\n" ) def sendCommand( command ) : - print( "Send: >>> "+command ) + print( "Send: >>> \n"+command ) tofile.write( command + EOL ) tofile.flush() @@ -55,7 +55,7 @@ def getResponse() : def doCommand( command ) : sendCommand( command ) response = getResponse() - print( "Rcvd: <<< " + response ) + print( "Rcvd: <<< \n" + response ) return response def do( command ) : @@ -63,9 +63,6 @@ def do( command ) : def quickTest() : do( 'Help: Command=Help' ) - do( 'Help: Command="SetTrackInfo"' ) - do( 'SetPreference: Name=GUI/Theme Value=light Reload=false' ) - def setup() : global path @@ -169,25 +166,20 @@ def image8() : # Zoomed in to show points stem-plot def image9() : global path - do( 'SetPreference: Name=/GUI/SampleView Value=1 Reload=True') makeMonoTracks(1) do( 'SelectTime: StartTime=0 EndTime=0.003' ) do( 'ZoomSel' ); do( 'Amplify: Ratio=3.0' ) + do( 'SetPreference: Name=/GUI/SampleView Value=1 Reload=1') do( 'Screenshot: Path='+path+' CaptureWhat=First_Track' ) # Zoomed in to show points no stem plot -def image10() : +def image9and10() : global path - do( 'SetPreference: Name=/GUI/SampleView Value=0 Reload=True') - makeMonoTracks(1) - do( 'SelectTime: StartTime=0 EndTime=0.003' ) - do( 'ZoomSel' ); - do( 'Amplify: Ratio=3.0' ) + image9() + do( 'SetPreference: Name=/GUI/SampleView Value=0 Reload=1') do( 'Screenshot: Path='+path+' CaptureWhat=First_Track' ) - - #quickTest() setup() image1() @@ -198,6 +190,5 @@ image5() image6() image7() image8() -image9() -image10() +image9and10() diff --git a/scripts/piped-work/pipe_test.py b/scripts/piped-work/pipe_test.py index 373d492e7..4a8ec4ddd 100644 --- a/scripts/piped-work/pipe_test.py +++ b/scripts/piped-work/pipe_test.py @@ -1,6 +1,6 @@ -# pipe-test.py +# pipe_test.py # Tests the audacity pipe. Sends 3 commands. -# Keep pipe-test.py short!! +# Keep pipe_test.py short!! # You can make more complicated longer tests to test other functionality # or to generate screenshots etc in other scripts. @@ -41,7 +41,7 @@ print( "-- File to read from has now been opened too\r\n" ) def sendCommand( command ) : - print( "Send: >>> "+command ) + print( "Send: >>> \n"+command ) tofile.write( command + EOL ) tofile.flush() @@ -57,7 +57,7 @@ def getResponse() : def doCommand( command ) : sendCommand( command ) response = getResponse() - print( "Rcvd: <<< " + response ) + print( "Rcvd: <<< \n" + response ) return response def do( command ) : @@ -65,7 +65,7 @@ def do( command ) : def quickTest() : do( 'Help: Command=Help' ) - do( 'Help: Command="SetTrackInfo"' ) - do( 'SetPreference: Name=GUI/Theme Value=light Reload=false' ) + #do( 'Help: Command="GetInfo"' ) + do( 'SetPreference: Name=GUI/Theme Value=dark Reload=1' ) quickTest() diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 16a015eff..52e8b51a7 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -149,7 +149,8 @@ bool ApplyAndSendResponse::Apply() bool bResult = mCommand->Apply(*( mCtx.get())); return bResult; } ); - wxString response = GetName(); + wxString response = wxT( "\n" ); + response += GetName(); // These three strings are deliberately not localised. // They are used in script responses and always happen in English. response += wxT(" finished: "); diff --git a/src/commands/CommandTargets.h b/src/commands/CommandTargets.h index a6302831b..1a23e48c2 100644 --- a/src/commands/CommandTargets.h +++ b/src/commands/CommandTargets.h @@ -218,17 +218,25 @@ class ResponseQueueTarget final : public CommandMessageTarget { private: ResponseQueue &mResponseQueue; + wxString mBuffer; public: ResponseQueueTarget(ResponseQueue &responseQueue) - : mResponseQueue(responseQueue) + : mResponseQueue(responseQueue), + mBuffer( wxEmptyString ) { } virtual ~ResponseQueueTarget() { + if( mBuffer.StartsWith("\n" ) ) + mBuffer = mBuffer.Mid( 1 ); + mResponseQueue.AddResponse( mBuffer ); mResponseQueue.AddResponse(wxString(wxT("\n"))); } void Update(const wxString &message) override { - mResponseQueue.AddResponse(message); + mBuffer += message; +#if 0 + mResponseQueue.AddResponse(message); +#endif } };