File: draw-box

package info (click to toggle)
libterm-slang-perl 0.07-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 100 kB
  • ctags: 39
  • sloc: perl: 614; makefile: 42
file content (84 lines) | stat: -rwxr-xr-x 1,487 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl -w

# $Id: draw-box,v 1.4 2000/04/17 03:53:11 joey Rel $

use strict;
use ExtUtils::testlib;
use Term::Slang qw(:all);

SLtt_get_terminfo();
SLang_init_tty(-1,0,1);
SLsig_block_signals();
SLsmg_init_smg();
SLsmg_cls();
SLsig_unblock_signals();
SLkp_init();

my $q = 'oink.';

my $dc = (length $q) + 2;
my $dr = 7;
   $dc = 36 if $dc < 32;

my ($s_rows,$s_cols) = SLtt_get_screen_size();

my $r = ($s_rows - $dr)/2;
my $c = ($s_cols - $dc)/2;

my $box_color = 2;
my $button_color = 3;

define_color($button_color,'white','green');
define_color($box_color,'yellow','blue');

SLsmg_set_color($box_color);
SLsmg_draw_box($r,$c,$dr,$dc);

SLsmg_set_color(0);

$r += 2;
draw_centered_string($q,$r,$c,$dc);
$r += 2;

display_button('Yes',$r,$c + 4);
display_button('No', $r,$c + 14);
display_button('Cancel',$r,$c + 24);

SLsmg_refresh();

while(my $k = SLkp_getkey()) {

	if ($k eq SL_KEY_LEFT) {
		SLsmg_write_string("foo");
		last;
	}
}

SLang_reset_tty();
SLsmg_reset_smg();

##########################
sub draw_centered_string {
	my ($s,$r,$c,$dc) = @_;
	SLsig_block_signals();
	SLsmg_gotorc($r,$c + ($dc - (length $s))/2);
	SLsmg_write_string($s);
	SLsig_unblock_signals();
}

sub display_button {
	my ($name,$r,$c) = @_;
	SLsig_block_signals();
	SLsmg_gotorc($r,$c);
	SLsmg_set_color($button_color);
	SLsmg_write_string(" $name ");
	SLsmg_set_color(0);
	SLsig_unblock_signals();
}

sub define_color {
	my ($obj,$fg,$bg) = @_;
	SLtt_set_color($obj,'',$fg,$bg);
}

__END__