perl-curses.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. Index: CHANGES.RSE
  2. ===================================================================
  3. RCS file: CHANGES.RSE
  4. diff -N CHANGES.RSE
  5. --- /dev/null 1 Jan 1970 00:00:00 -0000
  6. +++ CHANGES.RSE 16 Oct 2003 17:52:29 -0000 1.8
  7. @@ -0,0 +1,25 @@
  8. +
  9. + The following changes were made by Ralf S. Engelschall <rse@engelschall.com>
  10. + to the excellent Curses::UI by Maurice Makaay <maurice@gitaar.net>.
  11. +
  12. + o Make sure that Curses::UI::Listbox draws the selected values in bold
  13. + also under "multi" and "radio" options to be consistent in look &
  14. + feel with the standard list box.
  15. +
  16. + o Add support for root->overlapping(1) (default) and
  17. + root->overlapping(0) to optimize the redrawing by reducing to
  18. + the old and new focused widgets. The default is still to redraw
  19. + everything which is necessary to support overlapping windows.
  20. +
  21. + o Add -reverse option to Curses::UI::TextEditor.
  22. +
  23. + o Fix reverse rendering for Label demo in demo-widgets.
  24. +
  25. + o Add -htmltext option to Curses::UI::Widget, corresponding
  26. + text_chop(), text_length() and text_draw() functions to
  27. + Curses::UI::Common and used the stuff in Curses::UI::Listbox
  28. + to allow in-line markup.
  29. +
  30. + o Fix top-level DESTROY (destructor) function to correctly
  31. + shutdown Curses and allow re-initializations.
  32. +
  33. Index: lib/Curses/UI.pm
  34. ===================================================================
  35. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI.pm,v
  36. retrieving revision 1.1.1.7
  37. retrieving revision 1.11
  38. diff -u -d -u -d -r1.1.1.7 -r1.11
  39. --- lib/Curses/UI.pm 16 Oct 2003 17:51:37 -0000 1.1.1.7
  40. +++ lib/Curses/UI.pm 16 Oct 2003 17:52:30 -0000 1.11
  41. @@ -70,6 +70,7 @@
  42. -debug => undef, # Turn on debugging mode?
  43. -language => undef, # Which language to use?
  44. -mouse_support => 1, # Do we want mouse support
  45. + -overlapping => 1, # Whether overlapping widgets are supported
  46. -color_support => 0,
  47. -default_colors=> 1,
  48. #user data
  49. @@ -114,8 +115,11 @@
  50. DESTROY
  51. {
  52. my $this = shift;
  53. + my $scr = $this->{-canvasscr};
  54. + $scr->delwin() if (defined($scr));
  55. endwin();
  56. $Curses::UI::rootobject = undef;
  57. + $Curses::UI::initialized = 0;
  58. if ($this->{-clear_on_exit})
  59. {
  60. @@ -135,6 +139,7 @@
  61. sub clear_on_exit(;$) { shift()->accessor('-clear_on_exit', shift()) }
  62. sub cursor_mode(;$) { shift()->accessor('-cursor_mode', shift()) }
  63. sub lang(;$) { shift()->accessor('-language_object', shift()) }
  64. +sub overlapping(;$) { shift()->accessor('-overlapping', shift()) }
  65. # TODO: document
  66. sub debug(;$)
  67. Index: lib/Curses/UI/Common.pm
  68. ===================================================================
  69. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Common.pm,v
  70. retrieving revision 1.1.1.3
  71. retrieving revision 1.3
  72. diff -u -d -u -d -r1.1.1.3 -r1.3
  73. --- lib/Curses/UI/Common.pm 9 Oct 2003 18:09:43 -0000 1.1.1.3
  74. +++ lib/Curses/UI/Common.pm 9 Oct 2003 18:10:02 -0000 1.3
  75. @@ -35,6 +35,9 @@
  76. @EXPORT = qw(
  77. keys_to_lowercase
  78. text_wrap
  79. + text_draw
  80. + text_length
  81. + text_chop
  82. scrlength
  83. split_to_lines
  84. text_dimension
  85. @@ -213,6 +216,125 @@
  86. }
  87. return \@wrapped;
  88. +}
  89. +
  90. +sub text_tokenize {
  91. + my ($text) = @_;
  92. +
  93. + my @tokens = ();
  94. + while ($text ne '') {
  95. + if ($text =~ m/^<\/?[a-zA-Z0-9_]+>/s) {
  96. + push(@tokens, $&);
  97. + $text = $';
  98. + }
  99. + elsif ($text =~ m/^.+?(?=<\/?[a-zA-Z0-9_]+>)/s) {
  100. + push(@tokens, $&);
  101. + $text = $';
  102. + }
  103. + else {
  104. + push(@tokens, $text);
  105. + last;
  106. + }
  107. + }
  108. + return @tokens;
  109. +}
  110. +
  111. +sub text_draw($$;)
  112. +{
  113. + my $this = shift;
  114. + my ($y, $x, $text) = @_;
  115. +
  116. + if ($this->{-htmltext}) {
  117. + my @tokens = &text_tokenize($text);
  118. + foreach my $token (@tokens) {
  119. + if ($token =~ m/^<(standout|reverse|bold|underline|blink|dim)>$/s) {
  120. + my $type = $1;
  121. + if ($type eq 'standout') { $this->{-canvasscr}->attron(A_STANDOUT); }
  122. + elsif ($type eq 'reverse') { $this->{-canvasscr}->attron(A_REVERSE); }
  123. + elsif ($type eq 'bold') { $this->{-canvasscr}->attron(A_BOLD); }
  124. + elsif ($type eq 'underline') { $this->{-canvasscr}->attron(A_UNDERLINE); }
  125. + elsif ($type eq 'blink') { $this->{-canvasscr}->attron(A_BLINK); }
  126. + elsif ($type eq 'dim') { $this->{-canvasscr}->attron(A_DIM); }
  127. + }
  128. + elsif ($token =~ m/^<\/(standout|reverse|bold|underline|blink|dim)>$/s) {
  129. + my $type = $1;
  130. + if ($type eq 'standout') { $this->{-canvasscr}->attroff(A_STANDOUT); }
  131. + elsif ($type eq 'reverse') { $this->{-canvasscr}->attroff(A_REVERSE); }
  132. + elsif ($type eq 'bold') { $this->{-canvasscr}->attroff(A_BOLD); }
  133. + elsif ($type eq 'underline') { $this->{-canvasscr}->attroff(A_UNDERLINE); }
  134. + elsif ($type eq 'blink') { $this->{-canvasscr}->attroff(A_BLINK); }
  135. + elsif ($type eq 'dim') { $this->{-canvasscr}->attroff(A_DIM); }
  136. + }
  137. + else {
  138. + $this->{-canvasscr}->addstr($y, $x, $token);
  139. + $x += length($token);
  140. + }
  141. + }
  142. + }
  143. + else {
  144. + $this->{-canvasscr}->addstr($y, $x, $text);
  145. + }
  146. +}
  147. +
  148. +sub text_length {
  149. + my $this = shift;
  150. + my ($text) = @_;
  151. +
  152. + my $length = 0;
  153. + if ($this->{-htmltext}) {
  154. + my @tokens = &text_tokenize($text);
  155. + foreach my $token (@tokens) {
  156. + if ($token !~ m/^<\/?(reverse|bold|underline|blink|dim)>$/s) {
  157. + $length += length($token);
  158. + }
  159. + }
  160. + }
  161. + else {
  162. + $length = length($text);
  163. + }
  164. + return $length;
  165. +}
  166. +
  167. +sub text_chop {
  168. + my $this = shift;
  169. + my ($text, $max_length) = @_;
  170. +
  171. + if ($this->{-htmltext}) {
  172. + my @open = ();
  173. + my @tokens = &text_tokenize($text);
  174. + my $length = 0;
  175. + $text = '';
  176. + foreach my $token (@tokens) {
  177. + if ($token =~ m/^<(\/?)(reverse|bold|underline|blink|dim)>/s) {
  178. + my ($type, $name) = ($1, $2);
  179. + if (defined($type) and $type eq '/') {
  180. + pop(@open);
  181. + }
  182. + else {
  183. + push(@open, $name);
  184. + }
  185. + $text .= $token;
  186. + }
  187. + else {
  188. + $text .= $token;
  189. + $length += length($token);
  190. + if ($length > $max_length) {
  191. + $text = substr($text, 0, $max_length);
  192. + $text =~ s/.$/\$/;
  193. + while (defined($token = pop(@open))) {
  194. + $text .= "</$token>";
  195. + }
  196. + last;
  197. + }
  198. + }
  199. + }
  200. + }
  201. + else {
  202. + if (length($text) > $max_length) {
  203. + $text = substr($text, 0, $max_length);
  204. + }
  205. + }
  206. + return $text;
  207. }
  208. sub text_dimension ($;)
  209. Index: lib/Curses/UI/Label.pm
  210. ===================================================================
  211. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Label.pm,v
  212. retrieving revision 1.1.1.4
  213. retrieving revision 1.6
  214. diff -u -d -u -d -r1.1.1.4 -r1.6
  215. Index: lib/Curses/UI/Listbox.pm
  216. ===================================================================
  217. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Listbox.pm,v
  218. retrieving revision 1.1.1.5
  219. retrieving revision 1.7
  220. diff -u -d -u -d -r1.1.1.5 -r1.7
  221. --- lib/Curses/UI/Listbox.pm 9 Oct 2003 18:09:41 -0000 1.1.1.5
  222. +++ lib/Curses/UI/Listbox.pm 9 Oct 2003 18:10:02 -0000 1.7
  223. @@ -303,10 +303,7 @@
  224. (($this->{-multi} or $this->{-radio}) ? 4 : 0);
  225. # Chop length if needed.
  226. - if (($prefix_len + length($label)) > $this->canvaswidth) {
  227. - $label = substr($label, 0, ($this->canvaswidth-$prefix_len));
  228. - $label =~ s/.$/\$/;
  229. - }
  230. + $label = $this->text_chop($label, ($this->canvaswidth-$prefix_len));
  231. # Show current entry in reverse mode and
  232. # save cursor position.
  233. @@ -318,10 +315,12 @@
  234. }
  235. # Show selected element bold.
  236. - if (not $this->{-multi} and
  237. - not $this->{-radio} and
  238. - defined $this->{-selected} and
  239. - $this->{-selected} == $i) {
  240. + if ( ( not $this->{-multi}
  241. + and defined $this->{-selected}
  242. + and $this->{-selected} == $i)
  243. + or ( $this->{-multi}
  244. + and defined $this->{-selected}
  245. + and $this->{-selected}->{$i}) ) {
  246. $this->{-canvasscr}->attron(A_BOLD);
  247. }
  248. @@ -332,10 +331,7 @@
  249. );
  250. # Show label
  251. - $this->{-canvasscr}->addstr(
  252. - $y, $prefix_len,
  253. - $label
  254. - );
  255. + $this->text_draw($y, $prefix_len, $label);
  256. $this->{-canvasscr}->attroff(A_REVERSE);
  257. $this->{-canvasscr}->attroff(A_BOLD);
  258. Index: lib/Curses/UI/TextEditor.pm
  259. ===================================================================
  260. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/TextEditor.pm,v
  261. retrieving revision 1.1.1.6
  262. retrieving revision 1.7
  263. diff -u -d -u -d -r1.1.1.6 -r1.7
  264. --- lib/Curses/UI/TextEditor.pm 16 Oct 2003 17:51:38 -0000 1.1.1.6
  265. +++ lib/Curses/UI/TextEditor.pm 16 Oct 2003 17:51:55 -0000 1.7
  266. @@ -151,6 +151,7 @@
  267. -vscrollbar => 0, # show vertical scrollbar
  268. -hscrollbar => 0, # show horizontal scrollbar
  269. -readonly => 0, # only used as viewer?
  270. + -reverse => 0, # show in reverse
  271. # Single line options
  272. -password => undef, # masquerade chars with given char
  273. @@ -456,9 +457,10 @@
  274. # Turn on underlines and fill the screen with lines
  275. # if neccessary.
  276. - if ($this->{-showlines})
  277. + if ($this->{-showlines} or $this->{-reverse})
  278. {
  279. - $this->{-canvasscr}->attron(A_UNDERLINE);
  280. + $this->{-canvasscr}->attron(A_UNDERLINE) if ($this->{-showlines});;
  281. + $this->{-canvasscr}->attron(A_REVERSE) if ($this->{-reverse});
  282. for my $y (0..$this->canvasheight-1) {
  283. $this->{-canvasscr}->addstr($y, 0, " "x($this->canvaswidth));
  284. }
  285. @@ -480,9 +482,11 @@
  286. if (defined $this->{-search_highlight}
  287. and $this->{-search_highlight} == ($id+$this->{-yscrpos})) {
  288. - $this->{-canvasscr}->attron(A_REVERSE);
  289. + $this->{-canvasscr}->attron(A_REVERSE) if (not $this->{-reverse});
  290. + $this->{-canvasscr}->attroff(A_REVERSE) if ($this->{-reverse});
  291. } else {
  292. - $this->{-canvasscr}->attroff(A_REVERSE);
  293. + $this->{-canvasscr}->attroff(A_REVERSE) if (not $this->{-reverse});
  294. + $this->{-canvasscr}->attron(A_REVERSE) if ($this->{-reverse});
  295. }
  296. my $l = $this->{-scr_lines}->[$id + $this->{-yscrpos}];
  297. @@ -576,6 +580,7 @@
  298. }
  299. $this->{-canvasscr}->attroff(A_UNDERLINE) if $this->{-showlines};
  300. + $this->{-canvasscr}->attroff(A_REVERSE) if $this->{-reverse};
  301. $this->{-canvasscr}->noutrefresh();
  302. doupdate() unless $no_doupdate;
  303. return $this;
  304. Index: lib/Curses/UI/Widget.pm
  305. ===================================================================
  306. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Widget.pm,v
  307. retrieving revision 1.1.1.6
  308. retrieving revision 1.9
  309. diff -u -d -u -d -r1.1.1.6 -r1.9
  310. --- lib/Curses/UI/Widget.pm 16 Oct 2003 17:51:38 -0000 1.1.1.6
  311. +++ lib/Curses/UI/Widget.pm 16 Oct 2003 17:52:30 -0000 1.9
  312. @@ -85,6 +85,7 @@
  313. -onblur => undef, # onBlur event handler
  314. -intellidraw => 1, # Support intellidraw()?
  315. -focusable => 1, # This widget can get focus
  316. + -htmltext => 1, # Recognize HTML tags in drawn text
  317. #user data
  318. -userdata => undef, #user internal data
  319. @@ -482,7 +483,7 @@
  320. my $parent = $this->parent;
  321. $parent->focus($this) if defined $parent;
  322. - $this->draw(1);
  323. + $this->draw(1) if ($this->root->overlapping);
  324. return $this;
  325. }
  326. @@ -1017,6 +1018,8 @@
  327. my $show_cursor = $this->{-nocursor} ? 0 : 1;
  328. $this->root->cursor_mode($show_cursor);
  329. + $this->draw(1) if (not $this->root->overlapping);
  330. +
  331. return $this;
  332. }
  333. @@ -1025,6 +1028,7 @@
  334. my $this = shift;
  335. $this->{-focus} = 0;
  336. $this->run_event('-onblur');
  337. + $this->draw(1) if (not $this->root->overlapping);
  338. return $this;
  339. }
  340. Index: examples/demo-widgets
  341. ===================================================================
  342. RCS file: /u/rse/wrk/cui/cvs/cui/examples/demo-widgets,v
  343. retrieving revision 1.1.1.4
  344. retrieving revision 1.9
  345. diff -u -d -u -d -r1.1.1.4 -r1.9
  346. --- examples/demo-widgets 1 Sep 2003 07:24:37 -0000 1.1.1.4
  347. +++ examples/demo-widgets 16 Oct 2003 17:52:29 -0000 1.9
  348. @@ -1,6 +1,11 @@
  349. -#!/usr/bin/perl -w
  350. +#!/usr/lpkg/bin/perl -w
  351. use strict;
  352. use File::Temp qw( :POSIX );
  353. +use lib "../lib";
  354. +
  355. +# make KEY_BTAB (shift-tab) working in XTerm
  356. +# and also at the same time enable colors
  357. +#$ENV{TERM} = "xterm-vt220" if ($ENV{TERM} eq 'xterm');
  358. my $debug = 0;
  359. if (@ARGV and $ARGV[0] eq '-d') {
  360. @@ -150,7 +155,7 @@
  361. $w{1}->add(undef,'Label',-text=>"dim font",-y=>5,-dim=>1 );
  362. $w{1}->add(undef,'Label',-text=>"bold font",-y=>7,-bold=>1 );
  363. -$w{1}->add(undef,'Label',-text=>"reversed font",-y=>9,-reversed => 1 );
  364. +$w{1}->add(undef,'Label',-text=>"reversed font",-y=>9,-reverse => 1 );
  365. $w{1}->add(undef,'Label',-text=>"underlined font",-x=>15,-y=>5,-underline=>1 );
  366. $w{1}->add(undef,'Label',-text=>"blinking font",-x=>15,-y=>7,-blink=>1 );