Allow configuring the upper bound of the hash function
This allows limiting the nick colors used to the 16-color terminal set without modifying the TERM environment variable. Produces different results from just using the default configuration in a 16-color terminal, but what can you do?weechat-hashes
parent
bf70fcbfed
commit
a324795b86
11
catgirl.1
11
catgirl.1
|
@ -1,4 +1,4 @@
|
||||||
.Dd December 30, 2020
|
.Dd January 9, 2021
|
||||||
.Dt CATGIRL 1
|
.Dt CATGIRL 1
|
||||||
.Os
|
.Os
|
||||||
.
|
.
|
||||||
|
@ -77,9 +77,14 @@ The default is the first available of
|
||||||
.Xr xclip 1 ,
|
.Xr xclip 1 ,
|
||||||
.Xr xsel 1 .
|
.Xr xsel 1 .
|
||||||
.
|
.
|
||||||
.It Fl H Ar hash , Cm hash = Ar hash
|
.It Fl H Ar init,bound , Cm hash = Ar init,bound
|
||||||
Set the initial value of
|
Set the initial value of
|
||||||
the nick color hash function.
|
the nick color hash function
|
||||||
|
and the maximum IRC color value used.
|
||||||
|
The default is 0,75.
|
||||||
|
To use only colors from
|
||||||
|
the 16-color terminal set,
|
||||||
|
use 0,15.
|
||||||
.
|
.
|
||||||
.It Fl N Ar util , Cm notify = Ar util
|
.It Fl N Ar util , Cm notify = Ar util
|
||||||
Send notifications using a utility.
|
Send notifications using a utility.
|
||||||
|
|
12
chat.c
12
chat.c
|
@ -87,8 +87,6 @@ static void exitSave(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t hashInit;
|
|
||||||
|
|
||||||
uint execID;
|
uint execID;
|
||||||
int execPipe[2] = { -1, -1 };
|
int execPipe[2] = { -1, -1 };
|
||||||
int utilPipe[2] = { -1, -1 };
|
int utilPipe[2] = { -1, -1 };
|
||||||
|
@ -117,6 +115,14 @@ static void utilRead(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t hashInit;
|
||||||
|
uint32_t hashBound = 75;
|
||||||
|
|
||||||
|
static void parseHash(char *str) {
|
||||||
|
hashInit = strtoul(str, &str, 0);
|
||||||
|
if (*str) hashBound = strtoul(&str[1], NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static volatile sig_atomic_t signals[NSIG];
|
static volatile sig_atomic_t signals[NSIG];
|
||||||
static void signalHandler(int signal) {
|
static void signalHandler(int signal) {
|
||||||
signals[signal] = 1;
|
signals[signal] = 1;
|
||||||
|
@ -179,7 +185,7 @@ int main(int argc, char *argv[]) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
break; case '!': insecure = true;
|
break; case '!': insecure = true;
|
||||||
break; case 'C': utilPush(&urlCopyUtil, optarg);
|
break; case 'C': utilPush(&urlCopyUtil, optarg);
|
||||||
break; case 'H': hashInit = strtoul(optarg, NULL, 0);
|
break; case 'H': parseHash(optarg);
|
||||||
break; case 'N': utilPush(&uiNotifyUtil, optarg);
|
break; case 'N': utilPush(&uiNotifyUtil, optarg);
|
||||||
break; case 'O': utilPush(&urlOpenUtil, optarg);
|
break; case 'O': utilPush(&urlOpenUtil, optarg);
|
||||||
break; case 'R': self.restricted = true;
|
break; case 'R': self.restricted = true;
|
||||||
|
|
3
chat.h
3
chat.h
|
@ -137,6 +137,7 @@ static inline uint idFor(const char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint32_t hashInit;
|
extern uint32_t hashInit;
|
||||||
|
extern uint32_t hashBound;
|
||||||
static inline enum Color hash(const char *str) {
|
static inline enum Color hash(const char *str) {
|
||||||
if (*str == '~') str++;
|
if (*str == '~') str++;
|
||||||
uint32_t hash = hashInit;
|
uint32_t hash = hashInit;
|
||||||
|
@ -145,7 +146,7 @@ static inline enum Color hash(const char *str) {
|
||||||
hash ^= *str;
|
hash ^= *str;
|
||||||
hash *= 0x27220A95;
|
hash *= 0x27220A95;
|
||||||
}
|
}
|
||||||
return Blue + hash % 74;
|
return Blue + hash % (hashBound + 1 - Blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern struct Network {
|
extern struct Network {
|
||||||
|
|
Loading…
Reference in New Issue