… | |
… | |
51 | char *str = SvPVutf8 (sv, len); |
51 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
52 | return rxvt_utf8towcs (str, len); |
53 | } |
53 | } |
54 | |
54 | |
55 | static SV * |
55 | static SV * |
|
|
56 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
57 | { |
|
|
58 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
59 | |
|
|
60 | SV *sv = newSVpv (str, 0); |
|
|
61 | SvUTF8_on (sv); |
|
|
62 | free (str); |
|
|
63 | |
|
|
64 | return sv; |
|
|
65 | } |
|
|
66 | |
|
|
67 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
68 | new_ref (HV *hv, const char *klass) |
57 | { |
69 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
70 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
71 | } |
60 | |
72 | |
… | |
… | |
457 | |
469 | |
458 | case DT_STRING: |
470 | case DT_STRING: |
459 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
460 | break; |
472 | break; |
461 | |
473 | |
|
|
474 | case DT_USTRING_LEN: |
|
|
475 | { |
|
|
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
|
|
477 | int ulen = va_arg (ap, int); |
|
|
478 | wchar_t *wstr = new wchar_t [ulen]; |
|
|
479 | |
|
|
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
|
|
484 | |
|
|
485 | delete [] wstr; |
|
|
486 | } |
|
|
487 | |
462 | case DT_END: |
488 | case DT_END: |
463 | { |
489 | { |
464 | va_end (ap); |
490 | va_end (ap); |
465 | |
491 | |
466 | PUTBACK; |
492 | PUTBACK; |
… | |
… | |
518 | export_const (RS_Uline); |
544 | export_const (RS_Uline); |
519 | |
545 | |
520 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
521 | } |
547 | } |
522 | |
548 | |
|
|
549 | SV * |
|
|
550 | new (...) |
|
|
551 | CODE: |
|
|
552 | { |
|
|
553 | stringvec *argv = new stringvec; |
|
|
554 | bool success; |
|
|
555 | |
|
|
556 | for (int i = 0; i < items ;i++) |
|
|
557 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
558 | |
|
|
559 | rxvt_term *term = new rxvt_term; |
|
|
560 | |
|
|
561 | term->argv = argv; |
|
|
562 | |
|
|
563 | try |
|
|
564 | { |
|
|
565 | if (!term->init (argv->size (), argv->begin ())) |
|
|
566 | term = 0; |
|
|
567 | } |
|
|
568 | catch (const class rxvt_failure_exception &e) |
|
|
569 | { |
|
|
570 | term->destroy (); |
|
|
571 | croak ("exception caught while initializing new terminal instance"); |
|
|
572 | } |
|
|
573 | |
|
|
574 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
575 | } |
|
|
576 | OUTPUT: |
|
|
577 | RETVAL |
|
|
578 | |
523 | void |
579 | void |
524 | set_should_invoke (int htype, int value) |
580 | set_should_invoke (int htype, int value) |
525 | CODE: |
581 | CODE: |
526 | rxvt_perl.should_invoke [htype] = value; |
582 | rxvt_perl.should_invoke [htype] = value; |
527 | |
583 | |
… | |
… | |
589 | } |
645 | } |
590 | OUTPUT: |
646 | OUTPUT: |
591 | RETVAL |
647 | RETVAL |
592 | |
648 | |
593 | MODULE = urxvt PACKAGE = urxvt::term |
649 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
650 | |
|
|
651 | void |
|
|
652 | rxvt_term::destroy () |
594 | |
653 | |
595 | int |
654 | int |
596 | rxvt_term::strwidth (SV *str) |
655 | rxvt_term::strwidth (SV *str) |
597 | CODE: |
656 | CODE: |
598 | { |
657 | { |
… | |
… | |
634 | |
693 | |
635 | rxvt_push_locale (THIS->locale); |
694 | rxvt_push_locale (THIS->locale); |
636 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
695 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
637 | rxvt_pop_locale (); |
696 | rxvt_pop_locale (); |
638 | |
697 | |
639 | char *str = rxvt_wcstoutf8 (wstr); |
698 | RETVAL = wcs2sv (wstr); |
640 | free (wstr); |
699 | free (wstr); |
641 | |
|
|
642 | RETVAL = newSVpv (str, 0); |
|
|
643 | SvUTF8_on (RETVAL); |
|
|
644 | free (str); |
|
|
645 | } |
700 | } |
646 | OUTPUT: |
701 | OUTPUT: |
647 | RETVAL |
702 | RETVAL |
648 | |
703 | |
649 | # very portable, especially on objects as opposed to pods |
704 | # very portable, especially on objects as opposed to pods |
… | |
… | |
681 | RETVAL = *(int *)((char *)THIS + ix); |
736 | RETVAL = *(int *)((char *)THIS + ix); |
682 | OUTPUT: |
737 | OUTPUT: |
683 | RETVAL |
738 | RETVAL |
684 | |
739 | |
685 | U32 |
740 | U32 |
686 | rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) |
741 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
687 | CODE: |
742 | CODE: |
688 | { |
743 | { |
689 | RETVAL = THIS->screen.s_rstyle; |
744 | RETVAL = THIS->rstyle; |
690 | THIS->screen.s_rstyle = new_rstyle; |
745 | THIS->rstyle = new_rstyle; |
691 | } |
746 | } |
692 | OUTPUT: |
747 | OUTPUT: |
693 | RETVAL |
748 | RETVAL |
694 | |
749 | |
695 | int |
750 | int |
… | |
… | |
711 | rxvt_term::want_refresh () |
766 | rxvt_term::want_refresh () |
712 | CODE: |
767 | CODE: |
713 | THIS->want_refresh = 1; |
768 | THIS->want_refresh = 1; |
714 | |
769 | |
715 | void |
770 | void |
716 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
771 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
717 | PPCODE: |
772 | PPCODE: |
718 | { |
773 | { |
719 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
774 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
720 | XSRETURN_EMPTY; |
775 | XSRETURN_EMPTY; |
721 | |
776 | |
… | |
… | |
726 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
781 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
727 | |
782 | |
728 | for (int col = 0; col <THIS->ncol; col++) |
783 | for (int col = 0; col <THIS->ncol; col++) |
729 | wstr [col] = l.t [col]; |
784 | wstr [col] = l.t [col]; |
730 | |
785 | |
731 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
|
|
732 | free (wstr); |
|
|
733 | |
|
|
734 | SV *sv = newSVpv (str, 0); |
|
|
735 | SvUTF8_on (sv); |
|
|
736 | XPUSHs (sv_2mortal (sv)); |
786 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
737 | free (str); |
787 | |
|
|
788 | delete [] wstr; |
738 | } |
789 | } |
739 | |
790 | |
740 | if (new_text) |
791 | if (new_text) |
741 | { |
792 | { |
742 | wchar_t *wstr = sv2wcs (new_text); |
793 | wchar_t *wstr = sv2wcs (new_text); |
743 | |
794 | |
744 | int len = wcslen (wstr); |
795 | int len = min (wcslen (wstr) - start_ofs, max_len); |
745 | |
796 | |
746 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
797 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
747 | { |
798 | { |
748 | free (wstr); |
799 | free (wstr); |
749 | croak ("new_text extends beyond horizontal margins"); |
800 | croak ("new_text extends beyond horizontal margins"); |
750 | } |
801 | } |
751 | |
802 | |
752 | for (int col = start_col; col < start_col + len; col++) |
803 | for (int col = start_col; col < start_col + len; col++) |
753 | { |
804 | { |
754 | l.t [col] = wstr [col - start_col]; |
805 | l.t [col] = wstr [start_ofs + col - start_col]; |
755 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
806 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
756 | } |
807 | } |
757 | |
808 | |
758 | free (wstr); |
809 | free (wstr); |
759 | } |
810 | } |
760 | } |
811 | } |
761 | |
812 | |
762 | void |
813 | void |
763 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
814 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
764 | PPCODE: |
815 | PPCODE: |
765 | { |
816 | { |
766 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
817 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
767 | XSRETURN_EMPTY; |
818 | XSRETURN_EMPTY; |
768 | |
819 | |
… | |
… | |
783 | { |
834 | { |
784 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
835 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
785 | croak ("new_rend must be arrayref"); |
836 | croak ("new_rend must be arrayref"); |
786 | |
837 | |
787 | AV *av = (AV *)SvRV (new_rend); |
838 | AV *av = (AV *)SvRV (new_rend); |
788 | int len = av_len (av) + 1; |
839 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
789 | |
840 | |
790 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
841 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
791 | croak ("new_rend array extends beyond horizontal margins"); |
842 | croak ("new_rend array extends beyond horizontal margins"); |
792 | |
843 | |
793 | for (int col = start_col; col < start_col + len; col++) |
844 | for (int col = start_col; col < start_col + len; col++) |
794 | { |
845 | { |
795 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
846 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
796 | |
847 | |
797 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
848 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
798 | } |
849 | } |
799 | } |
850 | } |
800 | } |
851 | } |
801 | |
852 | |
802 | int |
853 | int |
803 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
854 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
804 | CODE: |
855 | CODE: |
805 | { |
856 | { |
806 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
857 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
807 | XSRETURN_EMPTY; |
858 | XSRETURN_EMPTY; |
808 | |
859 | |
809 | line_t &l = ROW(row_number); |
860 | line_t &l = ROW(row_number); |
810 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
861 | RETVAL = l.l; |
811 | |
862 | |
812 | if (new_length >= -1) |
863 | if (new_length >= 0) |
813 | l.l = new_length; |
864 | l.l = new_length; |
814 | } |
865 | } |
815 | OUTPUT: |
866 | OUTPUT: |
816 | RETVAL |
867 | RETVAL |
817 | |
868 | |
818 | bool |
869 | bool |
819 | rxvt_term::ROW_is_longer (int row_number) |
870 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
820 | CODE: |
871 | CODE: |
821 | { |
872 | { |
822 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
873 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
823 | XSRETURN_EMPTY; |
874 | XSRETURN_EMPTY; |
824 | |
875 | |
825 | line_t &l = ROW(row_number); |
876 | line_t &l = ROW(row_number); |
826 | RETVAL = l.l < 0; |
877 | RETVAL = l.is_longer (); |
|
|
878 | |
|
|
879 | if (new_is_longer >= 0) |
|
|
880 | l.is_longer (new_is_longer); |
827 | } |
881 | } |
828 | OUTPUT: |
882 | OUTPUT: |
829 | RETVAL |
883 | RETVAL |
830 | |
884 | |
831 | SV * |
885 | SV * |
… | |
… | |
916 | void |
970 | void |
917 | rxvt_term::selection (SV *newtext = 0) |
971 | rxvt_term::selection (SV *newtext = 0) |
918 | PPCODE: |
972 | PPCODE: |
919 | { |
973 | { |
920 | if (GIMME_V != G_VOID) |
974 | if (GIMME_V != G_VOID) |
921 | { |
975 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
922 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
|
|
923 | SV *sv = newSVpv (sel, 0); |
|
|
924 | SvUTF8_on (sv); |
|
|
925 | free (sel); |
|
|
926 | XPUSHs (sv_2mortal (sv)); |
|
|
927 | } |
|
|
928 | |
976 | |
929 | if (newtext) |
977 | if (newtext) |
930 | { |
978 | { |
931 | free (THIS->selection.text); |
979 | free (THIS->selection.text); |
932 | |
980 | |
933 | THIS->selection.text = sv2wcs (newtext); |
981 | THIS->selection.text = sv2wcs (newtext); |
934 | THIS->selection.len = wcslen (THIS->selection.text); |
982 | THIS->selection.len = wcslen (THIS->selection.text); |
935 | } |
983 | } |
|
|
984 | } |
|
|
985 | |
|
|
986 | void |
|
|
987 | rxvt_term::scr_add_lines (SV *string) |
|
|
988 | CODE: |
|
|
989 | { |
|
|
990 | wchar_t *wstr = sv2wcs (string); |
|
|
991 | int wlen = wcslen (wstr); |
|
|
992 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
993 | int nlines = 0; |
|
|
994 | |
|
|
995 | for (int i = wlen; i--; ) |
|
|
996 | { |
|
|
997 | ustr [i] = wstr [i]; |
|
|
998 | nlines += ustr [i] == '\012'; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | THIS->scr_add_lines (ustr, nlines, wlen); |
|
|
1002 | |
|
|
1003 | free (wstr); |
|
|
1004 | delete [] ustr; |
936 | } |
1005 | } |
937 | |
1006 | |
938 | void |
1007 | void |
939 | rxvt_term::tt_write (SV *octets) |
1008 | rxvt_term::tt_write (SV *octets) |
940 | INIT: |
1009 | INIT: |
941 | STRLEN len; |
1010 | STRLEN len; |
942 | char *str = SvPVbyte (octets, len); |
1011 | char *str = SvPVbyte (octets, len); |
943 | C_ARGS: |
1012 | C_ARGS: |
944 | str, len |
1013 | str, len |
945 | |
1014 | |
|
|
1015 | void |
|
|
1016 | rxvt_term::cmd_parse (SV *octets) |
|
|
1017 | CODE: |
|
|
1018 | { |
|
|
1019 | STRLEN len; |
|
|
1020 | char *str = SvPVbyte (octets, len); |
|
|
1021 | |
|
|
1022 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1023 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1024 | |
|
|
1025 | THIS->cmdbuf_ptr = str; |
|
|
1026 | THIS->cmdbuf_endp = str + len; |
|
|
1027 | |
|
|
1028 | THIS->cmd_parse (); |
|
|
1029 | |
|
|
1030 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1031 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1032 | } |
|
|
1033 | |
946 | SV * |
1034 | SV * |
947 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1035 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
948 | CODE: |
1036 | CODE: |
949 | { |
1037 | { |
950 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1038 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |