I tried to find but failed.
I think coloring of lines that start with '+' in red
... and coloring of lines that start with '-' in blue
... would be enough.
hello.c::
+#else <<<<< want this line in red
ISR_RESULT ISRs(U32 Interrupt, U32 Vector)
+#endif <<<<< want this line in red
{
-// printf ("Get IRQs \r\n"); <<<<< want this line in blue
- switch (Interrupt) <<<<< want this line in blue
- { <<<<< want this line in blue
- case ISR_MBOX0: <<<<< want this line in blue
You probably should use the code-block directive and use Pygment's diff lexer. Your *.rst file should probably look like this:
.. code-block:: diff
+#else
ISR_RESULT ISRs(U32 Interrupt, U32 Vector)
+#endif
{
-// printf ("Get IRQs \r\n");
- switch (Interrupt)
- {
- case ISR_MBOX0:
Related
I need to produce a large number of Powerpoint files with varying text (program of conference sessions). I try to do this with Perl and Win32::OLE. This works well with the exception of setting the color of the text I post. All I can set is the value for Red in RGB, but not the other colors. I use Powerpoint 2010. Also, I can change the color in Powerpoint via VBA.
Here is the code I use (commented with #- are some options that I tried and that did not work).
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft PowerPoint';
$Win32::OLE::Warn = 2; # Throw Errors, I'll catch them
my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| Win32::OLE->new('PowerPoint.Application', 'Quit');
$PptApp->{Visible} = 1;
my $Presentation = $PptApp->Presentations->Open({FileName=>'<input-filename.ppt>',ReadOnly=>1});
my $Slide = $Presentation->Slides(1);
$Slide->{Name} = "Slide1";
my $TextBox=$Slide->Shapes->AddTextbox({Orientation=>1,
Left=>25,
Top=>25,
Width=>550,
Height=>50,
});
$TextBox->TextFrame->TextRange->{Text} ="Big Ole Test";
$TextBox->TextFrame->TextRange->Font->{Color} = 255;
#- $TextBox->TextFrame->TextRange->Font->{Color} => ({RGB=>(Red=>86, Green=>55, Blue=>201)});
## Black
#- $TextBox->TextFrame->TextRange->Font->Color->RGB=>[255,255,255];
## Black
#- $TextBox->TextFrame->TextRange->Font->Color => [255,255,255];
## Black
#- $TextBox->TextFrame->TextRange->Font->Color->RGB => 'RGB(255,255,255)';
## Black
#- $TextBox->TextFrame->TextRange->Font->{Color}->{RGB}=>[255,255,255];
## Black
$Presentation ->SaveAs('<output-filename.ppt>');
You have to pass the value of the VBA RGB function. (Source) That's an integral value, not an array of integer values, or a string.
The value of RGB function can be calculated easily with some simple bit manipulation. The calculation for Red (r), Green (g) and Blue (b) components is:
(r) | (g << 8) | (b << 16)
Where | is the bitwise OR operator and << is the left shift operator. If you'd prefer to work without using bitwise operations, you could also use this calculation:
r + (g * 256) + (b * 65536)
I am trying to make a maze in Qbasic but when the pointer touches the maze lines then the program is not ending. I want that when the circle (which is the pointer ) touches the ends of the maze then the program should go to an end.The Program is this:-
cls
screen 12
DIM p AS STRING
DIM A1 AS STRING
15 print"What do you want to do?"
print"A:Draw AN IMAGE"," B:PLAY A MAZE GAME";
PRINT
PRINT"TYPE 'A' OR 'B'IN CAPITAL FORM"
GOTO 102
99 print "rules to play the maze game:"
print
print "1 use 'W' to move the ball foward"
print "2 use 'S' to move the ball backward"
print "3 use 'A' to move the ball leftward"
print "4 use 'D' to move the ball rightward"
INPUT A1
CLS
goto 10
102 INPUT P
if p="A"then
cls
goto 20
elseif p="B" then
cls
goto 99
elseif p<>"A" AND p<>"B" then
print "Choose between A and B"
GOTO 70
end if
10 pset(120,120)
draw "r100"
pset (120,140)
draw"r80"
pset (200,140)
draw "d100"
pset (220,120)
draw"d140"
pset (220,260)
draw "l90"
pset (200,240)
draw "l50"
pset (130,260)
draw"u50l120u90r60u40l50u60r300d90l35d260l60d30l80
h20l20h20u30r40u5l70d60f40r250u90h40u45r40u40r50u130h40r225d65l50d60l15
d130l40d50l20d15r45d40r20u45r10u10r10u90r100"
pset(150,240)
draw"u50l120u50r60u80l50u20r260d50l35d260l60d30l40h20l20h10r
40u50l120d98f50r290u115h40u20r40u40r50u160h10r140d20l50d60l15
d130h40d90l20d60r45d45r70u45r10u10r10u90r75"
20 dim k as string
x = 110
y = 105
do
k = ucase$(inkey$)
if k="W"then
y = y - 2
elseif k= "S" then
y = y + 8
elseif k="A"then
x = x - 8
elseif k="D" then
x = x + 5
end if
circle (x,y),7,10
loop until k ="Q"
GOTO 45
70 CLS
GOTO 15
if x=120 and y=120 then goto 45
40 cls
45 END
Pls Help
Thanks in Advance....
Ok, let's take a peak at your game loop presented below and reformated a bit for readability:
do
k = ucase$(inkey$)
if k="W"then
y = y - 2
elseif k= "S" then
y = y + 8
elseif k="A"then
x = x - 8
elseif k="D" then
x = x + 5
end if
circle (x,y),7,10
loop until k ="Q"
Your win case (if x=120 and y=120 then goto 45) doesn't actually occur within the loop but outside it.
With do loops, only the code between the do and loop statement will execute unless the "until" statement returns true. In order words:
do
'This code will execute
loop until k = "Q"
'This code will only execute after k=Q
Put the win case in the do loop and it should work.
If I recall correctly, QBasic allows whitespace in the beginning of a line. I recommend using whitespace to organize your code visually so you can see what's going on. Look at how I formatted your main loop. Everything that the do loop controls is tabbed to the right of the do and loop statement. This way you can easily see what the do loop is doing. Everything in the if statement gets the same treatment for similar reasons.
If you get in the habit of indenting your code, you can start to see the code's logic laid out cleanly.
Edit: It seems you're new to programming. If you enjoy it, I recommend learning Python through codecademy rather than QBasic. QBasic encourages some very bad habits, like goto statements.
I use a little script to trigger insert modes in order to change the line number color:
function! CursorLineNrColorInsert(mode)
" Insert mode: blue
if a:mode == "i"
highlight CursorLineNr ctermfg=4
highlight CursorLineNr guifg=#268bd2
" Replace mode: red
elseif a:mode == "r"
highlight CursorLineNr ctermfg=1
highlight CursorLineNr guifg=#dc322f
else
highlight CursorLineNr ctermfg=0
highlight CursorLineNr guifg=#073642
endif
endfunction
autocmd InsertEnter * call CursorLineNrColorInsert(v:insertmode)
autocmd InsertLeave * highlight CursorLineNr ctermfg=0
autocmd InsertLeave * highlight CursorLineNr guifg=#073642
That works pretty fine and changes my line number instantly when I enter any insert mode and reverts back to the original color in normal mode.
I would like to do the same for the visual mode:
function! CursorLineNrColorVisual(mode)
" Visual mode: orange
if mode()=~#"^[vV\<C-v>]"
highlight CursorLineNr ctermfg=9
highlight CursorLineNr guifg=#cb4b16
else
highlight CursorLineNr ctermfg=0
highlight CursorLineNr guifg=#073642
endif
endfunction
autocmd CursorMoved * call CursorLineNrColorVisual(mode())
Basically that works but not instantly since the function is triggered on CursorMoved. How could I fire CursorLineNrColorVisual() instantly as soon as I would activate any visual mode?
After spending some time in :help I ended with the following setup:
" Colorize line numbers in insert and visual modes
" ------------------------------------------------
function! SetCursorLineNrColorInsert(mode)
" Insert mode: blue
if a:mode == "i"
highlight CursorLineNr ctermfg=4 guifg=#268bd2
" Replace mode: red
elseif a:mode == "r"
highlight CursorLineNr ctermfg=1 guifg=#dc322f
endif
endfunction
function! SetCursorLineNrColorVisual()
set updatetime=0
" Visual mode: orange
highlight CursorLineNr cterm=none ctermfg=9 guifg=#cb4b16
endfunction
function! ResetCursorLineNrColor()
set updatetime=4000
highlight CursorLineNr cterm=none ctermfg=0 guifg=#073642
endfunction
vnoremap <silent> <expr> <SID>SetCursorLineNrColorVisual SetCursorLineNrColorVisual()
nnoremap <silent> <script> v v<SID>SetCursorLineNrColorVisual
nnoremap <silent> <script> V V<SID>SetCursorLineNrColorVisual
nnoremap <silent> <script> <C-v> <C-v><SID>SetCursorLineNrColorVisual
augroup CursorLineNrColorSwap
autocmd!
autocmd InsertEnter * call SetCursorLineNrColorInsert(v:insertmode)
autocmd InsertLeave * call ResetCursorLineNrColor()
autocmd CursorHold * call ResetCursorLineNrColor()
augroup END
In order to restore the color of line numbers after leaving the visual mode I had to do the following steps:
Remap relevant key bindings to call an "enter-visual-function"
While entering visual mode the function sets updatetime=0 for CursorHold events
Call a "leave-visual-function" by autocmd CursorHold
While leaving visual mode the function resets updatetime=4000 for CursorHold events
As romainl has pointed out, there are no events for entering / exiting visual mode. I'd do it like this:
function! CursorLineNrColorVisual()
...
return '' " Return nothing to make the map-expr a no-op.
endfunction
vnoremap <expr> <SID>CursorLineNrColorVisual CursorLineNrColorVisual()
nnoremap <script> v v<SID>CursorLineNrColorVisual
nnoremap <script> V V<SID>CursorLineNrColorVisual
nnoremap <script> <C-v> <C-v><SID>CursorLineNrColorVisual
Alternatively, you could try putting an expression (%{CursorLineNrColorVisual}) into 'statusline'; this gets evaluated pretty often.
[EDIT] Promptlines plugin uses this method :
Since the statusline is re-drawn eachtime a mode is changed, you can have a trigger each time a mode is changed by adding %{AnyName(mode())} in your statusline (it will not be displayed). Then, you can implement an AnyName function that will be able to filter the current mode.
As an example:
let &stl.='%{RedrawStatuslineColors(mode())}'
function! RedrawStatuslineColors(mode)
if a:mode == 'n'
call NormalHighlight()
elseif a:mode == 'i'
call InsertHighlight()
elseif a:mode == 'R'
call ReplaceHighlight()
elseif a:mode == 'v' || a:mode == 'V' || a:mode == '^V'
call VisualHighlight()
endif
endfunction
[EDIT 2] Itchyny suggested to use the others methods on this thread, to avoid performances issues: It's advised to cache the mode and finish the function (ie. RedrawStatuslineColors()) instantly.
I am currently translating some scripts from csh to perl. I have come across one script which has the following switch control
#And now some control
set get_command = h
set finish = 0
while (1)
switch ($get_command)
case "h":
case "H":
set cine_command = ""
cat << EOF
Control synchronised cine by (case insensitive):
A - A view data
B - B view data
a - accelerate
d - decelerate
r - real time heart rate
<num> - rate (frames per second)
i - toggle interpolation
s - step through (may lose a little synchronisation)
c - continue (restart) after stepping
y - reverse direction
h - help (repeat this)
f - finish (quit)
q - quit (finish)
<return> - quit
EOF
breaksw
case "":
case "f":
case "F":
case "q":
case "Q":
set cine_command = '-f'
set finish = 1
breaksw
case "a":
set cine_command = '-a'
breaksw
case "d":
case "D":
set cine_command = '-d'
breaksw
case "r":
case "R":
set cine_command = "-t $time_per_frame"
breaksw
case "i":
case "I":
set cine_command = '-i'
breaksw
case "s":
case "S":
set cine_command = "-s"
breaksw
case "c":
case "C":
set cine_command = "-c"
breaksw
case "y":
case "Y":
set cine_command = "-y"
breaksw
case '[0-9]*':
set cine_command = "-r $get_command"
breaksw
default:
echo "$get_command ignored"
set cine_command = ""
endsw
if ('$cine_command' != '') then
select_tv $FIRST_TV
cine $cine_command
select_tv $SECOND_TV
cine $cine_command
endif
#
# If we're stopping then get out of this loop.
#
if ($finish) break
echo -n "cine > "
set get_command = $<
end
I have Perl 5.8.8 installed on my system and using use Strict;which I know may become deprecated in the next perl release, I have tried the following
#Add some fine control to script
my $get_command = 'h';
my $finish = 0;
my $cine_command;
while(<>)
{
switch ($get_command)
{
case [hH] {$cine_command = "";}
print STDOUT << 'END';
Control synchronised cine by (case insensitive):
A - A view data
B - B view data
a - accelerate
d - decelerate
r - real time heart rate
<num> - rate (frames per second)
i - toggle interpolation
s - step through (may lose a little synchronisation)
c - continue (restart) after stepping
y - reverse direction
h - help (repeat this)
f - finish (quit)
q - quit (finish)
<return> - quit
END
case [fFqQ]
{
$cine_command = '-f';
$finish = 1;
}
case "a"
{
$cine_command = '-a';
}
case [dD]
{
$cine_command = '-d';
}
case [rR]
{
$cine_command = "-t $time_per_frame";
}
case [iI]
{
$cine_command = '-i';
}
case [sS]
{
$cine_command = '-s';
}
case [cC]
{
$cine_command = '-c';
}
case [yY]
{
$cine_command = '-y'
}
case /\d/
{
$cine_command = "-r $get_command";
}
else
{
print "$get_command ignored\n";
$cine_command = "";
}
if ($cine_command ne "")
{
`select_tv $FIRST_TV`;
`cine $cine_command`;
`select_tv $SECOND_TV`;
`cine $cine_command`;
}
exit if( $finish == 1);
print STDOUT "cine > \n";
chomp(my $get_command = <STDIN>);
}
}
When I press return I get the required options printed to the terminals. However, when I type any option into STDIN - e.g a, h or d - I get no response. When I enter retirn - I get the message "h ignored" printed to the terminal as expected.
Any ideas?
To those who say Get a newer version of Perl): Not everyone has control over their systems. If the OP is on Red Hat, it's probably a company machine which means the OP doesn't have control over it. The latest releas of Perl on Redhat is 5.8.8. We might consider it antique and obsolete, but many corporate version of Perl use it.
I have the latest and greatest versions of Perl on my local machines that I control, but I have to write using Perl 5.8.8 syntax, and I have to assume I can't download any CPAN modules.
This is real life, and it can suck. But, you have to live with it...
First off, Perl and Csh are two completely languages and doing a line-by-line translation of any language into another is not a good idea. Perl is a much more powerful language, and it might be nice to use many of the features to improve your csh script.
If you are parsing a command line, look into using the module Getopts::Long which will do a lot of the work for you and is available in Perl 5.8.8. This may do exactly what you're trying to do with the switch statement and take a lot less work and is a lot more flexible.
I would avoid using the switch statement in Perl. It never really worked very well. The new given/when stuff works better, but alas, it's only available since Perl 5.10.
Instead, forget the switch stuff and use an if/elsif structure then case statement:
my $usage =<<USAGE;
Control synchronised cine by (case insensitive):
A - A view data
B - B view data
a - accelerate
d - decelerate
r - real time heart rate
<num> - rate (frames per second)
i - toggle interpolation
s - step through (may lose a little synchronisation)
c - continue (restart) after stepping
y - reverse direction
h - help (repeat this)
f - finish (quit)
q - quit (finish)
<return> - quit
USAGE
$cine_command;
$finish;
while ( my $command = get_command() ) {
if ( $command =~ /^h$/i ) {
print "$usage\n";
exit 0;
}
elsif ( $command =~ /^(fq)$/i ) {
$cine_command = '-f'
$finish = 1
}
elsif ( $command =~ /^a$/i ) {
$cine_command = '-a';
}
elsif ...
It's not as elegant as a switch statement, but it does the job and is easy to understand and maintain. Also take advantage of using regular expression matching. For example $command =~ /^(fq)$/i is checking to see if$commandis equal toF,f,q, orQ` all at the same time.
while(<>){} in perl is not equivalent to while(1)in csh. while(<>) in perl is equivalent to while(defined($_ = <>)) which is a read and a check to see that eof has not been reached. try replacing while(<>) with while(1).
You might look at something like App::Cmd for a larger program with lots of options. Otherwise, a hash of subrefs might work for delegation rather than a switch statement.
I've a string as follows:
#define BEEF_LABLE #"Recommended Internal Temp 145 - Medium Rare 160 - Medium 170 - Well done"
I want to display it in a 4 lines label. "Recommended Internal Temp" in one line, "145 - Medium Rare" in 2nd line, "160 - Medium" in 3rd line and "170 - Well done" in 4th line.
How can I split the text accordingly.
yourLabel.lineBreakMode = UILineBreakModeWordWrap;
yourLabel.numberOfLines = 0;
and add ("\n") in the String accordingly... like this
#define BEEF_LABLE #"Recommended Internal Temp \n 145 - Medium Rare 160 \n- Medium \n 170 - Well done"