|
10 | 10 | %
|
11 | 11 | % CPRINTF then displays the text in the Command Window using the
|
12 | 12 | % specified STYLE argument. The accepted styles are those used for
|
13 |
| -% Matlab's syntax highlighting (see: File / Preferences / Colors / |
| 13 | +% MATLAB's syntax highlighting (see: File / Preferences / Colors / |
14 | 14 | % M-file Syntax Highlighting Colors), and also user-defined colors.
|
15 | 15 | %
|
16 | 16 | % The possible pre-defined STYLE names are:
|
|
33 | 33 | % STYLE beginning with '*' will be bold (R2011b+ only). For example:
|
34 | 34 | % '*Blue' is bold blue;
|
35 | 35 | % '*Comments' is bold green etc.
|
36 |
| -% Note: Matlab does not currently support both bold and underline, |
| 36 | +% Note: MATLAB does not currently support both bold and underline, |
37 | 37 | % only one of them can be used in a single cprintf command. But of
|
38 | 38 | % course bold and underline can be mixed by using separate commands.
|
39 | 39 | %
|
40 |
| -% STYLE also accepts a regular Matlab RGB vector, that can be underlined |
| 40 | +% STYLE also accepts a regular MATLAB RGB vector, that can be underlined |
41 | 41 | % and bolded: -[0,1,1] means underlined cyan, '*[1,0,0]' is bold red.
|
42 | 42 | %
|
43 | 43 | % STYLE is case-insensitive and accepts unique partial strings just
|
|
63 | 63 | % Please send to Yair Altman (altmany at gmail dot com)
|
64 | 64 | %
|
65 | 65 | % Warning:
|
66 |
| -% This code heavily relies on undocumented and unsupported Matlab |
67 |
| -% functionality. It works on Matlab 7+, but use at your own risk! |
| 66 | +% This code heavily relies on undocumented and unsupported MATLAB |
| 67 | +% functionality. It works on MATLAB 7+, but use at your own risk! |
68 | 68 | %
|
69 | 69 | % A technical description of the implementation can be found at:
|
70 | 70 | % <a href="http://undocumentedmatlab.com/blog/cprintf/">http://UndocumentedMatlab.com/blog/cprintf/</a>
|
|
75 | 75 | %
|
76 | 76 | % 2. In R2011a and earlier, consecutive differently-colored multi-line
|
77 | 77 | % CPRINTFs sometimes display incorrectly on the bottom line.
|
78 |
| -% As far as I could tell this is due to a Matlab bug. Examples: |
| 78 | +% As far as I could tell this is due to a MATLAB bug. Examples: |
79 | 79 | % >> cprintf('-str','under\nline'); cprintf('err','red\n'); % hidden 'red', unhidden '_'
|
80 | 80 | % >> cprintf('str','regu\nlar'); cprintf('err','red\n'); % underline red (not purple) 'lar'
|
81 | 81 | %
|
|
88 | 88 | % the last character of an underlined segment is not underlined for
|
89 | 89 | % some unknown reason (add an extra space character to make it look better)
|
90 | 90 | %
|
91 |
| -% 5. In old Matlab versions (e.g., Matlab 7.1 R14), multi-line styles |
| 91 | +% 5. In old MATLAB versions (e.g., MATLAB 7.1 R14), multi-line styles |
92 | 92 | % only affect the first line. Single-line styles work as expected.
|
93 | 93 | % R14 also appends a single space after underlined segments.
|
94 | 94 | %
|
|
102 | 102 | % 2011-03-04: Performance improvement
|
103 | 103 | % 2010-06-27: Fix for R2010a/b; fixed edge case reported by Sharron; CPRINTF with no args runs the demo
|
104 | 104 | % 2009-09-28: Fixed edge-case problem reported by Swagat K
|
105 |
| -% 2009-05-28: corrected nargout behavior sugegsted by Andreas Gäb |
| 105 | +% 2009-05-28: corrected nargout behavior sugegsted by Andreas Gäb |
106 | 106 | % 2009-05-13: First version posted on <a href="http://www.mathworks.com/matlabcentral/fileexchange/authors/27420">MathWorks File Exchange</a>
|
107 | 107 | %
|
108 | 108 | % See also:
|
|
142 | 142 |
|
143 | 143 | % In compiled mode
|
144 | 144 | try useDesktop = usejava('desktop'); catch, useDesktop = false; end
|
145 |
| - if isdeployed | ~useDesktop %#ok<OR2> - for Matlab 6 compatibility |
| 145 | + if isdeployed | ~useDesktop %#ok<OR2> - for MATLAB 6 compatibility |
146 | 146 | % do not display any formatting - use simple fprintf()
|
147 | 147 | % See: http://undocumentedmatlab.com/blog/bold-color-text-in-the-command-window/#comment-103035
|
148 | 148 | % Also see: https://mail.google.com/mail/u/0/?ui=2&shva=1#all/1390a26e7ef4aa4d
|
|
157 | 157 | if underlineFlag
|
158 | 158 | format = ['<a href="">' format '</a>'];
|
159 | 159 |
|
160 |
| - % Matlab 7.1 R14 (possibly a few newer versions as well?) |
| 160 | + % MATLAB 7.1 R14 (possibly a few newer versions as well?) |
161 | 161 | % have a bug in rendering consecutive hyperlinks
|
162 | 162 | % This is fixed by appending a single non-linked space
|
163 | 163 | if majorVersion < 7 || (majorVersion==7 && minorVersion <= 1)
|
|
213 | 213 | if majorVersion<7 || (majorVersion==7 && minorVersion<13)
|
214 | 214 | if bolFlag && ~underlineFlag
|
215 | 215 | % Set the leading hyperlink space character ('_') to the bg color, effectively hiding it
|
216 |
| - % Note: old Matlab versions have a bug in hyperlinks that need to be accounted for... |
| 216 | + % Note: old MATLAB versions have a bug in hyperlinks that need to be accounted for... |
217 | 217 | %disp(' '); dumpElement(docElement)
|
218 | 218 | setElementStyle(docElement,'CW_BG_Color',1+underlineFlag,majorVersion,minorVersion); %+getUrlsFix(docElement));
|
219 | 219 | %disp(' '); dumpElement(docElement)
|
|
277 | 277 | style = style(~boldIdx);
|
278 | 278 | end
|
279 | 279 | if underlineFlag && boldFlag
|
280 |
| - warning('YMA:cprintf:BoldUnderline','Matlab does not support both bold & underline') |
| 280 | + warning('YMA:cprintf:BoldUnderline','MATLAB does not support both bold & underline') |
281 | 281 | end
|
282 | 282 |
|
283 | 283 | % Check if the remaining style sting is a numeric vector
|
|
288 | 288 | end
|
289 | 289 | end
|
290 | 290 |
|
291 |
| - % Style = valid matlab RGB vector |
| 291 | + % Style = valid MATLAB RGB vector |
292 | 292 | if isnumeric(style) && length(style)==3 && all(style<=1) && all(abs(style)>=0)
|
293 | 293 | if any(style<0)
|
294 | 294 | underlineFlag = 1;
|
|
336 | 336 | end
|
337 | 337 | end
|
338 | 338 |
|
339 |
| -% Convert a Matlab RGB vector into a known style name (e.g., '[255,37,0]') |
| 339 | +% Convert a MATLAB RGB vector into a known style name (e.g., '[255,37,0]') |
340 | 340 | function styleName = getColorStyle(rgb)
|
341 | 341 | intColor = int32(rgb*255);
|
342 | 342 | javaColor = java.awt.Color(intColor(1), intColor(2), intColor(3));
|
343 | 343 | styleName = sprintf('[%d,%d,%d]',intColor);
|
344 | 344 | com.mathworks.services.Prefs.setColorPref(styleName,javaColor);
|
345 | 345 |
|
346 |
| -% Fix a bug in some Matlab versions, where the number of URL segments |
| 346 | +% Fix a bug in some MATLAB versions, where the number of URL segments |
347 | 347 | % is larger than the number of style segments in a doc element
|
348 | 348 | function delta = getUrlsFix(docElement) %#ok currently unused
|
349 | 349 | tokens = docElement.getAttribute('SyntaxTokens');
|
|
0 commit comments