mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Add SSH terminal colorization
This commit is contained in:
parent
976d77c76d
commit
bcc4f43932
4
Makefile
4
Makefile
|
@ -7,12 +7,12 @@ PREFIX?= /usr/local
|
||||||
|
|
||||||
SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \
|
SRCS= calmwm.c screen.c xmalloc.c client.c menu.c \
|
||||||
search.c util.c xutil.c conf.c xevents.c group.c \
|
search.c util.c xutil.c conf.c xevents.c group.c \
|
||||||
kbfunc.c mousefunc.c parse.y
|
kbfunc.c mousefunc.c parse.y colorize.c
|
||||||
|
|
||||||
OBJS= calmwm.o screen.o xmalloc.o client.o menu.o \
|
OBJS= calmwm.o screen.o xmalloc.o client.o menu.o \
|
||||||
search.o util.o xutil.o conf.o xevents.o group.o \
|
search.o util.o xutil.o conf.o xevents.o group.o \
|
||||||
kbfunc.o mousefunc.o strlcpy.o strlcat.o y.tab.o \
|
kbfunc.o mousefunc.o strlcpy.o strlcat.o y.tab.o \
|
||||||
strtonum.o fgetln.o
|
strtonum.o fgetln.o colorize.o
|
||||||
|
|
||||||
CPPFLAGS+= `pkg-config --cflags fontconfig x11 xft xinerama xrandr`
|
CPPFLAGS+= `pkg-config --cflags fontconfig x11 xft xinerama xrandr`
|
||||||
|
|
||||||
|
|
5
calmwm.h
5
calmwm.h
|
@ -302,6 +302,7 @@ struct conf {
|
||||||
struct ignore_q ignoreq;
|
struct ignore_q ignoreq;
|
||||||
struct cmd_q cmdq;
|
struct cmd_q cmdq;
|
||||||
#define CONF_STICKY_GROUPS 0x0001
|
#define CONF_STICKY_GROUPS 0x0001
|
||||||
|
#define CONF_COLORIZE_SSH 0x0002
|
||||||
int flags;
|
int flags;
|
||||||
#define CONF_BWIDTH 1
|
#define CONF_BWIDTH 1
|
||||||
int bwidth;
|
int bwidth;
|
||||||
|
@ -583,4 +584,8 @@ int xasprintf(char **, const char *, ...)
|
||||||
__attribute__((__format__ (printf, 2, 3)))
|
__attribute__((__format__ (printf, 2, 3)))
|
||||||
__attribute__((__nonnull__ (2)));
|
__attribute__((__nonnull__ (2)));
|
||||||
|
|
||||||
|
long crc24(char *);
|
||||||
|
long tint(long);
|
||||||
|
long shade(long);
|
||||||
|
|
||||||
#endif /* _CALMWM_H_ */
|
#endif /* _CALMWM_H_ */
|
||||||
|
|
67
colorize.c
Normal file
67
colorize.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Dimitri Sokolyuk <demon@dim13.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "calmwm.h"
|
||||||
|
|
||||||
|
#define CRC24_INIT 0x0B704CEL
|
||||||
|
#define CRC24_POLY 0x1864CFBL
|
||||||
|
|
||||||
|
long
|
||||||
|
crc24(char *s)
|
||||||
|
{
|
||||||
|
long crc;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (crc = CRC24_INIT; *s; s++) {
|
||||||
|
crc ^= *s << 0x10;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
crc <<= 1;
|
||||||
|
if (crc & 0x1000000)
|
||||||
|
crc ^= CRC24_POLY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
shade(long c)
|
||||||
|
{
|
||||||
|
unsigned char r = c >> 0x10;
|
||||||
|
unsigned char g = c >> 0x08;
|
||||||
|
unsigned char b = c;
|
||||||
|
|
||||||
|
r >>= 2;
|
||||||
|
g >>= 2;
|
||||||
|
b >>= 2;
|
||||||
|
|
||||||
|
return (r << 0x10) | (g << 0x8) | b;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
tint(long c)
|
||||||
|
{
|
||||||
|
unsigned char r = c >> 0x10;
|
||||||
|
unsigned char g = c >> 0x08;
|
||||||
|
unsigned char b = c;
|
||||||
|
|
||||||
|
r += (UCHAR_MAX - r) >> 1;
|
||||||
|
g += (UCHAR_MAX - g) >> 1;
|
||||||
|
b += (UCHAR_MAX - b) >> 1;
|
||||||
|
|
||||||
|
return (r << 0x10) | (g << 0x8) | b;
|
||||||
|
}
|
3
cwmrc.5
3
cwmrc.5
|
@ -131,6 +131,9 @@ Set the color of the border of a window indicating urgency.
|
||||||
.It Ic color ungroupborder Ar color
|
.It Ic color ungroupborder Ar color
|
||||||
Set the color of the border while ungrouping a window.
|
Set the color of the border while ungrouping a window.
|
||||||
.Pp
|
.Pp
|
||||||
|
.It Ic colorize Ic yes Ns \&| Ns Ic no
|
||||||
|
Colorize SSH terminals with hashed colors.
|
||||||
|
.Pp
|
||||||
.It Ic command Ar name path
|
.It Ic command Ar name path
|
||||||
Every
|
Every
|
||||||
.Ar name
|
.Ar name
|
||||||
|
|
13
kbfunc.c
13
kbfunc.c
|
@ -326,6 +326,8 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
|
||||||
char *buf, *lbuf, *p;
|
char *buf, *lbuf, *p;
|
||||||
char hostbuf[HOST_NAME_MAX+1];
|
char hostbuf[HOST_NAME_MAX+1];
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
long color = 0;
|
||||||
|
char colorarg[32];
|
||||||
int l;
|
int l;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
@ -371,8 +373,15 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
|
||||||
search_match_exec, NULL)) != NULL) {
|
search_match_exec, NULL)) != NULL) {
|
||||||
if (mi->text[0] == '\0')
|
if (mi->text[0] == '\0')
|
||||||
goto out;
|
goto out;
|
||||||
l = snprintf(path, sizeof(path), "%s -T '[ssh] %s' -e ssh %s",
|
if (Conf.flags & CONF_COLORIZE_SSH) {
|
||||||
cmd->path, mi->text, mi->text);
|
color = crc24(mi->text);
|
||||||
|
l = snprintf(colorarg, sizeof(colorarg),
|
||||||
|
" -fg #%.6x -bg #%.6x", tint(color), shade(color));
|
||||||
|
if (l == -1 || l >= sizeof(colorarg))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
l = snprintf(path, sizeof(path), "%s -T '[ssh] %s'%s -e ssh %s",
|
||||||
|
cmd->path, mi->text, color ? colorarg : "", mi->text);
|
||||||
if (l == -1 || l >= sizeof(path))
|
if (l == -1 || l >= sizeof(path))
|
||||||
goto out;
|
goto out;
|
||||||
u_spawn(path);
|
u_spawn(path);
|
||||||
|
|
9
parse.y
9
parse.y
|
@ -70,7 +70,7 @@ typedef struct {
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%token FONTNAME STICKY GAP MOUSEBIND
|
%token FONTNAME STICKY COLORIZE GAP MOUSEBIND
|
||||||
%token AUTOGROUP BIND COMMAND IGNORE
|
%token AUTOGROUP BIND COMMAND IGNORE
|
||||||
%token YES NO BORDERWIDTH MOVEAMOUNT
|
%token YES NO BORDERWIDTH MOVEAMOUNT
|
||||||
%token COLOR SNAPDIST
|
%token COLOR SNAPDIST
|
||||||
|
@ -119,6 +119,12 @@ main : FONTNAME STRING {
|
||||||
else
|
else
|
||||||
conf->flags |= CONF_STICKY_GROUPS;
|
conf->flags |= CONF_STICKY_GROUPS;
|
||||||
}
|
}
|
||||||
|
| COLORIZE yesno {
|
||||||
|
if ($2 == 0)
|
||||||
|
conf->flags &= ~CONF_COLORIZE_SSH;
|
||||||
|
else
|
||||||
|
conf->flags |= CONF_COLORIZE_SSH;
|
||||||
|
}
|
||||||
| BORDERWIDTH NUMBER {
|
| BORDERWIDTH NUMBER {
|
||||||
if ($2 < 0 || $2 > UINT_MAX) {
|
if ($2 < 0 || $2 > UINT_MAX) {
|
||||||
yyerror("invalid borderwidth: %lld", $2);
|
yyerror("invalid borderwidth: %lld", $2);
|
||||||
|
@ -276,6 +282,7 @@ lookup(char *s)
|
||||||
{ "bind", BIND},
|
{ "bind", BIND},
|
||||||
{ "borderwidth", BORDERWIDTH},
|
{ "borderwidth", BORDERWIDTH},
|
||||||
{ "color", COLOR},
|
{ "color", COLOR},
|
||||||
|
{ "colorize", COLORIZE},
|
||||||
{ "command", COMMAND},
|
{ "command", COMMAND},
|
||||||
{ "font", FONTCOLOR},
|
{ "font", FONTCOLOR},
|
||||||
{ "fontname", FONTNAME},
|
{ "fontname", FONTNAME},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user