swish/commit

Updated upstream files

authorJan Wielemaker
Fri Dec 23 14:45:01 2016 +0100
committerJan Wielemaker
Fri Dec 23 14:45:01 2016 +0100
commit22cebc58d0a51eb68496895545b0ad8a9e4b7195
tree818b72b012f2f7749227b521daa61170fe6226f4
parentd7b79e94a0600a9868d7134474d50b3d07dd9fa7
Diff style: patch stat
diff --git a/lib/swish/highlight.pl b/lib/swish/highlight.pl
index 778a185..4fcbe68 100644
--- a/lib/swish/highlight.pl
+++ b/lib/swish/highlight.pl
@@ -826,7 +826,8 @@ style(dcg(plain),	 brace_term_open-brace_term_close, []).
 style(brace_term,	 brace_term_open-brace_term_close, []).
 style(dict_content,	 dict_open-dict_close,             []).
 style(expanded,		 expanded,			   [text]).
-style(comment_string,	 comment_string,		   []).
+style(comment_string,	 comment_string,		   []). % up to 7.3.33
+style(comment(string),	 comment_string,		   []). % after 7.3.33
 style(ext_quant,	 ext_quant,			   []).
 style(unused_import,	 unused_import,			   [text]).
 style(undefined_import,	 undefined_import,		   [text]).
@@ -942,16 +943,44 @@ highlight_style(StyleName, Style) :-
 css_style(bold(true),      'font-weight'(bold)) :- !.
 css_style(underline(true), 'text-decoration'(underline)) :- !.
 css_style(colour(Name), color(RGB)) :-
-	current_prolog_flag(gui, true), !,
-	get(colour(Name), red,   R0),
-	get(colour(Name), green, G0),
-	get(colour(Name), blue,  B0),
-	R is R0//256,
-	G is G0//256,
-	B is B0//256,
+	x11_color(Name, R, G, B),
 	format(atom(RGB), '#~|~`0t~16r~2+~`0t~16r~2+~`0t~16r~2+', [R,G,B]).
 css_style(Style, Style).
 
+%%	x11_color(+Name, -R, -G, -B)
+%
+%	True if RGB is the color for the named X11 color.
+
+x11_color(Name, R, G, B) :-
+	(   x11_color_cache(_,_,_,_)
+	->  true
+	;   load_x11_colours
+	),
+	x11_color_cache(Name, R, G, B).
+
+:- dynamic
+	x11_color_cache/4.
+
+load_x11_colours :-
+	source_file(load_x11_colours, File),
+	file_directory_name(File, Dir),
+	directory_file_path(Dir, 'rgb.txt', RgbFile),
+	setup_call_cleanup(
+	    open(RgbFile, read, In),
+	    ( lazy_list(lazy_read_lines(In, [as(string)]), List),
+	      maplist(assert_colour, List)
+	    ),
+	    close(In)).
+
+assert_colour(String) :-
+	split_string(String, "\s\t\r", "\s\t\r", [RS,GS,BS|NameParts]),
+	number_string(R, RS),
+	number_string(G, GS),
+	number_string(B, BS),
+	atomic_list_concat(NameParts, '_', Name0),
+	downcase_atom(Name0, Name),
+	assertz(x11_color_cache(Name, R, G, B)).
+
 %%	css(?Context, ?Selector, -Style) is nondet.
 %
 %	Multifile hook to define additional style to apply in a specific
diff --git a/lib/swish/swish_csv.pl b/lib/swish/swish_csv.pl
index ecb0830..5b5eaa4 100644
--- a/lib/swish/swish_csv.pl
+++ b/lib/swish/swish_csv.pl
@@ -89,6 +89,9 @@ csv(output(_Id, message(_Term, _Class, HTML, _Where)), _VarNames, _Opts) :- !,
 	format('<html>~n~s~n</html>~n', [HTML]).
 csv(page(Page, Event), VarNames, Options) :-
 	csv(Event, VarNames, [page(Page)|Options]).
+csv(failure(_Id, _Time), VarNames, Options) :- !,
+	VarTerm =.. [row|VarNames],
+	success([], VarTerm, [more(false)|Options]).
 csv(Event, _VarNames, _) :-
 	print_term(Event, [output(user_error)]).