perl-curses.patch 14 KB

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