1 |
#! perl |
2 |
|
3 |
# |
4 |
# problems with this implementation include |
5 |
# |
6 |
# - primary, secondary, teriary is NOT different to other hilighting |
7 |
# - if rend values are missing, they are not interpolated |
8 |
# |
9 |
|
10 |
my $SIZEOF_LONG = length pack "l!", 0; |
11 |
|
12 |
sub refresh { |
13 |
my ($self) = @_; |
14 |
|
15 |
delete $self->{overlay}; |
16 |
|
17 |
my $text = $self->{text}; |
18 |
|
19 |
return unless length $text; |
20 |
|
21 |
my ($row, $col) = $self->screen_cur; |
22 |
|
23 |
my $idx = 0; |
24 |
|
25 |
my @rend = map { |
26 |
my $rstyle = $self->{caret} == $idx ? urxvt::OVERLAY_RSTYLE : $self->rstyle; |
27 |
|
28 |
$rstyle |= urxvt::RS_Uline if $_ & (urxvt::XIMUnderline | urxvt::XIMPrimary); |
29 |
$rstyle |= urxvt::RS_RVid if $_ & (urxvt::XIMReverse | urxvt::XIMSecondary); |
30 |
$rstyle |= urxvt::RS_Blink if $_ & (urxvt::XIMHighlight | urxvt::XIMTertiary); |
31 |
|
32 |
($rstyle) x ($self->strwidth (substr $text, $idx++, 1)) |
33 |
} unpack "l!*", $self->{rend}; |
34 |
|
35 |
if ($self->{caret} >= length $text) { |
36 |
$text .= " "; |
37 |
push @rend, urxvt::OVERLAY_RSTYLE; |
38 |
} |
39 |
|
40 |
$self->{overlay} = $self->overlay ($col, $row, $self->strwidth ($text), 1, $self->rstyle, 0); |
41 |
$self->{overlay}->set (0, 0, $self->special_encode ($text), \@rend); |
42 |
} |
43 |
|
44 |
sub on_xim_preedit_start { |
45 |
my ($self) = @_; |
46 |
|
47 |
() |
48 |
} |
49 |
|
50 |
sub on_xim_preedit_done { |
51 |
my ($self) = @_; |
52 |
|
53 |
delete $self->{overlay}; |
54 |
delete $self->{text}; |
55 |
delete $self->{rend}; |
56 |
|
57 |
() |
58 |
} |
59 |
|
60 |
sub on_xim_preedit_caret { |
61 |
my ($self, $pos, $dir, $style) = @_; |
62 |
warn "preedit_caret(@_)\n"; |
63 |
() |
64 |
} |
65 |
|
66 |
sub on_xim_preedit_draw { |
67 |
my ($self, $caret, $pos, $len, $feedback, $chars) = @_; |
68 |
|
69 |
$self->{caret} = $caret; |
70 |
|
71 |
substr $self->{rend}, $pos * $SIZEOF_LONG, $len * $SIZEOF_LONG, $feedback; |
72 |
substr $self->{text}, $pos , $len , $chars if defined $feedback || !defined $chars; |
73 |
|
74 |
$self->refresh; |
75 |
|
76 |
() |
77 |
} |
78 |
|
79 |
|