Comparison

util/stanza.lua @ 11642:7f2dee4249aa

util.stanza: Export pretty printing function
author Kim Alvefur <zash@zash.se>
date Tue, 29 Jun 2021 16:06:54 +0200
parent 11640:51598e46e136
child 11786:39164ea2ab9e
comparison
equal deleted inserted replaced
11641:b03053ec6dcf 11642:7f2dee4249aa
486 486
487 local function presence(attr) 487 local function presence(attr)
488 return new_stanza("presence", attr); 488 return new_stanza("presence", attr);
489 end 489 end
490 490
491 local pretty;
491 if do_pretty_printing then 492 if do_pretty_printing then
492 local getstyle, getstring = termcolours.getstyle, termcolours.getstring; 493 local getstyle, getstring = termcolours.getstyle, termcolours.getstring;
493 494
494 local blue1 = getstyle("1b3967"); 495 local blue1 = getstyle("1b3967");
495 local blue2 = getstyle("13b5ea"); 496 local blue2 = getstyle("13b5ea");
510 getstring(green1, "%1") .. -- & 511 getstring(green1, "%1") .. -- &
511 getstring(green2, "%2") .. -- amp 512 getstring(green2, "%2") .. -- amp
512 getstring(green1, "%3") -- ; 513 getstring(green1, "%3") -- ;
513 ); 514 );
514 515
515 local function pretty(s) 516 function pretty(s)
516 -- Tag soup color 517 -- Tag soup color
517 -- Outer gsub call takes each <tag>, applies colour to the brackets, the 518 -- Outer gsub call takes each <tag>, applies colour to the brackets, the
518 -- tag name, then applies one inner gsub call to colour the attributes and 519 -- tag name, then applies one inner gsub call to colour the attributes and
519 -- another for any text content. 520 -- another for any text content.
520 return (s:gsub("(</?)([^ >]*)(.-)([?/]?>)([^<]*)", function(opening_bracket, tag_name, attrs, closing_bracket, content) 521 return (s:gsub("(</?)([^ >]*)(.-)([?/]?>)([^<]*)", function(opening_bracket, tag_name, attrs, closing_bracket, content)
579 iq = iq; 580 iq = iq;
580 reply = reply; 581 reply = reply;
581 error_reply = error_reply; 582 error_reply = error_reply;
582 presence = presence; 583 presence = presence;
583 xml_escape = xml_escape; 584 xml_escape = xml_escape;
585 pretty_print = pretty;
584 }; 586 };