Skip to content

Instantly share code, notes, and snippets.

@domsson
Created June 26, 2020 12:02
Show Gist options
  • Save domsson/ac47e52aa07ffbb455f013ce2eb86f2f to your computer and use it in GitHub Desktop.
Save domsson/ac47e52aa07ffbb455f013ce2eb86f2f to your computer and use it in GitHub Desktop.
blocks = "desktop | | dummy mem cpu volume updates datetime"
width = 816
height = 14
foreground = #bbbece
background = #2a2c41
line-width = 2
line-color = #7285b7
block-prefix = " "
font = 6x13
label-font = "-wuncon-siji-medium-r-normal--10-100-75-75-c-80-iso10646-1"
affix-font = "-xos4-terminesspowerline-medium-r-normal--12-120-72-72-c-60-iso10646-1"
[desktop]
command = "bspc query -D -d focused --names"
trigger = "bspc subscribe"
prefix = " "
suffix = " "
underline = true
[dummy]
command = "echo ' '"
background = #bbd984
affix-foreground = #bbd984
affix-background = #2a2c41
[mem]
command = "mem-proc -mus"
live = true
label = "  Mem "
min-width = 5
foreground = #352c38
background = #7ea3fd
label-foreground = #352c38
label-background = #7ea3fd
affix-foreground = #7ea3fd
affix-background = #bbd984
[cpu]
command = "cpu-proc -mus"
live = true
label = "  Cpu "
min-width = 5
foreground = #352c38
background = #c399e7
label-foreground = #352c38
label-background = #c399e7
affix-foreground = #c399e7
affix-background = #7ea3fd
[volume]
command = "volume-pulse -mus -w'muted'"
live = true
label = "  "
min-width = 5
foreground = #352c38
background = #fadb82
label-foreground = #352c38
label-background = #fadb82
affix-foreground = #fadb82
affix-background = #c399e7
[updates]
command = "echo ' 27'"
background = #c399e7
label = "  Updates: "
foreground = #ffffff
background = #f27975
label-foreground = #ffffff
label-background = #f27975
affix-foreground = #f27975
affix-background = #fadb82
[datetime]
command = "datetime -m -f'%a %b %d, %Y %I:%M%p'"
label = "  "
live = true
affix-foreground = #2a2c41
affix-background = #f27975
@domsson
Copy link
Author

domsson commented Jul 8, 2020

Great! I can't wait to see your first results. And as you've witnessed today, you've already "contributed" a new feature to the project - without any programming. :)

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Cool mate :) Glad I could help you out with your project. I will keep you posted once when it is ready. For now it is only going to support spectrwm but I plan to in the future make my code support for other WMs as well.


In regards to the powerline font https://github.com/ryanoasis/powerline-extra-symbols how would I install it if you happen to know?


command = "echo '%{B#FF0000}red foo%{B-}'" In this code, what does %{B-} even mean?

@domsson
Copy link
Author

domsson commented Jul 9, 2020

In the bar section, you can set default foreground and background colors. These will apply to everything on the bar, unless a different color is being specified for a block, label or affix. When you use format strings manually, you can refer to the Lemonbar README for how they work. In this example, %{B#FF0000} sets the background color to red. %{B-} sets it back to the default. If you didn't put the %{B-}, then everything that came after this block would also be red. Consider it as tidying up after yourself. The same goes for %{F-}. In case you know HTML or XML, think of this as the closing tag.

For installing fonts, you'll have to search online for something like "how to install opentype fonts in (name of your distro)".

Also, if your Rust workspace program is on GitHub / GitLab, feel free to link it.

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Ah that makes sense :)

Do you know how would I install powerline fonts, I am sorry to ask you for this I am struggling to find out how to build it that is all :)

@domsson
Copy link
Author

domsson commented Jul 9, 2020

Download the .otf file (that's the font), then install it according to how it works in your distro. Here is the first result I found for Arch, here is the first result I found for Ubuntu. Here is a result for general "Linux". Just use your search-engine-foo. The Internet would know better than me. ;)

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Thanks mate :)

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

I know this is off topic but just out of curiosity, how come you have written all the projects inside candies in C rather than C++?

@domsson
Copy link
Author

domsson commented Jul 9, 2020

I started programming in PHP (self-taught), then used Java for a long time (that's what they taught us in University). After University, I wanted to learn C++ because it seems to be the most prevalent language in game programming. However, I had difficulties learning the language, as it has become very complex over the years. A friend of mine suggested we should try programming in C, as it is very low level and therefore would, in a way, teach us much more about the basics of programming than the higher level languages. So I started a couple hobby projects (one of them being succade!) to give C a try. I came to really love C, plus I realized that C seems to be the most prevalent language in the Linux / Kernel world. So... yeah, I guess I like that C is low level and minimalist. :)

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Ah I see mate :)

What are your thoughts on Rust? You know the code that I pasted (let me give you an updated version):

use std::process::Command;

fn main()
{
    let workspaces = ["Out1", "Out2"];
    // Initialize variables
    let color = Color
    {
        blue:   0x3b47f7,
        green:  0x14a03e,
        yellow: 0xc6e035,
        red:    0xdd382c,
    };

    let mut output = Command::new("sh");
    output.arg("-c").arg(format!("echo '%{{{}#{:x}}}Out1' '%{{{}#{:x}}}Out2'", is_active(), color.red, is_active(), color.green));
    output.status().expect("Error!");
}

fn output_workspaces()
{

}

fn is_active() -> &'static str
{
    return "F";
}

struct Color
{
    blue: u32,
    green: u32,
    yellow: u32,
    red: u32,
}

What are your thoughts on the Rust programming language? Is this a language better than C or the other way around?

@domsson
Copy link
Author

domsson commented Jul 9, 2020

I don't know Rust, so I can't say. But I remember having seen some benchmarks that showed that Rust has very good performance, similar to C/C++. Seeing how it is a compiled and object-oriented language, I guess it is rather a competitor to C++ than C? But at the end of the day, I don't think one is "better" than the other. I currently enjoy C, so I mostly use C. Others enjoy Rust, so they use Rust. As long as the results are somewhat similar, it doesn't matter.

Use whatever tool works and is right for the job. I remember that the author of bspwm said once that if he were to rewrite (or enhance?) bspwm, he would probably do so in Rust.

EDIT: If this benchmark is worth something, then Rust may even be faster than C for some tasks. Wow!

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Ah I see, thanks mate.

I just want to see what is the eqivilant of:

let mut output = Command::new("sh");
output.arg("-c").arg(format!("echo '%{{{}#{:x}}}Out1' '%{{{}#{:x}}}Out2'", is_active(), color.red, is_active(), color.green));
 output.status().expect("Error!");

if it were to be written in C, would it be less complex or more complex? All this code does is it outputs some values onto lemonbar (succade connects this code) (is_active() is a function that I created)?

@domsson
Copy link
Author

domsson commented Jul 9, 2020

Again, I don't know Rust, hence I'm not sure what's happening there. But I assume you're looking at something like printf() or fprintf():

 fprintf(stdout, "%s world!\n", "Hello");

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

echo '%{B#FF0000}red foo%{B-}' If I wanted to output this exact same command but I don't want to write in shell script, I want to write it in C lang instead, what would be the syntax/command? Sorry for asking so much I am curious to know what would be the most simplest language to use for such a task so I am curious to know its syntax.

@domsson
Copy link
Author

domsson commented Jul 9, 2020

Printing a string to stdout should be similarly simple / performant in pretty much every language under the sun. :) So I wouldn't worry about it. It's the stuff you do to fetch information, like the workspaces, or temperatures, or workload, or whatever, where languages might be different in how easy/hard efficient/inefficient it is. Here is what printing your example string might look like in C:

char color[] = "#FF0000";
char output[] = "red foo";
printf("%%{B%s}%s%%{B-}\n", color, output);

Or, if the "red foo" and color never change, then just:

printf("%%{B#FF0000}red foo%%{B-}\n");

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Interesting! However why would you declare color[] as a char, wouldn't it make more sense to declare it as an unsigned 4 byte integer?

@domsson
Copy link
Author

domsson commented Jul 9, 2020

Well, it really depends on the context. But let's say color was an int, then you could probably (I have not tested it) do this:

printf("%%{B#%08X}%s%%{B-}\n", color, output);

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Oh I see mate thanks.

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Have you used wmctrl package before? I am trying to get the output of the workspace's name but that seems to fail so I was just curious you have some experience with it by any chance?

@domsson
Copy link
Author

domsson commented Jul 9, 2020

I didn't even know about it, but it sounds very useful.

@Joe23232
Copy link

Joe23232 commented Jul 9, 2020

Yeah I was recommended to use it, but yeah I can't get the current work space's name (I can get hte ID).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment