question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to output rgb(n,n,n) ?

See original GitHub issue

I am struggling to get this to work as expected:

$color-black = rgb(0,0,0) // #000000
$color-white = rgb(255,255,255) // #FFFFFF
$color-red = rgb(201,37,49); // #c92531


$colors = primary-red $color-red, primary-white $color-white, primary-black $color-black;

generatestuff($c)
  for $pair in $c
   .color-{$pair[0]}
      color: rgb($pair[1])
generatestuff($colors)

The output is:

.color-primary-red {
  color: #c92531;
}
.color-primary-white {
  color: #fff;
}
.color-primary-black {
  color: #000;
}

What I expect/wants/desire…

.color-primary-red {
  color: rgb(201,37,49);
}
.color-primary-white {
  color: rgb(255,255,255);
}
.color-primary-black {
  color: rgb(0,0,0);
}

How can I achieve this if this is not intended behaviour?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Panyacommented, Aug 10, 2016

This is intended behaviour. The only way you can achieve this is by saving r, g, b values as lists and use unquote('rgb(' + join(',', $color) + ')'):

$color = 0, 0, 0

body
  color: unquote('rgb(' + join(',', $color) + ')')
0reactions
phun-kycommented, Jun 3, 2021

@Panya @srsgores Sorry for bringing up an old issue, encountered the use case again today.

I was trying to interpolate color variables:

From:

a
  border-bottom-color rgba(37, 116, 168, 0.9)
  background-image linear-gradient(180deg,rgba(37, 116, 168, .4) 0,transparent 1px,transparent)

To:


$color-a = rgb(37, 116, 168)
$size-b = 1px
a
  border-bottom-color rgba($color-a, 0.9)
  background-image "linear-gradient(180deg,rgba(%s, .4) 0,transparent %s,transparent)" % ($color-a $size-b)

And since the border-bottom-color color works, why wouldn’t it work in string interpolation. But it struck me, the interpolation is sent straight trough the parser, right?

Because this is the desired outcome:

a{
  border-bottom-color: rgba(37, 116, 168, 0.9);
  background-image: linear-gradient(180deg,rgba(37, 116, 168, .4) 0,transparent 1px,transparent);
}

But we get this:

a{
  border-bottom-color: rgba(37, 116, 168, 0.9);
  background-image: linear-gradient(180deg,rgba(#2574a8, .4) 0,transparent 1px,transparent);
}

One way is to do this:


$color-a = rgb(37, 116, 168)
$size-b = 1px
a
  border-bottom-color rgba($color-a, 0.9)
  background-image "linear-gradient(180deg,%s 0,transparent %s,transparent)" % (rgba($color-a, .4) $size-b)

But it’s not very readable.

And this does not either work:


$color-a = rgb(37, 116, 168)
a
  color rgba($color-a, 0.9) // results in rgba(37, 116, 168, 0.9)
  color rgba($color-a, 1) // results in #2574a8

Which makes things a bit inconsistent when searching and debugging the code.

Dunno if this is a rant or a real issue, but needed to jot down my thoughts about this…

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the value for colorControl color state?
I'm developing my own device handler and I have an RGB light. So, I get with setColorcommand a {hue:NN.NNN,saturation:NN.
Read more >
MediaWall V 4K/UHD Display Processor User's Guide
This guide is for use with the RGB Spectrum MediaWall V 4K/UHD Display Processor. ... where <nnn.nnn.nnn.nnn> is the MediaWall V IP address....
Read more >
ToDo list · Issue #1 · jarun/nnn - GitHub
press r to refresh the list; press del/R to delete (recursive) with confirmation; add option to start in disk usage analyzer mode ...
Read more >
https://unpkg.com/material-ui@1.0.0-beta.43/styles...
... the output range * @param {number} max The upper boundary of the output range ... @param {string} color - CSS color, i.e....
Read more >
How to change the output color of echo in Linux - Stack Overflow
Tip: for memorize it you can first add \[\] and then put your ANSI code between them: \[start-ANSI-code\]; \[end- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found