perl-curses.patch 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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 29 Mar 2003 10:43:45 -0000 1.6
  7. @@ -0,0 +1,19 @@
  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 Add color support.
  24. +
  25. + o Fix reverse rendering for Label demo in demo-widgets.
  26. +
  27. Index: lib/Curses/UI.pm
  28. ===================================================================
  29. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI.pm,v
  30. retrieving revision 1.1.1.3
  31. retrieving revision 1.5
  32. diff -u -d -u -d -r1.1.1.3 -r1.5
  33. --- lib/Curses/UI.pm 29 Mar 2003 10:41:56 -0000 1.1.1.3
  34. +++ lib/Curses/UI.pm 29 Mar 2003 10:42:44 -0000 1.5
  35. @@ -67,6 +67,8 @@
  36. -debug => undef, # Turn on debugging mode?
  37. -language => undef, # Which language to use?
  38. -mouse_support => 1, # Do we want mouse support
  39. + -overlapping => 1, # Whether overlapping widgets are supported
  40. + -colors => 0, # Whether colors are used
  41. #user data
  42. -userdata => undef, #user internal data
  43. @@ -126,6 +128,8 @@
  44. sub clear_on_exit(;$) { shift()->accessor('-clear_on_exit', shift()) }
  45. sub cursor_mode(;$) { shift()->accessor('-cursor_mode', shift()) }
  46. sub lang(;$) { shift()->accessor('-language_object', shift()) }
  47. +sub overlapping(;$) { shift()->accessor('-overlapping', shift()) }
  48. +sub colors(;$) { shift()->accessor('-colors', shift()) }
  49. # TODO: document
  50. sub debug(;$)
  51. @@ -136,6 +140,61 @@
  52. }
  53. # ----------------------------------------------------------------------
  54. +# Color support
  55. +# ----------------------------------------------------------------------
  56. +
  57. +$Curses::UI::colorpairs = 0;
  58. +$Curses::UI::colorpair = {};
  59. +
  60. +sub colorpair ($$;$$)
  61. +{
  62. + my $this = shift;
  63. + my ($name, $fg, $bg) = @_;
  64. + my $colors_name2num = {
  65. + 'black' => COLOR_BLACK,
  66. + 'red' => COLOR_RED,
  67. + 'green' => COLOR_GREEN,
  68. + 'yellow' => COLOR_YELLOW,
  69. + 'blue' => COLOR_BLUE,
  70. + 'magenta' => COLOR_MAGENTA,
  71. + 'cyan' => COLOR_CYAN,
  72. + 'white' => COLOR_WHITE
  73. + };
  74. +
  75. + if (not $this->{-colors}) {
  76. + return 0;
  77. + }
  78. + if (not defined($fg) and not defined($bg)) {
  79. + return ($Curses::UI::colorpair->{$name} || 0);
  80. + }
  81. + else {
  82. + my $n = $Curses::UI::colorpair->{$name};
  83. + if (not defined($n)) {
  84. + $Curses::UI::colorpairs++;
  85. + $n = $Curses::UI::colorpairs;
  86. + }
  87. + $fg = $colors_name2num->{$fg} || 'default';
  88. + if ($fg eq 'default') {
  89. + my ($fg_d, $bg_d) = (0, 0);
  90. + pair_content(0, $fg_d, $bg_d);
  91. + $fg = $fg_d;
  92. + }
  93. + $bg = $colors_name2num->{$bg} || 'default';
  94. + if ($bg eq 'default') {
  95. + my ($fg_d, $bg_d) = (0, 0);
  96. + pair_content(0, $fg_d, $bg_d);
  97. + $bg = $bg_d;
  98. + }
  99. + init_pair($n, $fg, $bg);
  100. + if ($name eq 'default') {
  101. + assume_default_colors($fg, $bg);
  102. + }
  103. + $Curses::UI::colorpair->{$name} = $n;
  104. + return $n;
  105. + }
  106. +}
  107. +
  108. +# ----------------------------------------------------------------------
  109. # Window resizing support
  110. # ----------------------------------------------------------------------
  111. @@ -151,6 +210,23 @@
  112. initscr();
  113. noecho();
  114. raw();
  115. +
  116. + # Color support
  117. + if ($this->{-colors}) {
  118. + if (has_colors()) {
  119. + start_color();
  120. + #my $bg = -1;
  121. + #use_default_colors();
  122. + my $bg = COLOR_BLACK;
  123. + assume_default_colors(COLOR_WHITE, $bg);
  124. + $Curses::UI::colorpair->{"default"} = 0;
  125. + $Curses::UI::colorpairs = 1;
  126. + $this->colorpair('selected', 'default', 'default');
  127. + }
  128. + else {
  129. + $this->{-colors} = 0;
  130. + }
  131. + }
  132. # Mouse events if possible
  133. my $old = 0;
  134. Index: lib/Curses/UI/Label.pm
  135. ===================================================================
  136. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Label.pm,v
  137. retrieving revision 1.1.1.2
  138. retrieving revision 1.3
  139. diff -u -d -u -d -r1.1.1.2 -r1.3
  140. --- lib/Curses/UI/Label.pm 28 Mar 2003 08:22:35 -0000 1.1.1.2
  141. +++ lib/Curses/UI/Label.pm 28 Mar 2003 08:24:58 -0000 1.3
  142. @@ -51,6 +51,7 @@
  143. -dim => 0,
  144. -blink => 0,
  145. -paddingspaces => 0, # Pad text with spaces?
  146. + -colorpair => undef, # Color-pair attribute
  147. %userargs,
  148. @@ -104,6 +105,7 @@
  149. sub underline ($;$) { shift()->set_attribute('-underline', shift()) }
  150. sub dim ($;$) { shift()->set_attribute('-dim', shift()) }
  151. sub blink ($;$) { shift()->set_attribute('-blink', shift()) }
  152. +sub colorpair ($;$) { shift()->set_attribute('-colorpair', shift()) }
  153. sub set_attribute($$;)
  154. {
  155. @@ -183,6 +185,7 @@
  156. $this->{-canvasscr}->attron(A_UNDERLINE) if $this->{-underline};
  157. $this->{-canvasscr}->attron(A_BLINK) if $this->{-blink};
  158. $this->{-canvasscr}->attron(A_DIM) if $this->{-dim};
  159. + $this->{-canvasscr}->attron(COLOR_PAIR($this->root->colorpair($this->{-colorpair}))) if $this->{-colorpair};
  160. # Draw the text. Clip it if it is too long.
  161. my $ypos = 0;
  162. Index: lib/Curses/UI/Listbox.pm
  163. ===================================================================
  164. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Listbox.pm,v
  165. retrieving revision 1.1.1.3
  166. retrieving revision 1.4
  167. diff -u -d -u -d -r1.1.1.3 -r1.4
  168. --- lib/Curses/UI/Listbox.pm 29 Mar 2003 10:41:56 -0000 1.1.1.3
  169. +++ lib/Curses/UI/Listbox.pm 29 Mar 2003 10:42:44 -0000 1.4
  170. @@ -304,10 +304,12 @@
  171. }
  172. # Show selected element bold.
  173. - if (not $this->{-multi} and
  174. - not $this->{-radio} and
  175. - defined $this->{-selected} and
  176. - $this->{-selected} == $i) {
  177. + if ( ( not $this->{-multi}
  178. + and defined $this->{-selected}
  179. + and $this->{-selected} == $i)
  180. + or ( $this->{-multi}
  181. + and defined $this->{-selected}
  182. + and $this->{-selected}->{$i}) ) {
  183. $this->{-canvasscr}->attron(A_BOLD);
  184. }
  185. Index: lib/Curses/UI/TextEditor.pm
  186. ===================================================================
  187. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/TextEditor.pm,v
  188. retrieving revision 1.1.1.3
  189. retrieving revision 1.4
  190. diff -u -d -u -d -r1.1.1.3 -r1.4
  191. --- lib/Curses/UI/TextEditor.pm 29 Mar 2003 10:41:57 -0000 1.1.1.3
  192. +++ lib/Curses/UI/TextEditor.pm 29 Mar 2003 10:42:44 -0000 1.4
  193. @@ -151,6 +151,7 @@
  194. -vscrollbar => 0, # show vertical scrollbar
  195. -hscrollbar => 0, # show horizontal scrollbar
  196. -readonly => 0, # only used as viewer?
  197. + -reverse => 0, # show in reverse
  198. # Single line options
  199. -password => undef, # masquerade chars with given char
  200. @@ -451,9 +452,10 @@
  201. # Turn on underlines and fill the screen with lines
  202. # if neccessary.
  203. - if ($this->{-showlines})
  204. + if ($this->{-showlines} or $this->{-reverse})
  205. {
  206. - $this->{-canvasscr}->attron(A_UNDERLINE);
  207. + $this->{-canvasscr}->attron(A_UNDERLINE) if ($this->{-showlines});;
  208. + $this->{-canvasscr}->attron(A_REVERSE) if ($this->{-reverse});
  209. for my $y (0..$this->canvasheight-1) {
  210. $this->{-canvasscr}->addstr($y, 0, " "x($this->canvaswidth));
  211. }
  212. @@ -464,9 +466,11 @@
  213. {
  214. if (defined $this->{-search_highlight}
  215. and $this->{-search_highlight} == ($id+$this->{-yscrpos})) {
  216. - $this->{-canvasscr}->attron(A_REVERSE);
  217. + $this->{-canvasscr}->attron(A_REVERSE) if (not $this->{-reverse});
  218. + $this->{-canvasscr}->attroff(A_REVERSE) if ($this->{-reverse});
  219. } else {
  220. - $this->{-canvasscr}->attroff(A_REVERSE);
  221. + $this->{-canvasscr}->attroff(A_REVERSE) if (not $this->{-reverse});
  222. + $this->{-canvasscr}->attron(A_REVERSE) if ($this->{-reverse});
  223. }
  224. my $l = $this->{-scr_lines}->[$id + $this->{-yscrpos}];
  225. @@ -560,6 +564,7 @@
  226. }
  227. $this->{-canvasscr}->attroff(A_UNDERLINE) if $this->{-showlines};
  228. + $this->{-canvasscr}->attroff(A_REVERSE) if $this->{-reverse};
  229. $this->{-canvasscr}->noutrefresh();
  230. doupdate() unless $no_doupdate;
  231. return $this;
  232. Index: lib/Curses/UI/Widget.pm
  233. ===================================================================
  234. RCS file: /u/rse/wrk/cui/cvs/cui/lib/Curses/UI/Widget.pm,v
  235. retrieving revision 1.1.1.3
  236. retrieving revision 1.4
  237. diff -u -d -u -d -r1.1.1.3 -r1.4
  238. --- lib/Curses/UI/Widget.pm 29 Mar 2003 10:41:57 -0000 1.1.1.3
  239. +++ lib/Curses/UI/Widget.pm 29 Mar 2003 10:42:44 -0000 1.4
  240. @@ -472,7 +472,7 @@
  241. my $parent = $this->parent;
  242. $parent->focus($this) if defined $parent;
  243. - $this->draw(1);
  244. + $this->draw(1) if ($this->root->overlapping);
  245. return $this;
  246. }
  247. @@ -523,6 +523,7 @@
  248. if ($this->{-sbborder}) # Square bracket ([,]) border
  249. {
  250. $this->{-borderscr}->attron(A_BOLD) if $this->{-focus};
  251. + $this->{-borderscr}->attron(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  252. my $offset = 1;
  253. $offset++ if $this->{-vscrollbar};
  254. for my $y (0 .. $this->{-sh}-1)
  255. @@ -532,10 +533,12 @@
  256. $this->{-borderscr}->addstr($rel_y, $this->{-bw}-$offset, ']');
  257. }
  258. $this->{-borderscr}->attroff(A_BOLD) if $this->{-focus};
  259. + $this->{-borderscr}->attroff(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  260. }
  261. elsif ($this->{-border}) # Normal border
  262. {
  263. $this->{-borderscr}->attron(A_BOLD) if $this->{-focus};
  264. + $this->{-borderscr}->attron(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  265. if ($this->root->compat) {
  266. $this->{-borderscr}->border(
  267. '|','|','-','-',
  268. @@ -545,6 +548,7 @@
  269. $this->{-borderscr}->box(ACS_VLINE, ACS_HLINE);
  270. }
  271. $this->{-borderscr}->attroff(A_BOLD) if $this->{-focus};
  272. + $this->{-borderscr}->attroff(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  273. # Draw a title if needed.
  274. if (defined $this->{-title})
  275. @@ -628,6 +632,7 @@
  276. # Draw the base of the scrollbar, in case
  277. # there is no border.
  278. $this->{-borderscr}->attron(A_BOLD) if $this->{-focus};
  279. + $this->{-borderscr}->attron(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  280. $this->{-borderscr}->move($ypos_min, $xpos);
  281. $this->{-borderscr}->vline(ACS_VLINE,$scrlen);
  282. if ($this->root->compat) {
  283. @@ -636,6 +641,7 @@
  284. $this->{-borderscr}->vline(ACS_VLINE,$scrlen);
  285. }
  286. $this->{-borderscr}->attroff(A_BOLD) if $this->{-focus};
  287. + $this->{-borderscr}->attroff(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  288. # Should an active region be drawn?
  289. my $scroll_active = ($this->{-vscrolllen} > $scrlen);
  290. @@ -693,6 +699,7 @@
  291. # Draw the base of the scrollbar, in case
  292. # there is no border.
  293. $this->{-borderscr}->attron(A_BOLD) if $this->{-focus};
  294. + $this->{-borderscr}->attron(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  295. $this->{-borderscr}->move($ypos, $xpos_min);
  296. if ($this->root->compat) {
  297. $this->{-borderscr}->hline('-',$scrlen);
  298. @@ -700,6 +707,7 @@
  299. $this->{-borderscr}->hline(ACS_HLINE,$scrlen);
  300. }
  301. $this->{-borderscr}->attroff(A_BOLD) if $this->{-focus};
  302. + $this->{-borderscr}->attroff(COLOR_PAIR($this->root->colorpair('selected'))) if $this->{-focus};
  303. # Should an active region be drawn?
  304. my $scroll_active = ($this->{-hscrolllen} > $scrlen);
  305. @@ -959,6 +967,8 @@
  306. my $show_cursor = $this->{-nocursor} ? 0 : 1;
  307. $this->root->cursor_mode($show_cursor);
  308. + $this->draw(1) if (not $this->root->overlapping);
  309. +
  310. return $this;
  311. }
  312. @@ -967,6 +977,7 @@
  313. my $this = shift;
  314. $this->{-focus} = 0;
  315. $this->run_event('-onblur');
  316. + $this->draw(1) if (not $this->root->overlapping);
  317. return $this;
  318. }
  319. Index: examples/demo-widgets
  320. ===================================================================
  321. RCS file: /u/rse/wrk/cui/cvs/cui/examples/demo-widgets,v
  322. retrieving revision 1.1.1.2
  323. retrieving revision 1.5
  324. diff -u -d -u -d -r1.1.1.2 -r1.5
  325. --- examples/demo-widgets 29 Mar 2003 10:41:58 -0000 1.1.1.2
  326. +++ examples/demo-widgets 29 Mar 2003 10:42:44 -0000 1.5
  327. @@ -1,6 +1,11 @@
  328. -#!/usr/bin/perl -w
  329. +#!/usr/lpkg/bin/perl -w
  330. use strict;
  331. use File::Temp qw( :POSIX );
  332. +use lib "../lib";
  333. +
  334. +# make KEY_BTAB (shift-tab) working in XTerm
  335. +# and also at the same time enable colors
  336. +$ENV{TERM} = "xterm-vt220" if ($ENV{TERM} eq 'xterm');
  337. my $debug = 0;
  338. if (@ARGV and $ARGV[0] eq '-d') {
  339. @@ -22,7 +27,10 @@
  340. my $cui = new Curses::UI (
  341. -clear_on_exit => 1,
  342. -debug => $debug,
  343. + -colors => 1,
  344. );
  345. +$cui->colorpair('selected', 'red', 'default');
  346. +$cui->colorpair('white-on-red', 'white', 'red');
  347. # Demo index
  348. my $current_demo = 1;
  349. @@ -150,9 +158,10 @@
  350. $w{1}->add(undef,'Label',-text=>"dim font",-y=>5,-dim=>1 );
  351. $w{1}->add(undef,'Label',-text=>"bold font",-y=>7,-bold=>1 );
  352. -$w{1}->add(undef,'Label',-text=>"reversed font",-y=>9,-reversed => 1 );
  353. +$w{1}->add(undef,'Label',-text=>"reversed font",-y=>9,-reverse => 1 );
  354. $w{1}->add(undef,'Label',-text=>"underlined font",-x=>15,-y=>5,-underline=>1 );
  355. $w{1}->add(undef,'Label',-text=>"blinking font",-x=>15,-y=>7,-blink=>1 );
  356. +$w{1}->add(undef,'Label',-text=>"colorized font",-x=>15,-y=>9,-colorpair => 'white-on-red' );
  357. # ----------------------------------------------------------------------
  358. # Buttons demo