Skip to content

Instantly share code, notes, and snippets.

@bisqwit
Created October 5, 2017 06:54
Show Gist options
  • Save bisqwit/a0e2cf4502a044a85837c43fe7ea4ac5 to your computer and use it in GitHub Desktop.
Save bisqwit/a0e2cf4502a044a85837c43fe7ea4ac5 to your computer and use it in GitHub Desktop.
My Xterm launcher script
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
#include <cstdio>
using namespace std;
/* saturation, value and hue all are 0..1 */
static void MakeTint(char *dest, double saturation, double value, double hue)
{
const double v = value * 255.0;
hue *= 6.0;
const double f = hue - (int)hue;
const double x = v * (1.0 - saturation);
const double y = v * (1.0 - (saturation * f));
const double z = v * (1.0 - (saturation * (1.0 - f)));
unsigned hex;
switch((int)hue)
{
case 0: hex = (((unsigned)v) << 16) | (((unsigned)z) << 8) | ((unsigned)x); break;
case 1: hex = (((unsigned)y) << 16) | (((unsigned)v) << 8) | ((unsigned)x); break;
case 2: hex = (((unsigned)x) << 16) | (((unsigned)v) << 8) | ((unsigned)z); break;
case 3: hex = (((unsigned)x) << 16) | (((unsigned)y) << 8) | ((unsigned)v); break;
case 4: hex = (((unsigned)z) << 16) | (((unsigned)x) << 8) | ((unsigned)v); break;
default:hex = (((unsigned)v) << 16) | (((unsigned)x) << 8) | ((unsigned)y); break;
}
sprintf(dest, "#%06X", hex);
}
int main(int argc, char** argv)
{
srand48(time(NULL));
double tint = drand48();
static char Tausta[8] = "#000000";
static char Kursori[8] = "#FFFFFF";
MakeTint(Tausta, 0.15, 1.00, tint);
MakeTint(Kursori, 0.20, 1.00, tint);
static const char *const parms[] =
{
"xterm",
"-bg", "black",
"-fg", "gray",
"-fn", "-misc-fixed-bold-r-normal--15-140-75-75-c-90-iso10646-1",
"-fb", "-misc-fixed-bold-r-normal--15-140-75-75-c-90-iso10646-1",
"-en", "UTF-8", "-u8",
"+rv",
"+bdc",
"-T", "Uterm",
"-wc",
"-bw", "0",
"-cr", Kursori,
"-k8",
"-sl", "5000",
"-geometry", "132x50"
};
std::vector<const char*> p;
p.assign(parms, parms + sizeof(parms)/sizeof(*parms));
p.insert(p.end(), argv+1, argv+argc);
p.push_back(NULL);
putenv( (char *) "LC_ALL=en_US");
execvp(parms[0], (char* const*) &p[0]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment