perl-curses.patch 13 KB

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