How to convert Str to enum? - enums

enum Colors<red green blue>
say red; # OUTPUT: red
my $foo = "red";
my Colors $color = $foo.(...)
What code do I put in the Stub to convert the Str "red" to the Color red?

The enum declarator installs the elements under the Colors package as well as providing the short names, thus red can also be accessed as Colors::red. Therefore, one can use the package lookup syntax to do the job:
my Colors $color = Colors::{$foo};
Optionally providing an error or default:
my Colors $color = Colors::{$foo} // die "No such color $foo";

Related

Change column color in Oracle apex

How can I change the background color of every second column using interactive report.
First of all I recommend using css. If you don't like CSS just go directly to IR section in my answer
CSS
th:nth-child(even),
td:nth-child(even){
background-color: red !important
}
or
th:nth-child(2),
td:nth-child(2) {
background-color: red !important
}
th:nth-child(4),
td:nth-child(4) {
background-color: blue !important
}
or
th#C152380905075548116,
td[headers="C152380905075548116"] {
background-color: red !important;
}
th#C152381026269548117,
td[headers="C152381026269548117"] {
background-color: blue !important;
}
where C152380905075548116 and C152381026269548117 are columns id that should be replaced.
IR
If you really need to use native IR functionalities you should follow 3 steps:
Change report SQL query so the column contains name of the color you want to use as background
eg:
select
...
VALUE1||'<span style="display: none">red</red>' as Artikl
VALUE2||'<span style="display: none">blue</red>' as "Broj gresaka"
..
from
..
Add IR highlights Actions > Format > Highlight
Name = Red background (Artikl)
Sequence = Sequence
Enabled = Yes
Highlight Type = Cell
Background Color = #FF7755
Text Color = null
Column = Artikl
Operator = Contains
Expression = red
and
Name = Blue background (Broj gresaka)
Sequence = Sequence
Enabled = Yes
Highlight Type = Cell
Background Color = #99CCFF
Text Color = null
Column = Artikl
Operator = Contains
Expression = blue
Set columns attribute Security > Escape special characters to No
It is not the perfect solution but it works :-)

Colors are not concatenating correctly in Sass

I am trying to concatenate two colors in Sass:
$helloWorld: pink;
$secondString: red;
p {
color:$helloWorld + $secondString;
}
But the result is:
p {
color: pink; }
Why aren't the colors concatenating to produce pinkred?
This is because Sass treats all colors as their hex value, regardless if they're named like pink. They're all hex values under the hood. Per the Sass Documentation:
Colors
Any CSS color expression returns a SassScript Color value. This includes a large number of named colors which are indistinguishable from unquoted strings.
The emphasis is mine. The documentation states that the color value is returned, which is the hex value. The included link also shows that named colors such as pink are just hex values under the hood. To address the adding issue, refer to the documentation again:
Color Operations
All arithmetic operations are supported for color values, where they work piecewise. This means that the operation is performed on the red, green, and blue components in turn. For example:
p {
color: #010203 + #040506;
}
computes 01 + 04 = 05, 02 + 05 = 07, and 03 + 06 = 09, and is compiled to:
p {
color: #050709; }
The same principle applies here. When you use addition on colors, you aren't concatenating them like strings, so pink + red is not pinkred. Instead, the hex values are added piecewise. Here's an example:
$blue: blue;
$red: red;
p {
color: $blue + $red
}
This yields:
p {
color: magenta
}
From the example above, you can see that this does not perform string concatenation, but it's adding blue (#0000FF) and red (#FF0000) to create magenta (#FF00FF). In your case, pink (#FFC0CB) and red (#FF0000) are added piecewise to produce #FFC0CB, which is just pink. That's why you get pink instead of pinkred.
If you want to concatenate them like strings, do not use+. Instead, you can try string interpolation so the colors are treated as strings, not colors:
p {
color: $helloWorld#{$secondString}
}
That will yield:
p {
color: pinkred
}
You can also use a more verbose method so that it's forced to act like a string (unquote just gets rid of the quotes):
p {
color: unquote($helloWorld+ "" + $secondString);
}
Try it at SassMeister. Note that pinkred isn't a named colors in Sass.

SASS for each interpolation error when export css in compressed mode

I have a map declared like below
Map Definition
$color-array:(
black:#4e4e4e,
blue:#0099cc,
dark-blue:#14394e,
green:#2ebc78,
white:#ffffff,
orange:#ed6a0e
);
and calling the same in for each loop to generate class for text color and background color like below
#each $color-name, $color-value in $color-array{
.#{$color-name}{
color: $color-value !important;
}
.bg-#{$color-name}{
background: $color-value !important;
}
}
I am using gruntjs for for compilation, when i set output style to compressed it gives below error
You probably don't mean to use the color value #000' in interpolation
here. It may end up represented as #000000, which will likely produce
invalid CSS. Always quote color names when using them as strings (for
example, "#000"). If you really want to use the color value here, use
"" + $color-name'.
Error: Invalid CSS after ".": expected class name, was "#000"
on line 25 of SCSS/_base.scss
from line 5 of scss/style.scss
But when i set output style to expanded it runs fine.
In your colors array, change all the key double-quoted string keys and things should work.
$color-array:(
"black":#4e4e4e,
"blue":#0099cc,
"dark-blue":#14394e,
"green":#2ebc78,
"white":#ffffff,
"orange":#ed6a0e
);
An alternative of changing the SCSS code would be to make sure the variable is a string like the error message mentioned
#each $color-name, $color-value in $color-array{
.#{"" + $color-name}{
color: $color-value !important;
}
.bg-#{"" + $color-name}{
background: $color-value !important;
}
}

Add color to JQuery Terminal

I am trying to add color the the jquery terminal like a bash terminal in linux.
I have tried the same arrangement of color codes
\033]01;31\] # pink
\033]00m\] # white
\033]01;36\] # bold green
\033]02;36\] # green
\033]01;34\] # blue
\033]01;33\] # bold yellow
and there is no color options.
A function I use is like so for javascript
function teal(message) {
return "[[gb;teal;black]" + message + "]";
}
Just wrap the string like the above.
The first colour is the text color and the second color is the background.
The gb at the start are for string formatting;
g = glow & b = bold
You can also under line and make them italic aswell
i = italic & u = underline
In the string, make sure not to have any [ or ] as this will affect the formatting. Use the escape character \[ or \] and it should work.
It will also work in C# as I have done this myself and should see no reason it wouldn't work with the likes of Java strings either.

Naming Color Variables in SASS

When creating a color scheme in SASS what's the conventional variable names for defining colors?
I know using color names are bad. Such as:
$blue
$red
$green
But I've not seen an alternative. I'm struggling for variable names for colors on the site that convey meaning.
Any ideas?
I found another idea in "SASS & Color Variables" article. The solution suggested by Sacha Greif is to use some variables to store descriptive color names, and some other to assign those colors to their functions:
// first we set descriptive variables:
$darkgrey: #333333;
$blue: #001eff;
// then we set functional variables:
$text_color: $darkgrey;
$link_color: $lightblue;
$border_color: $lightblue;
.myClass {
color: $text_color;
border-color: $border_color;
}
a {
color: $link_color;
}
I'm just beginning with SASS and don't know which approach is more practical, but I like the way it separates colors from their function.
In my personal experience the most useful way to name colors is to do it in regards of the color's function, such as
$background
$contrast
$text
$aside
$link
And so on. Of course which colors and name may depend on the design.
Then you may have different and exchangeable color schemes defined on different styles, such as:
_dark_scheme.scss
_light_scheme.scss
_pastels.scss
The idea here, is that you can use the same color variables in your main stylesheets, and do not depend on specific colors.
I like the idea of combining generic to specific naming (good for code completion) and description/functional naming. So you have something like this:
// Descriptive naming
$color-gray-light: #f3f3f3;
$color-gray-dark: #999999;
$color-red: red;
// Functional naming
$link-color: $color-red;
$link-border-color: $color-gray-light;
You can even create a mixin for greys (in the example RGBA is used for transparency, for example black on a red background would be more visible if it is 80% transparent black rather than dark grey).
#mixin grey($intensity: 0.5, $type: color) {
#{$type}: rgba(black, $intensity);
}
.i-am-50-percent-gray {
#include grey(0.5, color);
}
Give the result
.i-am-50-percent-gray {
color: rgba(0, 0, 0, 0.5);
}

Resources