From f99f7dca7552d21782354f675c0741896c9785f1 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Mon, 8 Oct 2018 10:10:42 +0100
Subject: 43616: Various parameter setting and display fixes.
Mostly to do with typeset -p and tied variables and their interaction.
Some general tied variable fixes.
---
Src/Modules/db_gdbm.c | 2 +-
Src/Modules/parameter.c | 44 +++++++++++++++++++++++---------------------
2 files changed, 24 insertions(+), 22 deletions(-)
(limited to 'Src/Modules')
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index ed702b912..12dd839cf 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -809,7 +809,7 @@ myfreeparamnode(HashNode hn)
zsfree(pm->node.nam);
/* If this variable was tied by the user, ename was ztrdup'd */
- if (pm->node.flags & PM_TIED && pm->ename) {
+ if (!(pm->node.flags & PM_SPECIAL) && pm->ename) {
zsfree(pm->ename);
pm->ename = NULL;
}
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 783c36df3..76824cf58 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -75,6 +75,8 @@ paramtypestr(Param pm)
val = dyncat(val, "-readonly");
if (f & PM_TAGGED)
val = dyncat(val, "-tag");
+ if (f & PM_TIED)
+ val = dyncat(val, "-tied");
if (f & PM_EXPORTED)
val = dyncat(val, "-export");
if (f & PM_UNIQUE)
@@ -2194,67 +2196,67 @@ static const struct gsu_array historywords_gsu =
static struct paramdef partab[] = {
SPECIALPMDEF("aliases", 0,
&pmraliases_gsu, getpmralias, scanpmraliases),
- SPECIALPMDEF("builtins", PM_READONLY, NULL, getpmbuiltin, scanpmbuiltins),
+ SPECIALPMDEF("builtins", PM_READONLY_SPECIAL, NULL, getpmbuiltin, scanpmbuiltins),
SPECIALPMDEF("commands", 0, &pmcommands_gsu, getpmcommand, scanpmcommands),
SPECIALPMDEF("dirstack", PM_ARRAY,
&dirs_gsu, NULL, NULL),
SPECIALPMDEF("dis_aliases", 0,
&pmdisraliases_gsu, getpmdisralias, scanpmdisraliases),
- SPECIALPMDEF("dis_builtins", PM_READONLY,
+ SPECIALPMDEF("dis_builtins", PM_READONLY_SPECIAL,
NULL, getpmdisbuiltin, scanpmdisbuiltins),
SPECIALPMDEF("dis_functions", 0,
&pmdisfunctions_gsu, getpmdisfunction, scanpmdisfunctions),
- SPECIALPMDEF("dis_functions_source", PM_READONLY, NULL,
+ SPECIALPMDEF("dis_functions_source", PM_READONLY_SPECIAL, NULL,
getpmdisfunction_source, scanpmdisfunction_source),
SPECIALPMDEF("dis_galiases", 0,
&pmdisgaliases_gsu, getpmdisgalias, scanpmdisgaliases),
- SPECIALPMDEF("dis_patchars", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("dis_patchars", PM_ARRAY|PM_READONLY_SPECIAL,
&dispatchars_gsu, NULL, NULL),
- SPECIALPMDEF("dis_reswords", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("dis_reswords", PM_ARRAY|PM_READONLY_SPECIAL,
&disreswords_gsu, NULL, NULL),
SPECIALPMDEF("dis_saliases", 0,
&pmdissaliases_gsu, getpmdissalias, scanpmdissaliases),
- SPECIALPMDEF("funcfiletrace", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("funcfiletrace", PM_ARRAY|PM_READONLY_SPECIAL,
&funcfiletrace_gsu, NULL, NULL),
- SPECIALPMDEF("funcsourcetrace", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("funcsourcetrace", PM_ARRAY|PM_READONLY_SPECIAL,
&funcsourcetrace_gsu, NULL, NULL),
- SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY_SPECIAL,
&funcstack_gsu, NULL, NULL),
SPECIALPMDEF("functions", 0, &pmfunctions_gsu, getpmfunction,
scanpmfunctions),
- SPECIALPMDEF("functions_source", PM_READONLY, NULL,
+ SPECIALPMDEF("functions_source", PM_READONLY_SPECIAL, NULL,
getpmfunction_source, scanpmfunction_source),
- SPECIALPMDEF("functrace", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("functrace", PM_ARRAY|PM_READONLY_SPECIAL,
&functrace_gsu, NULL, NULL),
SPECIALPMDEF("galiases", 0,
&pmgaliases_gsu, getpmgalias, scanpmgaliases),
- SPECIALPMDEF("history", PM_READONLY,
+ SPECIALPMDEF("history", PM_READONLY_SPECIAL,
NULL, getpmhistory, scanpmhistory),
- SPECIALPMDEF("historywords", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("historywords", PM_ARRAY|PM_READONLY_SPECIAL,
&historywords_gsu, NULL, NULL),
- SPECIALPMDEF("jobdirs", PM_READONLY,
+ SPECIALPMDEF("jobdirs", PM_READONLY_SPECIAL,
NULL, getpmjobdir, scanpmjobdirs),
- SPECIALPMDEF("jobstates", PM_READONLY,
+ SPECIALPMDEF("jobstates", PM_READONLY_SPECIAL,
NULL, getpmjobstate, scanpmjobstates),
- SPECIALPMDEF("jobtexts", PM_READONLY,
+ SPECIALPMDEF("jobtexts", PM_READONLY_SPECIAL,
NULL, getpmjobtext, scanpmjobtexts),
- SPECIALPMDEF("modules", PM_READONLY,
+ SPECIALPMDEF("modules", PM_READONLY_SPECIAL,
NULL, getpmmodule, scanpmmodules),
SPECIALPMDEF("nameddirs", 0,
&pmnameddirs_gsu, getpmnameddir, scanpmnameddirs),
SPECIALPMDEF("options", 0,
&pmoptions_gsu, getpmoption, scanpmoptions),
- SPECIALPMDEF("parameters", PM_READONLY,
+ SPECIALPMDEF("parameters", PM_READONLY_SPECIAL,
NULL, getpmparameter, scanpmparameters),
- SPECIALPMDEF("patchars", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("patchars", PM_ARRAY|PM_READONLY_SPECIAL,
&patchars_gsu, NULL, NULL),
- SPECIALPMDEF("reswords", PM_ARRAY|PM_READONLY,
+ SPECIALPMDEF("reswords", PM_ARRAY|PM_READONLY_SPECIAL,
&reswords_gsu, NULL, NULL),
SPECIALPMDEF("saliases", 0,
&pmsaliases_gsu, getpmsalias, scanpmsaliases),
- SPECIALPMDEF("userdirs", PM_READONLY,
+ SPECIALPMDEF("userdirs", PM_READONLY_SPECIAL,
NULL, getpmuserdir, scanpmuserdirs),
- SPECIALPMDEF("usergroups", PM_READONLY,
+ SPECIALPMDEF("usergroups", PM_READONLY_SPECIAL,
NULL, getpmusergroups, scanpmusergroups)
};
--
cgit v1.2.3
From 37d0005a9e651f366076c930019464d162506a57 Mon Sep 17 00:00:00 2001
From: Oliver Kiddle
Date: Mon, 5 Nov 2018 22:24:05 +0100
Subject: 43747: new module to map colours from hex triplets to the nearest
matching colour
---
ChangeLog | 6 ++
Src/Modules/nearcolor.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++
Src/Modules/nearcolor.mdd | 5 ++
Src/init.c | 1 +
Src/prompt.c | 19 ++++-
Src/zsh.h | 7 ++
6 files changed, 215 insertions(+), 1 deletion(-)
create mode 100644 Src/Modules/nearcolor.c
create mode 100644 Src/Modules/nearcolor.mdd
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index 1dfcb58f9..d224f7840 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-05 Oliver Kiddle
+
+ * 43747: Src/Modules/nearcolor.c, Src/Modules/nearcolor.mdd,
+ Src/init.c, Src/prompt.c, Src/zsh.h: new module to map
+ colours from hex triplets to the nearest matching colour
+
2018-11-03 Peter Stephenson
* 43752: Completion/Base/Completer/_expand: Fix quoting if
diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
new file mode 100644
index 000000000..2a763d470
--- /dev/null
+++ b/Src/Modules/nearcolor.c
@@ -0,0 +1,178 @@
+#include "nearcolor.mdh"
+#include "nearcolor.pro"
+
+#include
+
+struct cielab {
+ float L, a, b;
+};
+typedef struct cielab *Cielab;
+
+static float
+deltae(Cielab lab1, Cielab lab2)
+{
+ /* taking square root unnecessary as we're just comparing values */
+ return powf(lab1->L - lab2->L, 2) +
+ powf(lab1->a - lab2->a, 2) +
+ powf(lab1->b - lab2->b, 2);
+}
+
+static void
+RGBtoLAB(int red, int green, int blue, Cielab lab)
+{
+ float R = (float)red / 255.0;
+ float G = (float)green / 255.0;
+ float B = (float)blue / 255.0;
+ R = 100.0 * (R > 0.04045 ? powf((R + 0.055) / 1.055, 2.4) : R / 12.92);
+ G = 100.0 * (G > 0.04045 ? powf((G + 0.055) / 1.055, 2.4) : G / 12.92);
+ B = 100.0 * (B > 0.04045 ? powf((B + 0.055) / 1.055, 2.4) : B / 12.92);
+
+ /* Observer. = 2 degrees, Illuminant = D65 */
+ float X = (R * 0.4124 + G * 0.3576 + B * 0.1805) / 95.047;
+ float Y = (R * 0.2126 + G * 0.7152 + B * 0.0722) / 100.0;
+ float Z = (R * 0.0193 + G * 0.1192 + B * 0.9505) / 108.883;
+
+ X = (X > 0.008856) ? powf(X, 1.0/3.0) : (7.787 * X) + (16.0 / 116.0);
+ Y = (Y > 0.008856) ? powf(Y, 1.0/3.0) : (7.787 * Y) + (16.0 / 116.0);
+ Z = (Z > 0.008856) ? powf(Z, 1.0/3.0) : (7.787 * Z) + (16.0 / 116.0);
+
+ lab->L = (116.0 * Y) - 16.0;
+ lab->a = 500.0 * (X - Y);
+ lab->b = 200.0 * (Y - Z);
+}
+
+static int
+mapRGBto88(int red, int green, int blue)
+{
+ int component[] = { 0, 0x8b, 0xcd, 0xff, 0x2e, 0x5c, 0x8b, 0xa2, 0xb9, 0xd0, 0xe7 };
+ struct cielab orig, next;
+ float nextl, bestl = -1;
+ int r, g, b;
+ int comp_r = 0, comp_g = 0, comp_b = 0;
+
+ /* Get original value */
+ RGBtoLAB(red, green, blue, &orig);
+
+ /* try every one of the 72 colours */
+ for (r = 0; r < 11; r++) {
+ for (g = 0; g <= 3; g++) {
+ for (b = 0; b <= 3; b++) {
+ if (r > 3) g = b = r; /* advance inner loops to the block of greys */
+ RGBtoLAB(component[r], component[g], component[b], &next);
+ nextl = deltae(&orig, &next);
+ if (nextl < bestl || bestl < 0) {
+ bestl = nextl;
+ comp_r = r;
+ comp_g = g;
+ comp_b = b;
+ }
+ }
+ }
+ }
+
+ return (comp_r > 3) ? 77 + comp_r :
+ 16 + (comp_r * 16) + (comp_g * 4) + comp_b;
+}
+
+/*
+ * Convert RGB to nearest colour in the 256 colour range
+ */
+static int
+mapRGBto256(int red, int green, int blue)
+{
+ int component[] = {
+ 0, 0x5f, 0x87, 0xaf, 0xd7, 0xff,
+ 0x8, 0x12, 0x1c, 0x26, 0x30, 0x3a, 0x44, 0x4e,
+ 0x58, 0x62, 0x6c, 0x76, 0x80, 0x8a, 0x94, 0x9e,
+ 0xa8, 0xb2, 0xbc, 0xc6, 0xd0, 0xda, 0xe4, 0xee
+ };
+ struct cielab orig, next;
+ float nextl, bestl = -1;
+ int r, g, b;
+ int comp_r = 0, comp_g = 0, comp_b = 0;
+
+ /* Get original value */
+ RGBtoLAB(red, green, blue, &orig);
+
+ for (r = 0; r < sizeof(component)/sizeof(*component); r++) {
+ for (g = 0; g <= 5; g++) {
+ for (b = 0; b <= 5; b++) {
+ if (r > 5) g = b = r; /* advance inner loops to the block of greys */
+ RGBtoLAB(component[r], component[g], component[b], &next);
+ nextl = deltae(&orig, &next);
+ if (nextl < bestl || bestl < 0) {
+ bestl = nextl;
+ comp_r = r;
+ comp_g = g;
+ comp_b = b;
+ }
+ }
+ }
+ }
+
+ return (comp_r > 5) ? 226 + comp_r :
+ 16 + (comp_r * 36) + (comp_g * 6) + comp_b;
+}
+
+static int
+getnearestcolor(UNUSED(Hookdef dummy), Color_rgb col)
+{
+ if (tccolours == 256)
+ return mapRGBto256(col->red, col->green, col->blue);
+ if (tccolours == 88)
+ return mapRGBto88(col->red, col->green, col->blue);
+ return 0;
+}
+
+static struct features module_features = {
+ NULL, 0,
+ NULL, 0,
+ NULL, 0,
+ NULL, 0,
+ 0
+};
+
+/**/
+int
+setup_(UNUSED(Module m))
+{
+ return 0;
+}
+
+/**/
+int
+features_(Module m, char ***features)
+{
+ *features = featuresarray(m, &module_features);
+ return 0;
+}
+
+/**/
+int
+enables_(Module m, int **enables)
+{
+ return handlefeatures(m, &module_features, enables);
+}
+
+/**/
+int
+boot_(Module m)
+{
+ addhookfunc("get_color_attr", (Hookfn) getnearestcolor);
+ return 0;
+}
+
+/**/
+int
+cleanup_(Module m)
+{
+ deletehookfunc("get_color_attr", (Hookfn) getnearestcolor);
+ return setfeatureenables(m, &module_features, NULL);
+}
+
+/**/
+int
+finish_(UNUSED(Module m))
+{
+ return 0;
+}
diff --git a/Src/Modules/nearcolor.mdd b/Src/Modules/nearcolor.mdd
new file mode 100644
index 000000000..2fcdaf04e
--- /dev/null
+++ b/Src/Modules/nearcolor.mdd
@@ -0,0 +1,5 @@
+name=zsh/nearcolor
+link=dynamic
+load=no
+
+objects="nearcolor.o"
diff --git a/Src/init.c b/Src/init.c
index cec914329..e7e62e2f7 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -94,6 +94,7 @@ mod_export struct hookdef zshhooks[] = {
HOOKDEF("exit", NULL, HOOKF_ALL),
HOOKDEF("before_trap", NULL, HOOKF_ALL),
HOOKDEF("after_trap", NULL, HOOKF_ALL),
+ HOOKDEF("get_color_attr", NULL, HOOKF_ALL),
};
/* keep executing lists until EOF found */
diff --git a/Src/prompt.c b/Src/prompt.c
index 959ed8e3d..39edbdb2b 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1621,7 +1621,24 @@ match_colour(const char **teststrp, int is_fg, int colour)
int shft, on, named = 0, tc;
if (teststrp) {
- if ((named = ialpha(**teststrp))) {
+ if (**teststrp == '#' && isxdigit((*teststrp)[1])) {
+ struct color_rgb color;
+ char *end;
+ zlong col = zstrtol(*teststrp+1, &end, 16);
+ if (end - *teststrp == 4) {
+ color.red = col >> 8 | ((col >> 8) << 4);
+ color.green = (col & 0xf0) >> 4;
+ color.green |= color.green << 4;
+ color.blue = col & 0xf;
+ color.blue |= color.blue << 4;
+ } else if (end - *teststrp == 7) {
+ color.red = col >> 16;
+ color.green = (col & 0xff00) >> 8;
+ color.blue = col & 0xff;
+ }
+ *teststrp = end;
+ colour = runhookdef(GETCOLORATTR, &color);
+ } else if ((named = ialpha(**teststrp))) {
colour = match_named_colour(teststrp);
if (colour == 8) {
/* default */
diff --git a/Src/zsh.h b/Src/zsh.h
index 894158818..68731e226 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2707,6 +2707,12 @@ struct ttyinfo {
#define COL_SEQ_BG (1)
#define COL_SEQ_COUNT (2)
+struct color_rgb {
+ unsigned int red, green, blue;
+};
+
+typedef struct color_rgb *Color_rgb;
+
/*
* Flags to testcap() and set_colour_attribute (which currently only
* handles TSC_PROMPT).
@@ -3203,6 +3209,7 @@ enum {
#define EXITHOOK (zshhooks + 0)
#define BEFORETRAPHOOK (zshhooks + 1)
#define AFTERTRAPHOOK (zshhooks + 2)
+#define GETCOLORATTR (zshhooks + 3)
#ifdef MULTIBYTE_SUPPORT
/* Final argument to mb_niceformat() */
--
cgit v1.2.3
From 50597692e021ee071b971e13a14dde5b22d31639 Mon Sep 17 00:00:00 2001
From: Oliver Kiddle
Date: Mon, 5 Nov 2018 22:24:10 +0100
Subject: 43759: add support for true colour terminals
---
ChangeLog | 5 +++
Src/Modules/nearcolor.c | 8 ++--
Src/Zle/complist.c | 9 +++--
Src/Zle/zle.h | 4 +-
Src/Zle/zle_refresh.c | 31 ++++++++-------
Src/Zle/zle_tricky.c | 9 +++--
Src/prompt.c | 104 ++++++++++++++++++++++++++++--------------------
Src/zsh.h | 33 ++++++++++-----
Src/zsh_system.h | 4 ++
9 files changed, 127 insertions(+), 80 deletions(-)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index d224f7840..cb18c9e71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2018-11-05 Oliver Kiddle
+ * 43759: Src/Modules/nearcolor.c, Src/Zle/complist.c,
+ Src/Zle/zle.h, Src/Zle/zle_refresh.c, Src/Zle/zle_tricky.c,
+ Src/prompt.c, Src/zsh.h, Src/zsh_system.h: add support for
+ true colour terminals
+
* 43747: Src/Modules/nearcolor.c, Src/Modules/nearcolor.mdd,
Src/init.c, Src/prompt.c, Src/zsh.h: new module to map
colours from hex triplets to the nearest matching colour
diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
index 2a763d470..128658e20 100644
--- a/Src/Modules/nearcolor.c
+++ b/Src/Modules/nearcolor.c
@@ -118,10 +118,12 @@ static int
getnearestcolor(UNUSED(Hookdef dummy), Color_rgb col)
{
if (tccolours == 256)
- return mapRGBto256(col->red, col->green, col->blue);
+ return mapRGBto256(col->red, col->green, col->blue) + 1;
if (tccolours == 88)
- return mapRGBto88(col->red, col->green, col->blue);
- return 0;
+ return mapRGBto88(col->red, col->green, col->blue) + 1;
+ /* returning 1 indicates black rather than failure (0) so this
+ * module still serves to prevent fallback on true color */
+ return 1;
}
static struct features module_features = {
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index e768aee5d..429c8159f 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -1096,6 +1096,7 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
p += len;
if (*p) {
int arg = 0, is_fg;
+ zattr atr;
if (idigit(*p))
arg = zstrtol(p, &p, 10);
@@ -1159,13 +1160,13 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
/* colours must be ASCII */
if (*p == '{') {
p++;
- arg = match_colour((const char **)&p, is_fg, 0);
+ atr = match_colour((const char **)&p, is_fg, 0);
if (*p == '}')
p++;
} else
- arg = match_colour(NULL, is_fg, arg);
- if (arg >= 0 && dopr)
- set_colour_attribute(arg, is_fg ? COL_SEQ_FG :
+ atr = match_colour(NULL, is_fg, arg);
+ if (atr != TXT_ERROR && dopr)
+ set_colour_attribute(atr, is_fg ? COL_SEQ_FG :
COL_SEQ_BG, 0);
break;
case ZWC('f'):
diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h
index 8261da92b..f06c56483 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -430,7 +430,7 @@ enum {
*/
struct region_highlight {
/* Attributes turned on in the region */
- int atr;
+ zattr atr;
/* Start of the region */
int start;
/* Start of the region in metafied ZLE line */
@@ -488,7 +488,7 @@ typedef struct {
* need the effect; 'off' attributes are only present for the
* last character in the sequence.
*/
- int atr;
+ zattr atr;
} REFRESH_ELEMENT;
/* A string of screen cells */
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index d0dd1ef06..1f293845f 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -149,7 +149,7 @@ char *lpromptbuf, *rpromptbuf;
/* Text attributes after displaying prompts */
/**/
-unsigned pmpt_attr, rpmpt_attr;
+zattr pmpt_attr, rpmpt_attr;
/* number of lines displayed */
@@ -208,7 +208,7 @@ int predisplaylen, postdisplaylen;
* displayed on screen.
*/
-static int default_atr_on, special_atr_on;
+static zattr default_atr_on, special_atr_on;
/*
* Array of region highlights, no special termination.
@@ -521,7 +521,7 @@ unset_region_highlight(Param pm, int exp)
/* The last attributes that were on. */
-static int lastatr;
+static zattr lastatr;
/*
* Clear the last attributes that we set: used when we're going
@@ -560,7 +560,7 @@ tcoutclear(int cap)
/**/
void
-zwcputc(const REFRESH_ELEMENT *c, int *curatrp)
+zwcputc(const REFRESH_ELEMENT *c, zattr *curatrp)
{
/*
* Safety: turn attributes off if last heard of turned on.
@@ -638,7 +638,7 @@ static int
zwcwrite(const REFRESH_STRING s, size_t i)
{
size_t j;
- int curatr = 0;
+ zattr curatr = 0;
for (j = 0; j < i; j++)
zwcputc(s + j, &curatr);
@@ -891,7 +891,7 @@ snextline(Rparams rpms)
/**/
static void
-settextattributes(int atr)
+settextattributes(zattr atr)
{
if (txtchangeisset(atr, TXTNOBOLDFACE))
tsetcap(TCALLATTRSOFF, 0);
@@ -992,7 +992,7 @@ zrefresh(void)
int tmppos; /* t - tmpline */
int tmpalloced; /* flag to free tmpline when finished */
int remetafy; /* flag that zle line is metafied */
- int txtchange; /* attributes set after prompts */
+ zattr txtchange; /* attributes set after prompts */
int rprompt_off = 1; /* Offset of rprompt from right of screen */
struct rparams rpms;
#ifdef MULTIBYTE_SUPPORT
@@ -1212,8 +1212,9 @@ zrefresh(void)
rpms.s = nbuf[rpms.ln = 0] + lpromptw;
rpms.sen = *nbuf + winw;
for (t = tmpline, tmppos = 0; tmppos < tmpll; t++, tmppos++) {
- int base_atr_on = default_atr_on, base_atr_off = 0, ireg;
- int all_atr_on, all_atr_off;
+ unsigned ireg;
+ zattr base_atr_on = default_atr_on, base_atr_off = 0;
+ zattr all_atr_on, all_atr_off;
struct region_highlight *rhp;
/*
* Calculate attribute based on region.
@@ -1446,7 +1447,8 @@ zrefresh(void)
more_end = 1;
if (statusline) {
- int outll, outsz, all_atr_on, all_atr_off;
+ int outll, outsz;
+ zattr all_atr_on, all_atr_off;
char *statusdup = ztrdup(statusline);
ZLE_STRING_T outputline =
stringaszleline(statusdup, 0, &outll, &outsz, NULL);
@@ -1672,7 +1674,7 @@ zrefresh(void)
/* output the right-prompt if appropriate */
if (put_rpmpt && !iln && !oput_rpmpt) {
- int attrchange;
+ zattr attrchange;
moveto(0, winw - rprompt_off - rpromptw);
zputs(rpromptbuf, shout);
@@ -1926,7 +1928,7 @@ refreshline(int ln)
/* 3: main display loop - write out the buffer using whatever tricks we can */
for (;;) {
- int now_off;
+ zattr now_off;
#ifdef MULTIBYTE_SUPPORT
if ((!nl->chr || nl->chr != WEOF) && (!ol->chr || ol->chr != WEOF)) {
@@ -2506,8 +2508,9 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs)
*vp = zr_zr;
for (t0 = 0; t0 < tmpll; t0++) {
- int base_atr_on = 0, base_atr_off = 0, ireg;
- int all_atr_on, all_atr_off;
+ unsigned ireg;
+ zattr base_atr_on = 0, base_atr_off = 0;
+ zattr all_atr_on, all_atr_off;
struct region_highlight *rhp;
/*
* Calculate attribute based on region.
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 22c381237..2b25d6b2e 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -2431,6 +2431,7 @@ printfmt(char *fmt, int n, int dopr, int doesc)
/* Handle the `%' stuff (%% == %, %n == ). */
if (doesc && *p == '%') {
int arg = 0, is_fg;
+ zattr atr;
if (idigit(*++p))
arg = zstrtol(p, &p, 10);
if (*p) {
@@ -2482,13 +2483,13 @@ printfmt(char *fmt, int n, int dopr, int doesc)
is_fg = (*p == 'F');
if (p[1] == '{') {
p += 2;
- arg = match_colour((const char **)&p, is_fg, 0);
+ atr = match_colour((const char **)&p, is_fg, 0);
if (*p != '}')
p--;
} else
- arg = match_colour(NULL, is_fg, arg);
- if (arg >= 0)
- set_colour_attribute(arg, is_fg ? COL_SEQ_FG :
+ atr = match_colour(NULL, is_fg, arg);
+ if (atr != TXT_ERROR)
+ set_colour_attribute(atr, is_fg ? COL_SEQ_FG :
COL_SEQ_BG, 0);
break;
case 'f':
diff --git a/Src/prompt.c b/Src/prompt.c
index 39edbdb2b..284c02475 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -33,7 +33,7 @@
/* text attribute mask */
/**/
-mod_export unsigned txtattrmask;
+mod_export zattr txtattrmask;
/* the command stack for use with %_ in prompts */
@@ -168,7 +168,7 @@ promptpath(char *p, int npath, int tilde)
/**/
mod_export char *
-promptexpand(char *s, int ns, char *rs, char *Rs, unsigned int *txtchangep)
+promptexpand(char *s, int ns, char *rs, char *Rs, zattr *txtchangep)
{
struct buf_vars new_vars;
@@ -236,8 +236,8 @@ promptexpand(char *s, int ns, char *rs, char *Rs, unsigned int *txtchangep)
}
/* Parse the argument for %F and %K */
-static int
-parsecolorchar(int arg, int is_fg)
+static zattr
+parsecolorchar(zattr arg, int is_fg)
{
if (bv->fm[1] == '{') {
char *ep;
@@ -268,10 +268,11 @@ parsecolorchar(int arg, int is_fg)
/**/
static int
-putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
+putpromptchar(int doprint, int endchar, zattr *txtchangep)
{
char *ss, *hostnam;
int t0, arg, test, sep, j, numjobs, len;
+ zattr atr;
struct tm *tm;
struct timespec ts;
time_t timet;
@@ -538,13 +539,13 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
tsetcap(TCUNDERLINEEND, TSC_PROMPT|TSC_DIRTY);
break;
case 'F':
- arg = parsecolorchar(arg, 1);
- if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) {
- txtchangeset(txtchangep, arg & TXT_ATTR_FG_ON_MASK,
+ atr = parsecolorchar(arg, 1);
+ if (!(atr & (TXT_ERROR | TXTNOFGCOLOUR))) {
+ txtchangeset(txtchangep, atr & TXT_ATTR_FG_ON_MASK,
TXTNOFGCOLOUR | TXT_ATTR_FG_COL_MASK);
txtunset(TXT_ATTR_FG_COL_MASK);
- txtset(arg & TXT_ATTR_FG_ON_MASK);
- set_colour_attribute(arg, COL_SEQ_FG, TSC_PROMPT);
+ txtset(atr & TXT_ATTR_FG_ON_MASK);
+ set_colour_attribute(atr, COL_SEQ_FG, TSC_PROMPT);
break;
}
/* else FALLTHROUGH */
@@ -554,13 +555,13 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, TSC_PROMPT);
break;
case 'K':
- arg = parsecolorchar(arg, 0);
- if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) {
- txtchangeset(txtchangep, arg & TXT_ATTR_BG_ON_MASK,
+ atr = parsecolorchar(arg, 0);
+ if (!(atr & (TXT_ERROR | TXTNOBGCOLOUR))) {
+ txtchangeset(txtchangep, atr & TXT_ATTR_BG_ON_MASK,
TXTNOBGCOLOUR | TXT_ATTR_BG_COL_MASK);
txtunset(TXT_ATTR_BG_COL_MASK);
- txtset(arg & TXT_ATTR_BG_ON_MASK);
- set_colour_attribute(arg, COL_SEQ_BG, TSC_PROMPT);
+ txtset(atr & TXT_ATTR_BG_ON_MASK);
+ set_colour_attribute(atr, COL_SEQ_BG, TSC_PROMPT);
break;
}
/* else FALLTHROUGH */
@@ -1185,7 +1186,7 @@ countprompt(char *str, int *wp, int *hp, int overf)
/**/
static int
prompttrunc(int arg, int truncchar, int doprint, int endchar,
- unsigned int *txtchangep)
+ zattr *txtchangep)
{
if (arg > 0) {
char ch = *bv->fm, *ptr, *truncstr;
@@ -1567,8 +1568,8 @@ static const char *ansi_colours[] = {
/* Defines the available types of highlighting */
struct highlight {
const char *name;
- int mask_on;
- int mask_off;
+ zattr mask_on;
+ zattr mask_off;
};
static const struct highlight highlights[] = {
@@ -1615,11 +1616,21 @@ match_named_colour(const char **teststrp)
*/
/**/
-mod_export int
+mod_export zattr
match_colour(const char **teststrp, int is_fg, int colour)
{
- int shft, on, named = 0, tc;
+ int shft, named = 0, tc;
+ zattr on;
+ if (is_fg) {
+ shft = TXT_ATTR_FG_COL_SHIFT;
+ on = TXTFGCOLOUR;
+ tc = TCFGCOLOUR;
+ } else {
+ shft = TXT_ATTR_BG_COL_SHIFT;
+ on = TXTBGCOLOUR;
+ tc = TCBGCOLOUR;
+ }
if (teststrp) {
if (**teststrp == '#' && isxdigit((*teststrp)[1])) {
struct color_rgb color;
@@ -1637,7 +1648,12 @@ match_colour(const char **teststrp, int is_fg, int colour)
color.blue = col & 0xff;
}
*teststrp = end;
- colour = runhookdef(GETCOLORATTR, &color);
+ colour = runhookdef(GETCOLORATTR, &color) - 1;
+ if (colour < 0) { /* no hook function added, try true color (24-bit) */
+ colour = (((color.red << 8) + color.green) << 8) + color.blue;
+ return on | (is_fg ? TXT_ATTR_FG_24BIT : TXT_ATTR_BG_24BIT) |
+ (zattr)colour << shft;
+ }
} else if ((named = ialpha(**teststrp))) {
colour = match_named_colour(teststrp);
if (colour == 8) {
@@ -1645,22 +1661,14 @@ match_colour(const char **teststrp, int is_fg, int colour)
return is_fg ? TXTNOFGCOLOUR : TXTNOBGCOLOUR;
}
}
- else
+ else {
colour = (int)zstrtol(*teststrp, (char **)teststrp, 10);
- }
- if (colour < 0 || colour >= 256)
- return -1;
- if (is_fg) {
- shft = TXT_ATTR_FG_COL_SHIFT;
- on = TXTFGCOLOUR;
- tc = TCFGCOLOUR;
- } else {
- shft = TXT_ATTR_BG_COL_SHIFT;
- on = TXTBGCOLOUR;
- tc = TCBGCOLOUR;
+ if (colour < 0 || colour >= 256)
+ return TXT_ERROR;
+ }
}
/*
- * Try termcap for numbered characters if posible.
+ * Try termcap for numbered characters if possible.
* Don't for named characters, since our best bet
* of getting the names right is with ANSI sequences.
*/
@@ -1671,7 +1679,7 @@ match_colour(const char **teststrp, int is_fg, int colour)
* Can we assume ANSI colours work?
*/
if (colour > 7)
- return -1; /* No. */
+ return TXT_ERROR; /* No. */
} else {
/*
* We can handle termcap colours and the number
@@ -1681,7 +1689,7 @@ match_colour(const char **teststrp, int is_fg, int colour)
TXT_ATTR_BG_TERMCAP;
}
}
- return on | (colour << shft);
+ return on | (zattr)colour << shft;
}
/*
@@ -1691,7 +1699,7 @@ match_colour(const char **teststrp, int is_fg, int colour)
/**/
mod_export void
-match_highlight(const char *teststr, int *on_var)
+match_highlight(const char *teststr, zattr *on_var)
{
int found = 1;
@@ -1701,7 +1709,8 @@ match_highlight(const char *teststr, int *on_var)
found = 0;
if (strpfx("fg=", teststr) || strpfx("bg=", teststr)) {
- int is_fg = (teststr[0] == 'f'), atr;
+ int is_fg = (teststr[0] == 'f');
+ zattr atr;
teststr += 3;
atr = match_colour(&teststr, is_fg, 0);
@@ -1711,7 +1720,7 @@ match_highlight(const char *teststr, int *on_var)
break;
found = 1;
/* skip out of range colours but keep scanning attributes */
- if (atr >= 0)
+ if (atr != TXT_ERROR)
*on_var |= atr;
} else {
for (hl = highlights; hl->name; hl++) {
@@ -1776,7 +1785,7 @@ output_colour(int colour, int fg_bg, int use_tc, char *buf)
/**/
mod_export int
-output_highlight(int atr, char *buf)
+output_highlight(zattr atr, char *buf)
{
const struct highlight *hp;
int atrlen = 0, len;
@@ -1939,7 +1948,8 @@ allocate_colour_buffer(void)
strlen(fg_bg_sequences[COL_SEQ_BG].end);
len = lenfg > lenbg ? lenfg : lenbg;
- colseq_buf = (char *)zalloc(len+1);
+ /* add 1 for the null and 14 for truecolor */
+ colseq_buf = (char *)zalloc(len+15);
}
/* Free the colour buffer previously allocated. */
@@ -1970,21 +1980,23 @@ free_colour_buffer(void)
/**/
mod_export void
-set_colour_attribute(int atr, int fg_bg, int flags)
+set_colour_attribute(zattr atr, int fg_bg, int flags)
{
char *ptr;
int do_free, is_prompt = (flags & TSC_PROMPT) ? 1 : 0;
- int colour, tc, def, use_termcap;
+ int colour, tc, def, use_termcap, use_truecolor;
if (fg_bg == COL_SEQ_FG) {
colour = txtchangeget(atr, TXT_ATTR_FG_COL);
tc = TCFGCOLOUR;
def = txtchangeisset(atr, TXTNOFGCOLOUR);
+ use_truecolor = txtchangeisset(atr, TXT_ATTR_FG_24BIT);
use_termcap = txtchangeisset(atr, TXT_ATTR_FG_TERMCAP);
} else {
colour = txtchangeget(atr, TXT_ATTR_BG_COL);
tc = TCBGCOLOUR;
def = txtchangeisset(atr, TXTNOBGCOLOUR);
+ use_truecolor = txtchangeisset(atr, TXT_ATTR_BG_24BIT);
use_termcap = txtchangeisset(atr, TXT_ATTR_BG_TERMCAP);
}
@@ -1992,12 +2004,13 @@ set_colour_attribute(int atr, int fg_bg, int flags)
* If we're not restoring the default, and either have a
* colour value that is too large for ANSI, or have been told
* to use the termcap sequence, try to use the termcap sequence.
+ * True color is not covered by termcap.
*
* We have already sanitised the values we allow from the
* highlighting variables, so much of this shouldn't be
* necessary at this point, but we might as well be safe.
*/
- if (!def && (colour > 7 || use_termcap)) {
+ if (!def && !use_truecolor && (colour > 7 || use_termcap)) {
/*
* We can if it's available, and either we couldn't get
* the maximum number of colours, or the colour is in range.
@@ -2041,6 +2054,9 @@ set_colour_attribute(int atr, int fg_bg, int flags)
strcpy(ptr, fg_bg_sequences[fg_bg].def);
while (*ptr)
ptr++;
+ } else if (use_truecolor) {
+ ptr += sprintf(ptr, "8;2;%d;%d;%d", colour >> 16,
+ (colour >> 8) & 0xff, colour & 0xff);
} else
*ptr++ = colour + '0';
strcpy(ptr, fg_bg_sequences[fg_bg].end);
diff --git a/Src/zsh.h b/Src/zsh.h
index 68731e226..10897372b 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2633,6 +2633,12 @@ struct ttyinfo {
* Text attributes for displaying in ZLE
*/
+#ifdef HAVE_STDINT_H
+ typedef uint64_t zattr;
+#else
+ typedef zulong zattr;
+#endif
+
#define TXTBOLDFACE 0x0001
#define TXTSTANDOUT 0x0002
#define TXTUNDERLINE 0x0004
@@ -2664,32 +2670,41 @@ struct ttyinfo {
*/
#define TXT_MULTIWORD_MASK 0x0400
+/* used when, e.g an invalid colour is specified */
+#define TXT_ERROR 0x0800
+
/* Mask for colour to use in foreground */
-#define TXT_ATTR_FG_COL_MASK 0x000FF000
+#define TXT_ATTR_FG_COL_MASK 0x000000FFFFFF0000
/* Bits to shift the foreground colour */
-#define TXT_ATTR_FG_COL_SHIFT (12)
+#define TXT_ATTR_FG_COL_SHIFT (16)
/* Mask for colour to use in background */
-#define TXT_ATTR_BG_COL_MASK 0x0FF00000
+#define TXT_ATTR_BG_COL_MASK 0xFFFFFF0000000000
/* Bits to shift the background colour */
-#define TXT_ATTR_BG_COL_SHIFT (20)
+#define TXT_ATTR_BG_COL_SHIFT (40)
/* Flag to use termcap AF sequence to set colour, if available */
-#define TXT_ATTR_FG_TERMCAP 0x10000000
+#define TXT_ATTR_FG_TERMCAP 0x1000
/* Flag to use termcap AB sequence to set colour, if available */
-#define TXT_ATTR_BG_TERMCAP 0x20000000
+#define TXT_ATTR_BG_TERMCAP 0x2000
+
+/* Flag to indicate that foreground is a 24-bit colour */
+#define TXT_ATTR_FG_24BIT 0x4000
+/* Flag to indicate that background is a 24-bit colour */
+#define TXT_ATTR_BG_24BIT 0x8000
/* Things to turn on, including values for the colour elements */
#define TXT_ATTR_ON_VALUES_MASK \
(TXT_ATTR_ON_MASK|TXT_ATTR_FG_COL_MASK|TXT_ATTR_BG_COL_MASK|\
- TXT_ATTR_FG_TERMCAP|TXT_ATTR_BG_TERMCAP)
+ TXT_ATTR_FG_TERMCAP|TXT_ATTR_BG_TERMCAP|\
+ TXT_ATTR_FG_24BIT|TXT_ATTR_BG_24BIT)
/* Mask out everything to do with setting a foreground colour */
#define TXT_ATTR_FG_ON_MASK \
- (TXTFGCOLOUR|TXT_ATTR_FG_COL_MASK|TXT_ATTR_FG_TERMCAP)
+ (TXTFGCOLOUR|TXT_ATTR_FG_COL_MASK|TXT_ATTR_FG_TERMCAP|TXT_ATTR_FG_24BIT)
/* Mask out everything to do with setting a background colour */
#define TXT_ATTR_BG_ON_MASK \
- (TXTBGCOLOUR|TXT_ATTR_BG_COL_MASK|TXT_ATTR_BG_TERMCAP)
+ (TXTBGCOLOUR|TXT_ATTR_BG_COL_MASK|TXT_ATTR_BG_TERMCAP|TXT_ATTR_BG_24BIT)
/* Mask out everything to do with activating colours */
#define TXT_ATTR_COLOUR_ON_MASK \
diff --git a/Src/zsh_system.h b/Src/zsh_system.h
index 8289ee97c..e7d529b6e 100644
--- a/Src/zsh_system.h
+++ b/Src/zsh_system.h
@@ -137,6 +137,10 @@ char *alloca _((size_t));
#include
#endif
+#ifdef HAVE_STDINT_H
+# include
+#endif
+
#include
#include
#include
--
cgit v1.2.3
From 71c9130ede00c6ddf1e72e479178f4c2360f6a9e Mon Sep 17 00:00:00 2001
From: Oliver Kiddle
Date: Thu, 8 Nov 2018 11:01:27 +0100
Subject: unposted: add usual copyright header to nearcolor module sources
---
ChangeLog | 2 ++
Src/Modules/nearcolor.c | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index a2df6fda0..19cc2f5ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2018-11-08 Oliver Kiddle
+ * unposted: Src/Modules/nearcolor.c: add usual copyright header
+
* 43784: Completion/Zsh/Command/_compadd: clarify descriptions on
options related to match sorting
diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
index 128658e20..b51b4fd2c 100644
--- a/Src/Modules/nearcolor.c
+++ b/Src/Modules/nearcolor.c
@@ -1,3 +1,32 @@
+/*
+ * nearcolor.c - map colours to nearest match in 88 or 256 colour palette
+ *
+ * This file is part of zsh, the Z shell.
+ *
+ * Copyright (c) 2018 Oliver Kiddle
+ * All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and to distribute modified versions of this software for any
+ * purpose, provided that the above copyright notice and the following
+ * two paragraphs appear in all copies of this software.
+ *
+ * In no event shall Oliver Kiddle or the Zsh Development Group be liable
+ * to any party for direct, indirect, special, incidental, or consequential
+ * damages arising out of the use of this software and its documentation,
+ * even if Oliver Kiddle and the Zsh Development Group have been advised of
+ * the possibility of such damage.
+ *
+ * Oliver Kiddle and the Zsh Development Group specifically disclaim any
+ * warranties, including, but not limited to, the implied warranties of
+ * merchantability and fitness for a particular purpose. The software
+ * provided hereunder is on an "as is" basis, and Oliver Kiddle and the
+ * Zsh Development Group have no obligation to provide maintenance,
+ * support, updates, enhancements, or modifications.
+ *
+ */
+
#include "nearcolor.mdh"
#include "nearcolor.pro"
--
cgit v1.2.3
From 5a7070178826e7b0db94e0a3d285849315e5c5ab Mon Sep 17 00:00:00 2001
From: Oliver Kiddle
Date: Thu, 8 Nov 2018 11:01:36 +0100
Subject: 43805: make nearcolor module use the default colour rather than black
as a fallback
---
ChangeLog | 3 +++
Src/Modules/nearcolor.c | 7 ++++---
Src/prompt.c | 4 +++-
3 files changed, 10 insertions(+), 4 deletions(-)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index 636ea4dd7..41a2f7aa9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2018-11-08 Oliver Kiddle
+ * 43805: Src/Modules/nearcolor.c, Src/prompt.c: make nearcolor
+ module use the default colour rather than black as a fallback
+
* 43804: Src/prompt.c: also need to be able to turn colour
attributes back into hex triples for region_highlight variable
diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
index b51b4fd2c..0b9877bf4 100644
--- a/Src/Modules/nearcolor.c
+++ b/Src/Modules/nearcolor.c
@@ -146,13 +146,14 @@ mapRGBto256(int red, int green, int blue)
static int
getnearestcolor(UNUSED(Hookdef dummy), Color_rgb col)
{
+ /* we add 1 to the colours so that colour 0 (black) is
+ * distinguished from runhookdef() indicating that no
+ * hook function is registered */
if (tccolours == 256)
return mapRGBto256(col->red, col->green, col->blue) + 1;
if (tccolours == 88)
return mapRGBto88(col->red, col->green, col->blue) + 1;
- /* returning 1 indicates black rather than failure (0) so this
- * module still serves to prevent fallback on true color */
- return 1;
+ return -1;
}
static struct features module_features = {
diff --git a/Src/prompt.c b/Src/prompt.c
index 377015ad8..568bfc2a9 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1650,10 +1650,12 @@ match_colour(const char **teststrp, int is_fg, int colour)
return TXT_ERROR;
*teststrp = end;
colour = runhookdef(GETCOLORATTR, &color) - 1;
- if (colour < 0) { /* no hook function added, try true color (24-bit) */
+ if (colour == -1) { /* no hook function added, try true color (24-bit) */
colour = (((color.red << 8) + color.green) << 8) + color.blue;
return on | (is_fg ? TXT_ATTR_FG_24BIT : TXT_ATTR_BG_24BIT) |
(zattr)colour << shft;
+ } else if (colour <= -2) {
+ return TXT_ERROR;
}
} else if ((named = ialpha(**teststrp))) {
colour = match_named_colour(teststrp);
--
cgit v1.2.3
From a8cc017c74a916b690dc074c299faf4bd24b5af4 Mon Sep 17 00:00:00 2001
From: Kamil Dudka
Date: Wed, 7 Nov 2018 14:04:52 +0100
Subject: 43791: File descriptor could be closed twice in clone
---
ChangeLog | 4 ++++
Src/Modules/clone.c | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index 72a74849e..97751c16e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-11-09 Peter Stephenson
+
+ * 43791: Kamil: Src/Modules/clone.c: file descriptor was closed twice.
+
2018-11-08 Oliver Kiddle
* 43779 (tweaked): Joey Pabalinas: Functions/Zle/select-bracketed:
diff --git a/Src/Modules/clone.c b/Src/Modules/clone.c
index ef6275dcf..4b2655505 100644
--- a/Src/Modules/clone.c
+++ b/Src/Modules/clone.c
@@ -96,7 +96,8 @@ bin_clone(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
init_io(NULL);
setsparam("TTY", ztrdup(ttystrname));
}
- close(ttyfd);
+ else
+ close(ttyfd);
if (pid < 0) {
zerrnam(nam, "fork failed: %e", errno);
return 1;
--
cgit v1.2.3
From 5ad76492af8931added1ae9600309d915d1427a5 Mon Sep 17 00:00:00 2001
From: dana
Date: Tue, 13 Nov 2018 13:01:01 -0600
Subject: 43800: Add nanosecond support to strftime built-in
---
ChangeLog | 5 ++++
Doc/Zsh/mod_datetime.yo | 8 +++++--
Src/Modules/datetime.c | 64 +++++++++++++++++++++++++++++++++++--------------
Test/V09datetime.ztst | 29 ++++++++++++++++++++++
4 files changed, 86 insertions(+), 20 deletions(-)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index 7e69c5841..4cba03c71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-13 dana
+
+ * 43800: Doc/Zsh/mod_datetime.yo, Src/Modules/datetime.c,
+ Test/V09datetime.ztst: Add nanosecond support to strftime built-in
+
2018-11-12 Oliver Kiddle
* 43819: Completion/Unix/Command/_adb: expand adb completion to
diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo
index 27bc78157..da65a9bbd 100644
--- a/Doc/Zsh/mod_datetime.yo
+++ b/Doc/Zsh/mod_datetime.yo
@@ -6,9 +6,13 @@ The tt(zsh/datetime) module makes available one builtin command:
startitem()
findex(strftime)
cindex(date string, printing)
-xitem(tt(strftime) [ tt(-s) var(scalar) ] var(format) var(epochtime) )
+xitem(tt(strftime) [ tt(-s) var(scalar) ] var(format) [ var(epochtime) [ var(nanoseconds) ] ] )
item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) ] var(format) var(timestring) )(
-Output the date denoted by var(epochtime) in the var(format) specified.
+Output the date in the var(format) specified. With no var(epochtime), the
+current system date/time is used; optionally, var(epochtime) may be used to
+specify the number of seconds since the epoch, and var(nanoseconds) may
+additionally be used to specify the number of nanoseconds past the second
+(otherwise that number is assumed to be 0).
See manref(strftime)(3) for details. The zsh extensions described in
ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\
ifnzman(noderef(Prompt Expansion)) are also available.
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index be378b347..18c7fb58e 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -100,8 +100,8 @@ output_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
{
int bufsize, x, len;
char *endptr = NULL, *scalar = NULL, *buffer;
- time_t secs;
- struct tm *t;
+ struct tm *tm;
+ struct timespec ts;
if (OPT_ISSET(ops,'s')) {
scalar = OPT_ARG(ops, 's');
@@ -110,30 +110,58 @@ output_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
return 1;
}
}
- if (OPT_ISSET(ops, 'r'))
+ if (OPT_ISSET(ops, 'r')) {
+ if (!argv[1]) {
+ zwarnnam(nam, "timestring expected");
+ return 1;
+ }
return reverse_strftime(nam, argv, scalar, OPT_ISSET(ops, 'q'));
-
- errno = 0;
- secs = (time_t)strtoul(argv[1], &endptr, 10);
- if (errno != 0) {
- zwarnnam(nam, "%s: %e", argv[1], errno);
- return 1;
- } else if (*endptr != '\0') {
- zwarnnam(nam, "%s: invalid decimal number", argv[1]);
- return 1;
}
- t = localtime(&secs);
- if (!t) {
- zwarnnam(nam, "%s: unable to convert to time", argv[1]);
- return 1;
+ if (!argv[1]) {
+ zgettime(&ts);
+ tm = localtime(&ts.tv_sec);
+ } else {
+ errno = 0;
+
+ ts.tv_sec = (time_t)strtoul(argv[1], &endptr, 10);
+ if (errno != 0) {
+ zwarnnam(nam, "%s: %e", argv[1], errno);
+ return 1;
+ } else if (*argv[1] == '\0' || *endptr != '\0') {
+ zwarnnam(nam, "%s: invalid decimal number", argv[1]);
+ return 1;
+ }
+
+ tm = localtime(&ts.tv_sec);
+ if (!tm) {
+ zwarnnam(nam, "%s: unable to convert to time", argv[1]);
+ return 1;
+ }
+
+ ts.tv_nsec = 0L;
+ if (argv[2]) {
+ ts.tv_nsec = (long)zstrtol(argv[2], &endptr, 10);
+ if (errno != 0) {
+ zwarnnam(nam, "%s: %e", argv[2], errno);
+ return 1;
+ } else if (*argv[2] == '\0' || *endptr != '\0') {
+ zwarnnam(nam, "%s: invalid decimal number", argv[2]);
+ return 1;
+ } else if (ts.tv_nsec < 0) {
+ zwarnnam(nam, "%s: invalid nanosecond value", argv[2]);
+ return 1;
+ }
+ }
}
+
bufsize = strlen(argv[0]) * 8;
buffer = zalloc(bufsize);
len = 0;
for (x=0; x < 4; x++) {
- if ((len = ztrftime(buffer, bufsize, argv[0], t, 0L)) >= 0 || x==3)
+ if ((len = ztrftime(buffer, bufsize, argv[0], tm, ts.tv_nsec)) >= 0 ||
+ x==3)
break;
buffer = zrealloc(buffer, bufsize *= 2);
}
@@ -207,7 +235,7 @@ getcurrenttime(UNUSED(Param pm))
}
static struct builtin bintab[] = {
- BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, "qrs:", NULL),
+ BUILTIN("strftime", 0, bin_strftime, 1, 3, 0, "qrs:", NULL),
};
static const struct gsu_integer epochseconds_gsu =
diff --git a/Test/V09datetime.ztst b/Test/V09datetime.ztst
index ffad96c04..22d560750 100644
--- a/Test/V09datetime.ztst
+++ b/Test/V09datetime.ztst
@@ -82,3 +82,32 @@
# The result can be '%@' (Linux), '@' (BSDs) or an error (Cygwin).
[[ $(strftime '%@' 0 2> /dev/null) == (%|)@ || $? != 0 ]]
0:bad format specifier
+
+# This test may fail at 23:59:59.xxx on New Year's Eve :/
+ [[ "$( strftime '%Y' )" == "$( strftime '%Y' "$EPOCHSECONDS" )" ]]
+0:epochtime optional
+
+ strftime '%Y-%m-%d %H:%M:%S.%3.' 1012615322
+ strftime '%Y-%m-%d %H:%M:%S.%3.' 1012615322 0
+ strftime '%Y-%m-%d %H:%M:%S.%3.' 1012615322 2
+ strftime '%Y-%m-%d %H:%M:%S.%3.' 1012615322 $(( 222 * (10 ** 9) ))
+0:optional nanoseconds
+>2002-02-02 02:02:02.000
+>2002-02-02 02:02:02.000
+>2002-02-02 02:02:02.000
+>2002-02-02 02:02:02.222
+
+ strftime '%Y' '' 2> /dev/null
+1:empty epochtime not allowed
+
+ strftime '%Y' 1012615322 '' 2> /dev/null
+1:empty nanoseconds not allowed
+
+ strftime '%N' 1012615322 ${(l<64><9>):-} 2> /dev/null
+1:overflowed nanoseconds not allowed
+
+ strftime '%N' 1012615322 -1 2> /dev/null
+1:negative nanoseconds not allowed
+
+ strftime -r '%Y' 2> /dev/null
+1:-r timestring not optional
--
cgit v1.2.3
From e258e7d251b7403a6d77b23e6927b659bf9c2c37 Mon Sep 17 00:00:00 2001
From: Ivan Tkachenko
Date: Thu, 15 Nov 2018 10:59:09 +0900
Subject: 43823: remove unnecessary metafy() in stattimeprint()
---
ChangeLog | 5 +++++
Src/Modules/stat.c | 4 +---
2 files changed, 6 insertions(+), 3 deletions(-)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index d07a9dff3..9a6a1540e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-15 Jun-ichi Takimoto
+
+ * Ivan Tkachenko: 43823: Src/Modules/stat.c: remove unnecessary
+ metafy() in stattimeprint()
+
2018-11-14 Peter Stephenson
* 43620: Doc/Zsh/expn.yo: more care documenting command
diff --git a/Src/Modules/stat.c b/Src/Modules/stat.c
index 50a6a9bb2..7c736072b 100644
--- a/Src/Modules/stat.c
+++ b/Src/Modules/stat.c
@@ -198,10 +198,8 @@ stattimeprint(time_t tim, long nsecs, char *outbuf, int flags)
if (flags & STF_STRING) {
char *oend = outbuf + strlen(outbuf);
/* Where the heck does "40" come from? */
- int len = ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
+ ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
localtime(&tim), nsecs);
- if (len > 0)
- metafy(oend, len, META_NOALLOC);
if (flags & STF_RAW)
strcat(oend, ")");
}
--
cgit v1.2.3
From 8d0f7681a05c4c49a22cb67b585f54e6f2e29931 Mon Sep 17 00:00:00 2001
From: Jun-ichi Takimoto
Date: Mon, 19 Nov 2018 14:57:30 +0900
Subject: 43829: nearcolor.c: use double instead of float
---
ChangeLog | 4 ++++
Src/Modules/nearcolor.c | 38 +++++++++++++++++++-------------------
2 files changed, 23 insertions(+), 19 deletions(-)
(limited to 'Src/Modules')
diff --git a/ChangeLog b/ChangeLog
index de265986a..ced545aaf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-11-19 Jun-ichi Takimoto
+
+ * 43829: Src/Modules/nearcolor.c: use double instead of float
+
2018-11-16 dana
* Daniel O'Connor: 43830: Completion/BSD/Command/_cu: Complete
diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
index 0b9877bf4..b49ee9afb 100644
--- a/Src/Modules/nearcolor.c
+++ b/Src/Modules/nearcolor.c
@@ -33,37 +33,37 @@
#include
struct cielab {
- float L, a, b;
+ double L, a, b;
};
typedef struct cielab *Cielab;
-static float
+static double
deltae(Cielab lab1, Cielab lab2)
{
/* taking square root unnecessary as we're just comparing values */
- return powf(lab1->L - lab2->L, 2) +
- powf(lab1->a - lab2->a, 2) +
- powf(lab1->b - lab2->b, 2);
+ return pow(lab1->L - lab2->L, 2) +
+ pow(lab1->a - lab2->a, 2) +
+ pow(lab1->b - lab2->b, 2);
}
static void
RGBtoLAB(int red, int green, int blue, Cielab lab)
{
- float R = (float)red / 255.0;
- float G = (float)green / 255.0;
- float B = (float)blue / 255.0;
- R = 100.0 * (R > 0.04045 ? powf((R + 0.055) / 1.055, 2.4) : R / 12.92);
- G = 100.0 * (G > 0.04045 ? powf((G + 0.055) / 1.055, 2.4) : G / 12.92);
- B = 100.0 * (B > 0.04045 ? powf((B + 0.055) / 1.055, 2.4) : B / 12.92);
+ double R = red / 255.0;
+ double G = green / 255.0;
+ double B = blue / 255.0;
+ R = 100.0 * (R > 0.04045 ? pow((R + 0.055) / 1.055, 2.4) : R / 12.92);
+ G = 100.0 * (G > 0.04045 ? pow((G + 0.055) / 1.055, 2.4) : G / 12.92);
+ B = 100.0 * (B > 0.04045 ? pow((B + 0.055) / 1.055, 2.4) : B / 12.92);
/* Observer. = 2 degrees, Illuminant = D65 */
- float X = (R * 0.4124 + G * 0.3576 + B * 0.1805) / 95.047;
- float Y = (R * 0.2126 + G * 0.7152 + B * 0.0722) / 100.0;
- float Z = (R * 0.0193 + G * 0.1192 + B * 0.9505) / 108.883;
+ double X = (R * 0.4124 + G * 0.3576 + B * 0.1805) / 95.047;
+ double Y = (R * 0.2126 + G * 0.7152 + B * 0.0722) / 100.0;
+ double Z = (R * 0.0193 + G * 0.1192 + B * 0.9505) / 108.883;
- X = (X > 0.008856) ? powf(X, 1.0/3.0) : (7.787 * X) + (16.0 / 116.0);
- Y = (Y > 0.008856) ? powf(Y, 1.0/3.0) : (7.787 * Y) + (16.0 / 116.0);
- Z = (Z > 0.008856) ? powf(Z, 1.0/3.0) : (7.787 * Z) + (16.0 / 116.0);
+ X = (X > 0.008856) ? pow(X, 1.0/3.0) : (7.787 * X) + (16.0 / 116.0);
+ Y = (Y > 0.008856) ? pow(Y, 1.0/3.0) : (7.787 * Y) + (16.0 / 116.0);
+ Z = (Z > 0.008856) ? pow(Z, 1.0/3.0) : (7.787 * Z) + (16.0 / 116.0);
lab->L = (116.0 * Y) - 16.0;
lab->a = 500.0 * (X - Y);
@@ -75,7 +75,7 @@ mapRGBto88(int red, int green, int blue)
{
int component[] = { 0, 0x8b, 0xcd, 0xff, 0x2e, 0x5c, 0x8b, 0xa2, 0xb9, 0xd0, 0xe7 };
struct cielab orig, next;
- float nextl, bestl = -1;
+ double nextl, bestl = -1;
int r, g, b;
int comp_r = 0, comp_g = 0, comp_b = 0;
@@ -116,7 +116,7 @@ mapRGBto256(int red, int green, int blue)
0xa8, 0xb2, 0xbc, 0xc6, 0xd0, 0xda, 0xe4, 0xee
};
struct cielab orig, next;
- float nextl, bestl = -1;
+ double nextl, bestl = -1;
int r, g, b;
int comp_r = 0, comp_g = 0, comp_b = 0;
--
cgit v1.2.3