Code covered by the BSD License  

Highlights from
setPrompt - Set the Command Window prompt

5.0

5.0 | 10 ratings Rate this file 58 Downloads (last 30 days) File Size: 11.9 KB File ID: #26471
image thumbnail

setPrompt - Set the Command Window prompt

by

 

24 Jan 2010 (Updated )

Sets the Command Window prompt to the specified string

| Watch this File

File Information
Description

setPrompt(newPrompt) sets the Command Window prompt to the specified NEWPROMPT.
NEWPROMPT can be one of the following:
 
       - a static string: setPrompt('>> ')
              => this is the default prompt string ('>> ')
 
       - an evaluable string: setPrompt('datestr(now)')
              => the new prompt will look like: '25-Jan-2010 01:00:51'
              Note: the evaluable string is expected to return a string
 
       - an evaluable function: setPrompt(@()(['[',datestr(now),'] ']))
              => the new prompt will look like: '[25-Jan-2010 01:00:51] '
              Note: the evaluable function is expected to return a string
 
       - the static string 'timestamp' will continuously update the last (current)
         prompt with the current time: '[25-Jan-2010 01:00:51] '. This has
         the effect of displaying desktop command execution times.
         The 'timestamp' string can be used with other static text to
         customize its appearance. For example: setPrompt('<timestamp!> ').
       - an empty value or no input argument restores the default prompt
 
Examples:
     setPrompt('[-]') % Replaces '>> ' prompt with '[-]'
     setPrompt('%') % => '% ' (space-padded)
     setPrompt('sprintf(''<%f>'',now)') % => '<734163.056262>'
     setPrompt('datestr(now)') % => '25-Jan-2010 01:00:51' (unchanging)
     setPrompt('[''['',datestr(now),''] '']') % => '[25-Jan-2010 01:00:51] '
     setPrompt(@()(['[',datestr(now),'] '])) % => '[25-Jan-2010 01:00:51] '
         (note that these are the same: the first uses an evaluable string,
          while the second uses an evaluable function)
     setPrompt('timestamp') % => '[25-Jan-2010 01:00:51] ' (continuously-updated)
     setPrompt('<timestamp> ') % => '<25-Jan-2010 01:00:51> ' (continuously-updated)
     setPrompt('>> ') % restores the default prompt
     setPrompt('') % restores the default prompt
     setPrompt % restores the default prompt
 
Warning:
     This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!
 
Technical explanation:
     A technical explanation of the code in this utility can be found on http://undocumentedmatlab.com/blog/setprompt-setting-matlab-desktop-prompt/
 
Bugs and suggestions:
     Please send to Yair Altman (altmany at gmail dot com)

Acknowledgements

Cprintf Display Formatted Colored Text In The Command Window inspired this file.

MATLAB release MATLAB 7.6 (R2008a)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (16)
10 Oct 2014 Yair Altman

@Qun HAN - I've updated the utility for R2014a & R2014b. Download the latest version.

10 Oct 2014 Qun HAN

In MATLAB R2014A, I got the following error.

Error using setPrompt (line 115)
The name 'CaretUpdateCallback' is not an accessible property for an instance of class 'com.mathworks.mde.cmdwin.XCmdWndView'

28 Jul 2013 Laurent

This is what I was looking for
Thx Yair

04 Jul 2013 Markus Leuthold

Hi Yair

Great submission! Two questions

1) I've put setPrompt into startup.m. However, it doesn't work from there. I'm sure setPrompt is executed (added a disp statement to verify). It works fine AFTER Matlab is started

2) Any idea how to change the caret color? I've added
set(jTextArea,'caretColor',[1 0 0]);
to your code, but it doesn't seem to work. Neither does your uiinspect work on the property 'caretColor'

thanks!

24 Jan 2013 Gary  
13 Sep 2012 Skirmante

Hi,
really useful function, only one request. Could you look into debugging while using setPromt? If you debug step by step, it prints new setPromt message appending last one and deleting few symbols from last prompt. It looks like that:
'[2012-09-13 11:36:[2012-09-13 11:36:[2012-09-13 11:36:[2012-09-13 11:36:13]'
I could do that myself but that would take time to understand this code :) thanks

22 May 2012 Brian  
19 Feb 2011 Kenneth Eaton

Very nice! The only problem I had when trying to run it on R2010b was this warning message:

Warning: Possible deprecated use of set on a Java callback.
> In setPrompt at 115

Which I suppressed by doing the following:

warning('off','MATLAB:hg:JavaSetHGProperty');

11 Jan 2011 Andy

I have a student edition of ML R2010a on Windows 7. It comes with the default prompt 'EDU>>', which I wanted to change back to the familiar '>>'. setPrompt worked, but it leaves too much space (copied and pasted):

EDU>> setPrompt('>>');
>> see how much space there is?

I would have preferred:

EDU>> setPrompt('>>');
>> only one space before text

Still, great stuff. Thanks, Yair!

01 Feb 2010 Jean-Guilhem Dalissier

Thank you very much Yair, your new version works perfectly. Tested successfully on R2008b and R2007b. Work also perfectly on R14SP3 adding a “try, if ismac … end”.

27 Jan 2010 John D'Errico

I would only add (as one of the people who reported a Mac problem) that I saw the problem in release R2007b, on an old mac with probably an old copy of Java. For the rest of you, rest assured that this appears to be a well written, well documented, professional piece of code.

27 Jan 2010 Yair Altman

*** Mac users ***
Please note that I have received information that setPrompt causes problems on MacOS. It appears to work ok on non-Mac platforms though (inc. Windows)

26 Jan 2010 Yair Altman

oops - temporary problem with the webpage (now fixed)...

I don't know the legal status of removing the EDU from the prompt. Since this is the first time anyone has been able to modify the prompt, I think the question has never before arisen.

26 Jan 2010 Jan Simon

I cannot get the link to the blog on undocumentedmatlab to run (-> 404 error).
Is there a statement from TMW, if removing "EDU" from the prompt conclicts with the license conditions? See: http://www.mathworks.com/support/solutions/en/data/1-16N4J/index.html?solution=1-16N4J
If it is legal, I love it.

26 Jan 2010 Aurelien Queffurust

I thought that it was impossible to modify this "core" feature. tested successfully under R2010a Prerelease. Great job Yair!

25 Jan 2010 Ragaar Ashnod  
Updates
26 Jan 2010

Fixed a few edge cases (some inspired by J. Raymond); added continuously-updated timestamp option

29 Jan 2010

Fixed a few edge-cases (some reported by J.G. Dalissier) with '>> ' terminated prompts; fixed a few problems with continuous timestamps; enabled customizing continuous timestamp prompts; added Mac warning

10 Oct 2014

Fixed for R2014a & R2014b

20 Oct 2014

Updated submission title (no code change)

Contact us