Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
too many and too less terminal-emulators
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Thu Jan 24, 2013 5:10 am    Post subject: Reply with quote

Rather than a bash script, this is what I use to produce my "status bar", which is updated every second and looks like this:
Code:
Load: 0.46   RAM: 32 MiB   Swap: 0 MiB    Thu Jan 24   00:00:18


This is the code. I wrote it for my use only. It's not very portable, flexible, or idiot-proof; it doesn't include error checking and the other things good code should have before it's distributed. But it's far more efficient than a shell script (the normal way of doing it). It also never closes the display, but that doesn't matter because I always close X when close dwm. To be "correct", I suppose the pointer to the XDisplay should be a global variable, so it could be closed by signal trapping, but I hate global variables and that scenario will probably never occur, and it's a one-time 4-byte leak if it did occur, so fuck it. :lol:
Code:
#include <stdio.h>        // snprintf()
#include <stdlib.h>       // getloadavg()
#include <unistd.h>       // sleep()
#include <time.h>
#include <X11/Xlib.h>
#include <string.h>


static void append_load(char *st);

static void append_ram(char *st);

static void append_time(char *st);



int main() {

  const size_t outsize = 70;
  char status[outsize];
  Display *dpy = XOpenDisplay(":0");

  while(1) {

    memset(status, 0, outsize);

    append_load(status);
    append_ram(status + strlen(status));
    append_time(status + strlen(status));

    XStoreName(dpy, DefaultRootWindow(dpy), status);
    XSync(dpy, False);

    sleep(1);

  }

  XCloseDisplay(dpy);

  return 0;

}



// Reads system load (1 min avg) and appends to passed status string.
static void append_load(char *st) {

  static const size_t max = 13;
  static double loads[1];

  getloadavg(loads, 1);

  snprintf(st, max, "  Load: %.2f ", loads[0]);

}


// Creates formatted local time and appends to status string.
static void append_time(char *st) {

  static const size_t max = 24;
  static time_t now;
  static struct tm ltm;

  time(&now);
  localtime_r(&now, &ltm);
  strftime(st, max, "  %a %b %-e  %T ", &ltm);

}



// Calculates RAM in use and appends to passed status string.
static void append_ram(char *st) {

  static const size_t max = 32;
  static FILE *fp;
  static char label[11];
  static int value;
  static int found;
  static int memstats[6] = {0};
  static int ram_used;
  static int swap_used;

  memset(label, 0, sizeof(label));
  found = 0;

  fp = fopen("/proc/meminfo", "r");

  // search by label because /proc/meminfo entries vary
  while ( fscanf(fp, "%10s %d %*s", label, &value) != EOF ) {

    if ( strcmp(label, "MemTotal:") == 0 ) {
      memstats[0] = value;
      found ++;
    } else if ( strcmp(label, "MemFree:") == 0 ) {
      memstats[1] = value;
      found ++;
    } else if ( strcmp(label, "Buffers:") == 0 ) {
      memstats[2] = value;
      found++;
    } else if ( strcmp(label, "Cached:") == 0 ) {
      memstats[3] = value;
      found++;
    } else if ( strcmp(label, "SwapTotal:") == 0 ) {
      memstats[4] = value;
      found++;
    } else if ( strcmp(label, "SwapFree:") == 0 ) {
      memstats[5] = value;
      found++;
    }

    if ( found >=6 ) break;

  }

  fclose(fp);

  ram_used = memstats[0] - ( memstats[1] + memstats[2] + memstats[3] );
  swap_used = memstats[4] - memstats[5];

  snprintf(st, max, "  RAM: %d MiB  Swap: %d MiB ", ram_used/1024, swap_used/1024);

}

_________________
juniper wrote:
I use ubuntu, which is why I am posting here.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Thu Jan 24, 2013 11:49 am    Post subject: Reply with quote

My post wasn't meant to be a joke, I'm serious! Especially because I'm digging into C anyway at the moment and I want to code many different things from gtk-graphic widget stuff for my desktop (I always wanted a binary clock but all I've found in the portage tree or elsewhere aren't my taste, so its a good programming exercise payed with the exact style I want) to system programming. I mean one important thing of Linux is the availability of the source and if one don't modify/ play with it, it would be a waste (at least for people that work with computers or just like to play with them) and without C there isn't much to do, therefore I have another playground with practical consequences and move towards my own desktop..

Quote:
If I want to be notified of something, I'll code that in to my own status bar (which is fed by an efficient little C application I wrote).

++

Quote:
But it's far more efficient than a shell script (the normal way of doing it

do you think it would be better to code as much as possible in C and avoid python/bash-scripts?

thanks to you both for the code examples, I will try them today! Do you know "stumpwm" ? I didn't try it but could be also cool...
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Prenj
n00b
n00b


Joined: 20 Nov 2011
Posts: 13

PostPosted: Thu Jan 24, 2013 2:13 pm    Post subject: Reply with quote

LoTeK wrote:
do you think it would be better to code as much as possible in C and avoid python/bash-scripts?


Python is pretty cool. You can prototype in it and mix with C as you please.
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Thu Jan 24, 2013 7:55 pm    Post subject: Reply with quote

I've heard of stumpwm but haven't tried it myself.

Shell script (e.g., BASH) is fine for most purposes and if there's a utility or tool already existing which that does exactly what you want, just calling it from a script is smart; why reinvent the wheel?

Python is much faster than shell and fast enough for almost any end-user purposes. There are entire window managers written in Python and languages like it. Python is much higher-level than C/C++, so you can get a lot more done in it with a few lines of code. It's got all kinds of powerful built-in capabilities, so you don't have to make use of external libraries as much. In a GNU/Linux distribution like Gentoo, where python is a core part of the system (Portage is written mostly in Python, for example), it's already on your system and may well need to loaded at various times, so there's some overlap of needs there. (In other words, in my opinion, it's better to use Python than something else you're not already using, like Ruby or some other interpreted language).

Like Prenj suggested, a good approach is to write what you want in shell (BASH unless you've changed yours) or an interpreted language (e.g., Python), and then, if there is significant benefit to doing so, you can write it in C, C++ or another compiled language (although, as you've noted, on Linux it makes sense to do things in C/C++ that are going to interact with the system, use a C-based widget set, and so on.).

To be honest, C is overkill for most things a user would want to do, but extending your desktop environment can be an exception to that, if it's a function that's constantly running or very frequently used.

Also, be advised that I'm not a computer scientist, programmer, or sysadmin like many of the guys in here: I'm just a hobbyist; so I may be telling you a lot of stupid crap and you can almost certainly get better advice from almost anybody. :)
_________________
juniper wrote:
I use ubuntu, which is why I am posting here.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Fri Jan 25, 2013 2:59 pm    Post subject: Reply with quote

Quote:
Shell script (e.g., BASH) is fine for most purposes and if there's a utility or tool already existing which that does exactly what you want, just calling it from a script is smart; why reinvent the wheel?

ok.. but mostly programs that you didn't wrote by yourself don't do exactly what you want. But maybe it's better to code new things then just rewrite python-scripts in C.

Quote:
There are entire window managers written in Python and languages like it. Python is much higher-level than C/C++, so you can get a lot more done in it with a few lines of code. It's got all kinds of powerful built-in capabilities, so you don't have to make use of external libraries as much. In a GNU/Linux distribution like Gentoo, where python is a core part of the system (Portage is written mostly in Python, for example), it's already on your system and may well need to loaded at various times, so there's some overlap of needs there. (In other words, in my opinion, it's better to use Python than something else you're not already using, like Ruby or some other interpreted language).

what is the reason that portage was written in python and that gentoo is so focused on python? I've heard that there is paludis which is written in C/C++..

Quote:
Like Prenj suggested, a good approach is to write what you want in shell (BASH unless you've changed yours) or an interpreted language (e.g., Python), and then, if there is significant benefit to doing so, you can write it in C, C++ or another compiled language (although, as you've noted, on Linux it makes sense to do things in C/C++ that are going to interact with the system, use a C-based widget set, and so on.).

To be honest, C is overkill for most things a user would want to do, but extending your desktop environment can be an exception to that, if it's a function that's constantly running or very frequently used.


so the reason for using python is because it's nearly as fast as C and it's more comfortable to code in a higher-level language? Although I see the advantages I don't like it when you go to far away from the hardware, because the source is then more and more different from the actual program. I know one should know as many languages as possible but I hate it when I'm for example very familiar with C-syntax and then I write an octave-code, and although the syntax is similar to C, it's sometimes exhausting to recall all the small differences and it's a bit more error-prone.

Quote:
Also, be advised that I'm not a computer scientist, programmer, or sysadmin like many of the guys in here: I'm just a hobbyist; so I may be telling you a lot of stupid crap and you can almost certainly get better advice from almost anybody. :)


ok, thats the reason why you can afford it to read so much about politics :P no seriously, I think if you tell me bullshit then someone of those pros would step in and if not I will recognize it someday and to make mistakes is good for the learning curve. Moreover hobbyist are sometimes better then pros :)
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"


Last edited by LoTeK on Sun Feb 03, 2013 1:54 am; edited 1 time in total
Back to top
View user's profile Send private message
Prenj
n00b
n00b


Joined: 20 Nov 2011
Posts: 13

PostPosted: Fri Jan 25, 2013 4:20 pm    Post subject: Reply with quote

I wasn't suggesting to re-write stuff in C.

I was suggesting writing stuff in Python, because it's fast to develop in, portable, and has amazing pool of toolkits and libraries for almost everything.

It is fast enough for lots of uses, but if/when you come to the point that something isn't fast enough in python, you can write that slow piece of code in C, and execute it within the existing python code.

That way you don't have to re-write everything, nor do you have to use C all the way, which IS time-consuming and it takes away the focus from developing what you want, to having to fiddle with all the crufty bits that you HAVE to do, in order to make it work.

Also, it teaches you the most important lesson, and that is just because something is written in C, it doesn't mean it has to be faster then something written in Java or Python. It may not sound true, if you only think about simple programs, where you would basically write the same stuff in Python or C.

But it has to do with writing with wrong paradigm in mind, like do you use asynchronious I/O or do you poll and waste CPU time on that. Or do you read/write to a disk, or do you keep stuff in memory, and occasionally sync when you run out of space.

So my advice would be, if you're just gonna fiddle, and write some for-loops, open files and such, write it in both languages, if you want to learn. But if you are gonna make something more complex, read up on different ways of designing things (read about Design Patterns), write it in Python first, cos you can follow a pattern easier from higher-level language, and then when you feel bold enough, do it in C, or parts of it.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Fri Jan 25, 2013 7:01 pm    Post subject: Reply with quote

Quote:
I wasn't suggesting to re-write stuff in C.

I know, I've said this because I thought about rewriting stuff in C, but it's maybe a waste of time...

Quote:
I was suggesting writing stuff in Python, because it's fast to develop in, portable, and has amazing pool of toolkits and libraries for almost everything.

ok, I don't know python yet (I think its similar to octave ?!), but so is C (maybe not as fast to develop compared to python, I don't know)

Quote:
That way you don't have to re-write everything, nor do you have to use C all the way, which IS time-consuming and it takes away the focus from developing what you want, to having to fiddle with all the crufty bits that you HAVE to do, in order to make it work.

This was a main reason for betrand meyer to develop Eiffel (simple syntax that allow one to focus on the problem and not the language). I see the advantages of this approach, but maybe there are contexts that require "ugly" low-level handling. The problem I have with the "focus on the problem and not the language or hardware" approach is that in computer science or engineering you should WANT to bother with machines and bits etc otherwise you should become a mathematician then you don't have to bother with such things at all, or do you disagree?

Quote:
Also, it teaches you the most important lesson, and that is just because something is written in C, it doesn't mean it has to be faster then something written in Java or Python. It may not sound true, if you only think about simple programs, where you would basically write the same stuff in Python or C.

yes I've heard of that (in some tests C/C++ programs were even the slowest, but I don't remember in what context)

Quote:
So my advice would be, if you're just gonna fiddle, and write some for-loops, open files and such, write it in both languages, if you want to learn. But if you are gonna make something more complex, read up on different ways of designing things (read about Design Patterns), write it in Python first, cos you can follow a pattern easier from higher-level language, and then when you feel bold enough, do it in C, or parts of it.

ok sounds reasonable :)
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Fri Jan 25, 2013 8:33 pm    Post subject: Reply with quote

Where are you from, LoTeK?
_________________
juniper wrote:
I use ubuntu, which is why I am posting here.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Fri Jan 25, 2013 9:38 pm    Post subject: Reply with quote

haha why? because my english is not very shakespeare style? :)
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Sat Jan 26, 2013 12:51 am    Post subject: Reply with quote

No, just curious. You're English is very good; almost always perfectly correct. Better than several supposedly English-speaking users here. The sentence structure and usage is slightly unusual occasionally. My instinct tells me you're European, probably Eastern European.
_________________
juniper wrote:
I use ubuntu, which is why I am posting here.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Sat Jan 26, 2013 4:54 pm    Post subject: Reply with quote

Ok, thanks very much :)
pretty close.. from switzerland..
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Fran
Guru
Guru


Joined: 29 Feb 2004
Posts: 521
Location: Coruña (Spain)

PostPosted: Sat Jan 26, 2013 6:30 pm    Post subject: Reply with quote

BoneKracker wrote:
You're English is very good

Better than you'res :P
Back to top
View user's profile Send private message
tylerwylie
Guru
Guru


Joined: 19 Sep 2004
Posts: 456
Location: /US/Illinois

PostPosted: Sat Jan 26, 2013 7:24 pm    Post subject: Reply with quote

C++ sucks big floppy donkey dick, use python for everything and C++ for nothing.


*looks around for dmitchell*
_________________
Bastiat wrote:
“The state is that great fiction by which everyone tries to live at the expense of everyone else.”
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Sat Jan 26, 2013 7:33 pm    Post subject: Reply with quote

why? do you mean from a theoretical position? In the sense that it's C with classes, so not really a "clean O-O" language like eiffel but also way more complicated than C?

Although I'm no expert I think C++ is way better than java or even C# (we need a vomit icon :) ) and because python is a scripting language you can't do any low-level stuff...
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
smartass
Apprentice
Apprentice


Joined: 04 Jul 2011
Posts: 189
Location: right behind you ... (you did turn around, didn't you?)

PostPosted: Sat Jan 26, 2013 8:14 pm    Post subject: Reply with quote

LoTeK wrote:
... and because python is a scripting language you can't do any low-level stuff...
False.
Making C/C++ extension modules for Python or calling C functions is actually quite easy with Python.
And the Python standard library provides modules for almost any common system call, so you can conveniently work with pts, sockets, threads and other stuff in Python, with the nice bonus of having e.g. sockets as objects, so you don't have to pass a socket pointer to each call. Of course, these modules are implemented in C, so it's almost as fast.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Sat Jan 26, 2013 8:28 pm    Post subject: Reply with quote

Ok, I get it, I have to learn python :)
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Prenj
n00b
n00b


Joined: 20 Nov 2011
Posts: 13

PostPosted: Sat Jan 26, 2013 8:48 pm    Post subject: Reply with quote

smartass wrote:
LoTeK wrote:
... and because python is a scripting language you can't do any low-level stuff...
False.
Making C/C++ extension modules for Python or calling C functions is actually quite easy with Python.
And the Python standard library provides modules for almost any common system call, so you can conveniently work with pts, sockets, threads and other stuff in Python, with the nice bonus of having e.g. sockets as objects, so you don't have to pass a socket pointer to each call. Of course, these modules are implemented in C, so it's almost as fast.


++

And with 3rd party libraries, Python is just crazy, take a look at twisted: http://twistedmatrix.com/trac/

writing a server for whatever in python+twisted compared to doing it in C with epoll() and doing all the cruft, you can really see the generational difference between languages.
Back to top
View user's profile Send private message
tylerwylie
Guru
Guru


Joined: 19 Sep 2004
Posts: 456
Location: /US/Illinois

PostPosted: Sat Jan 26, 2013 8:51 pm    Post subject: Reply with quote

I'm just laying some bait for dmitchell you guys, we already know how bad C++ is but we have to make sure everyone knows.
_________________
Bastiat wrote:
“The state is that great fiction by which everyone tries to live at the expense of everyone else.”
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Sun Jan 27, 2013 2:08 am    Post subject: Reply with quote

Fran wrote:
BoneKracker wrote:
You're English is very good

Better than you'res :P

Ecksalent! Nice ketch. :lol:
_________________
juniper wrote:
I use ubuntu, which is why I am posting here.
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Mon Jan 28, 2013 1:10 pm    Post subject: Reply with quote

I've tried dwm now and I like it, but I don't know how to fix this error:
Code:
dwm: missing font set ISO8859-1

do you had the same problem? because your config.h doesn't include anything else?! I've tried to include some fonts headers from /usr/include to dwm.c but it hasn't changed anything...
in /etc/locale.gen I've uncommented only en_US ISO-8859-1 and en_US.UTF8 UTF 8.

btw, I've started to use anonymous-pro, very nice font for coding, one can see a clear difference between ":" , ";" and the different brackets..
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Mon Jan 28, 2013 1:22 pm    Post subject: Reply with quote

LoTeK wrote:
I've tried dwm now and I like it, but I don't know how to fix this error:
Code:
dwm: missing font set ISO8859-1

do you had the same problem? because your config.h doesn't include anything else?! I've tried to include some fonts headers from /usr/include to dwm.c but it hasn't changed anything...
in /etc/locale.gen I've uncommented only en_US ISO-8859-1 and en_US.UTF8 UTF 8.

btw, I've started to use anonymous-pro, very nice font for coding, one can see a clear difference between ":" , ";" and the different brackets..

Those are harmless warnings. Looking at my ~/.xsession-errors, I see:
Code:
dwm: missing fontset: JISX0201.1976-0
dwm: missing fontset: GB2312.1980-0
dwm: missing fontset: KSC5601.1987-0
dwm: missing fontset: JISX0208.1983-0
dwm: missing fontset: ISO8859-14
dwm: missing fontset: ISO8859-4
dwm: missing fontset: ISO8859-3

:lol:
_________________
juniper wrote:
I use ubuntu, which is why I am posting here.


Last edited by Bones McCracker on Mon Jan 28, 2013 1:30 pm; edited 2 times in total
Back to top
View user's profile Send private message
LoTeK
Apprentice
Apprentice


Joined: 26 Jul 2012
Posts: 270

PostPosted: Mon Jan 28, 2013 1:28 pm    Post subject: Reply with quote

but I've set:
Code:
static const char font[] = "-*-anonymous-pro-medium-r-*-*-16-*-*-*-*-*-*-*;

and my font won't get loaded (with openbox it works)
_________________
"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1564
Location: U.S.A.

PostPosted: Mon Jan 28, 2013 1:33 pm    Post subject: Reply with quote

LoTeK wrote:
but I've set:
Code:
static const char font[] = "-*-anonymous-pro-medium-r-*-*-16-*-*-*-*-*-*-*;

and my font won't get loaded (with openbox it works)

PEBKAC (Problem Exists Between Keyboard And Chair). Looks like you forgot the quote at the end of the string. (Does that work in openbox?) :P

By the way, if you haven't found this yet:
http://dwm.suckless.org/
_________________
juniper wrote:
I use ubuntu, which is why I am posting here.
Back to top
View user's profile Send private message
Dr.Willy
Guru
Guru


Joined: 15 Jul 2007
Posts: 324
Location: NRW, Germany

PostPosted: Mon Jan 28, 2013 9:24 pm    Post subject: Reply with quote

BoneKracker wrote:
Code:

URxvt*color0: #000010       // black -> black russian
URxvt*color1: #9e1828       // red -> tamarillo
URxvt*color2: #aece92       // green -> pine glade
URxvt*color3: #968a38       // yello -> sycamore
URxvt*color4: #414171       // blue -> east bay
URxvt*color5: #963c59       // magenta -> vin rouge
URxvt*color6: #418179       // cyan -> viridian
URxvt*color7: #bebebe       // white -> silver
URxvt*color8: #666666       // bright black -> dove gray
URxvt*color9: #cf6171       // bright red -> chestnut rose
URxvt*color10: #c5f779      // gright green -> sulu
URxvt*color11: #fff796      // bright yellow -> witch haze
URxvt*color12: #4186be      // bright blue -> steel blue
URxvt*color13: #cf9ebe      // bright magenta -> viola
URxvt*color14: #71bebe      // bright cyan -> neptune
URxvt*color15: #ffffff      // bright white -> white
URxvt*background: 0
URxvt*foreground: 15
URxvt*cursorColor: magenta


…if you wrote those comments yourself, it's time to hand in your man-card. :P

No seriously, those are actually really good. cat >> .Xresources I say.

BoneKracker wrote:
Rather than a bash script, this is what I use to produce my "status bar", which is updated every second and looks like this:
Code:
Load: 0.46   RAM: 32 MiB   Swap: 0 MiB    Thu Jan 24   00:00:18


This is the code. I wrote it for my use only. It's not very portable, flexible, or idiot-proof; it doesn't include error checking and the other things good code should have before it's distributed. But it's far more efficient than a shell script (the normal way of doing it). It also never closes the display, but that doesn't matter because I always close X when close dwm. To be "correct", I suppose the pointer to the XDisplay should be a global variable, so it could be closed by signal trapping, but I hate global variables and that scenario will probably never occur, and it's a one-time 4-byte leak if it did occur, so fuck it. :lol:

No!
Must -fomg-optimize!
Xlib bad! memset superfluous! strlen() superfluous! PERFORMENSE!

BoneKracker wrote:
To be honest, C is overkill for most things a user would want to do, but extending your desktop environment can be an exception to that, if it's a function that's constantly running or very frequently used.

Yeah that reminds me of when I was still using wmii. I mean I really liked it for what it did, it came with nice defaults and I also liked the "programmable configuration".
But as much as I liked it's 9p interface, when I realised that I was effectively running a shellscript that started a python program that read the user input and used a python library to write commands to a file that would be handeled by a 9p server that would interpret the command I felt that this might just be a little too much overhead for opening a terminal.
Back to top
View user's profile Send private message
aidanjt
Veteran
Veteran


Joined: 20 Feb 2005
Posts: 1101
Location: Rep. of Ireland

PostPosted: Tue Jan 29, 2013 1:44 am    Post subject: Reply with quote

Python is OK for most things, except you have to write python.
_________________
juniper wrote:
you experience political reality dilation when travelling at american political speeds. it's in einstein's formulas. it's not their fault.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum