PERL_O=rxvtperl.o
PERLFLAGS="`$PERL -MExtUtils::Embed -e ccopts`"
PERLLIB="`$PERL -MExtUtils::Embed -e ldopts`"
- PERLARCHLIB="`$PERL -MConfig -e 'print $Config{archlib}'`"
+ PERLPRIVLIBEXP="`$PERL -MConfig -e 'print $Config{privlibexp}'`"
AC_MSG_RESULT(ok)
else
AC_MSG_ERROR(no working perl found, or perl not version >= 5.8)
fi
AC_SUBST(PERLLIB)
AC_SUBST(PERLFLAGS)
-AC_SUBST(PERLARCHLIB)
+AC_SUBST(PERLPRIVLIBEXP)
AC_SUBST(PERL)
AC_SUBST(IF_PERL)
AC_SUBST(PERL_O)
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os VERSION DATE LSMDATE LIBVERSION CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK LINKER CXXCPP EGREP INSTALL_LIBRXVT RXVTNAME MV RM CP LN SED ECHO CMP TBL TIC X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS XPM_CPPFLAGS XPM_CFLAGS XPM_LIBS rxvt_int16_typedef rxvt_uint16_typedef rxvt_int32_typedef rxvt_uint32_typedef rxvt_intp_define rxvt_u_intp_define PERL PERLLIB PERLFLAGS PERLARCHLIB IF_PERL PERL_O DEBUG DINCLUDE DLIB include_stdint_h include_stdarg_h include_stdlib_h include_unistd_h include_string_h include_fcntl_h include_util_h include_assert_h include_sys_ioctl_h include_sys_select_h include_sys_strredir_h include_sys_time_h include_time_h LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os VERSION DATE LSMDATE LIBVERSION CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AWK LINKER CXXCPP EGREP INSTALL_LIBRXVT RXVTNAME MV RM CP LN SED ECHO CMP TBL TIC X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS XPM_CPPFLAGS XPM_CFLAGS XPM_LIBS rxvt_int16_typedef rxvt_uint16_typedef rxvt_int32_typedef rxvt_uint32_typedef rxvt_intp_define rxvt_u_intp_define PERL PERLLIB PERLFLAGS PERLPRIVLIBEXP IF_PERL PERL_O DEBUG DINCLUDE DLIB include_stdint_h include_stdarg_h include_stdlib_h include_unistd_h include_string_h include_fcntl_h include_util_h include_assert_h include_sys_ioctl_h include_sys_select_h include_sys_strredir_h include_sys_time_h include_time_h LIBOBJS LTLIBOBJS'
ac_subst_files='MCOMMON'
# Initialize some variables set by options.
PERL_O=rxvtperl.o
PERLFLAGS="`$PERL -MExtUtils::Embed -e ccopts`"
PERLLIB="`$PERL -MExtUtils::Embed -e ldopts`"
- PERLARCHLIB="`$PERL -MConfig -e 'print $Config{archlib}'`"
+ PERLPRIVLIBEXP="`$PERL -MConfig -e 'print $Config{privlibexp}'`"
echo "$as_me:$LINENO: result: ok" >&5
echo "${ECHO_T}ok" >&6
else
s,@PERL@,$PERL,;t t
s,@PERLLIB@,$PERLLIB,;t t
s,@PERLFLAGS@,$PERLFLAGS,;t t
-s,@PERLARCHLIB@,$PERLARCHLIB,;t t
+s,@PERLPRIVLIBEXP@,$PERLPRIVLIBEXP,;t t
s,@IF_PERL@,$IF_PERL,;t t
s,@PERL_O@,$PERL_O,;t t
s,@DEBUG@,$DEBUG,;t t
$(PERL) -MExtUtils::Embed -e xsinit -- -std urxvt
rxvtperl.C: rxvtperl.xs typemap
- $(PERL) @PERLARCHLIB@/ExtUtils/xsubpp -C++ -typemap @PERLARCHLIB@/ExtUtils/typemap -typemap typemap -prototypes $< >$@
+ $(PERL) @PERLPRIVLIBEXP@/ExtUtils/xsubpp -C++ -typemap @PERLPRIVLIBEXP@/ExtUtils/typemap -typemap typemap -prototypes $< >$@
rxvtperl.o: rxvtperl.C perlxsi.c
$(COMPILE) @PERLFLAGS@ -DLIBDIR="\"$(libdir)/urxvt\"" -c $<
vector<rxvt_term *> rxvt_term::termlist;
-static char curlocale[128];
+static char curlocale[128], savelocale[128];
bool
rxvt_set_locale (const char *locale)
return true;
}
+bool
+rxvt_push_locale (const char *locale)
+{
+ strcpy (savelocale, curlocale);
+ rxvt_set_locale (locale);
+}
+
+void
+rxvt_pop_locale ()
+{
+ rxvt_set_locale (savelocale);
+}
+
#if ENABLE_COMBINING
class rxvt_composite_vec rxvt_composite;
#ifdef TINTING
Rs_def(shade)
#endif
+#if ENABLE_PERL
+ Rs_def(perl_lib)
+ Rs_def(perl_eval)
+ Rs_def(perl)
+#endif
#define SET_LOCALE(locale) rxvt_set_locale (locale)
extern bool rxvt_set_locale (const char *locale);
+extern bool rxvt_push_locale (const char *locale);
+extern void rxvt_pop_locale ();
/*
*****************************************************************************
CODE:
rxvt_fatal ("%s", msg);
+NV
+NOW ()
+ CODE:
+ RETVAL = NOW;
+ OUTPUT:
+ RETVAL
+
+MODULE = urxvt PACKAGE = urxvt::term
+
int
-wcswidth (SV *str)
+rxvt_term::strwidth (SV *str)
CODE:
{
wchar_t *wstr = sv2wcs (str);
+
+ rxvt_push_locale (THIS->locale);
RETVAL = wcswidth (wstr, wcslen (wstr));
+ rxvt_pop_locale ();
+
free (wstr);
}
OUTPUT:
RETVAL
-NV
-NOW ()
+SV *
+rxvt_term::locale_encode (SV *str)
CODE:
- RETVAL = NOW;
- OUTPUT:
+{
+ wchar_t *wstr = sv2wcs (str);
+
+ rxvt_push_locale (THIS->locale);
+ char *mbstr = rxvt_wcstombs (wstr);
+ rxvt_pop_locale ();
+
+ free (wstr);
+
+ RETVAL = newSVpv (mbstr, 0);
+ free (mbstr);
+}
+ OUTPUT:
RETVAL
-MODULE = urxvt PACKAGE = urxvt::term
+SV *
+rxvt_term::locale_decode (SV *octets)
+ CODE:
+{
+ STRLEN len;
+ char *data = SvPVbyte (octets, len);
+
+ rxvt_push_locale (THIS->locale);
+ wchar_t *wstr = rxvt_mbstowcs (data, len);
+ rxvt_pop_locale ();
+
+ char *str = rxvt_wcstoutf8 (wstr);
+ free (wstr);
+
+ RETVAL = newSVpv (str, 0);
+ SvUTF8_on (RETVAL);
+ free (str);
+}
+ OUTPUT:
+ RETVAL
void
rxvt_term::_resource (char *name, int index, SV *newval = 0)
free (wtext);
}
+void
+rxvt_term::tt_write (SV *octets)
+ INIT:
+ STRLEN len;
+ char *str = SvPVbyte (octets, len);
+ C_ARGS:
+ (unsigned char *)str, len
+
MODULE = urxvt PACKAGE = urxvt::timer
SV *
* Put your scripts into F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>, they will be loaded automatically.
-* Each script will only be loaded once, even in urxvtd, and will be valid
-globally.
-
* Scripts are evaluated in a 'use strict' and 'use utf8' environment, and
thus must be encoded as UTF-8.
=head1 DESCRIPTION
+On startup, @@RXVT_NAME@@ will scan F<@@RXVT_LIBDIR@@/urxvt/perl-ext/>
+for files and will load them. Everytime a terminal object gets created,
+the directory specified by the C<perl-lib> resource will be additionally
+scanned.
+
+Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where
+scripts will be shared for all terminals.
+
+Hooks in scripts specified by C<perl-lib> will only be called for the
+terminals created with that specific option value.
+
+=head2 General API Considerations
+
+All objects (such as terminals, time watchers etc.) are typical
+reference-to-hash objects. The hash can be used to store anything you
+like. The only reserved member is C<_ptr>, which must not be changed.
+
+When objects are destroyed on the C++ side, the perl object hashes are
+emptied, so its best to store related objects such as time watchers and
+the like inside the terminal object so they get destroyed as soon as the
+terminal is destroyed.
+
=head2 Hooks
The following subroutines can be declared in loaded scripts, and will be called
=item urxvt::warn $string
-Calls C<rxvt_warn> witht eh given string which should not include a
+Calls C<rxvt_warn> with the given string which should not include a
newline. The module also overwrites the C<warn> builtin with a function
that calls this function.
Using this function has the advantage that its output ends up in the
correct place, e.g. on stderr of the connecting urxvtc client.
-=item $cellwidth = urxvt::wcswidth $string
-
-Returns the number of screen-cells this string would need. Correctly
-accounts for wide and combining characters.
-
=item $time = urxvt::NOW
Returns the "current time" (as per the event loop).
};
}
-load_script $_ for grep -f $_, <$LIBDIR/perl-ext/*>;
+sub load_scripts($) {
+ my ($dir) = @_;
+
+ verbose 3, "loading scripts from '$dir'";
+
+ load_script $_
+ for grep -f $_,
+ <$dir/perl-ext/*>;
+}
+
+sub on_init {
+ my ($term) = @_;
+
+ my $libdir = $term->resource ("perl_lib");
+
+ load_scripts $libdir
+ if defined $libdir;
+}
+
+register_package __PACKAGE__;
+load_scripts $LIBDIR;
=back
display_name embed ext_bwidth fade font geometry hold iconName
imFont imLocale inputMethod insecure int_bwidth intensityStyles
italicFont jumpScroll lineSpace loginShell mapAlert menu meta8
- modifier mouseWheelScrollPage name pastableTabs path pointerBlank
- pointerBlankDelay preeditType print_pipe pty_fd reverseVideo saveLines
- scrollBar scrollBar_align scrollBar_floating scrollBar_right
- scrollBar_thickness scrollTtyKeypress scrollTtyOutput scrollWithBuffer
- scrollstyle secondaryScreen secondaryScroll selectstyle shade term_name
- title transparent transparent_all tripleclickwords utmpInhibit
- visualBell
+ modifier mouseWheelScrollPage name pastableTabs path perl perl_eval
+ perl_lib pointerBlank pointerBlankDelay preeditType print_pipe pty_fd
+ reverseVideo saveLines scrollBar scrollBar_align scrollBar_floating
+ scrollBar_right scrollBar_thickness scrollTtyKeypress scrollTtyOutput
+ scrollWithBuffer scrollstyle secondaryScreen secondaryScroll selectstyle
+ shade term_name title transparent transparent_all tripleclickwords
+ utmpInhibit visualBell
=cut
my @lines = split /\n/, $text;
my $w = 0;
- for (map urxvt::wcswidth $_, @lines) {
+ for (map $self->strwidth ($_), @lines) {
$w = $_ if $w < $_;
}
Write a string at the given position into the overlay.
+=item $cellwidth = $term->strwidth $string
+
+Returns the number of screen-cells this string would need. Correctly
+accounts for wide and combining characters.
+
+=item $octets = $term->locale_encode $string
+
+Convert the given text string into the corresponding locale encoding.
+
+=item $string = $term->locale_decode $octets
+
+Convert the given locale-encoded octets into a perl string.
+
+=item $term->tt_write ($octets)
+
+Write the octets given in C<$data> to the tty (i.e. as program input). To
+pass characters instead of octets, you should convetr you strings first to
+the locale-specific encoding using C<< $term->locale_encode >>.
+
=back
=head2 The C<urxvt::timer> Class
BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, "enable secondary screen"),
BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, "enable secondary screen scroll"),
#endif
+#if ENABLE_PERL
+ STRG (Rs_perl_lib, "perl-lib", 0, "string", "directory where to look for additional extension scripts"),
+ STRG (Rs_perl_eval, "perl-eval", 0, "string", "string to be evaluated after all extensions have been loaded"),
+ STRG (Rs_perl, "perl", "perl", "string", "unused by urxvt proper, free for extensions to use"),
+#endif
#if 0 && TODO
#if !defined(NO_RESOURCES) && defined(USE_XGETDEFAULT)
INFO ("xrm", "string", "X resource"),