1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtperl.xs |
2 | * File: rxvtperl.xs |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2005 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
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 | |
… | |
… | |
215 | h += 2; |
227 | h += 2; |
216 | } |
228 | } |
217 | |
229 | |
218 | text = new text_t *[h]; |
230 | text = new text_t *[h]; |
219 | rend = new rend_t *[h]; |
231 | rend = new rend_t *[h]; |
220 | |
232 | |
221 | for (int y = 0; y < h; y++) |
233 | for (int y = 0; y < h; y++) |
222 | { |
234 | { |
223 | text_t *tp = text[y] = new text_t[w]; |
235 | text_t *tp = text[y] = new text_t[w]; |
224 | rend_t *rp = rend[y] = new rend_t[w]; |
236 | rend_t *rp = rend[y] = new rend_t[w]; |
225 | |
237 | |
226 | text_t t0, t1, t2; |
238 | text_t t0, t1, t2; |
227 | rend_t r = rstyle; |
239 | rend_t r = rstyle; |
228 | |
240 | |
229 | if (border == 2) |
241 | if (border == 2) |
230 | { |
242 | { |
231 | if (y == 0) |
243 | if (y == 0) |
232 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
244 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
233 | else if (y < h - 1) |
245 | else if (y < h - 1) |
234 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
246 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
235 | else |
247 | else |
236 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
248 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
237 | |
249 | |
238 | *tp++ = t0; |
250 | *tp++ = t0; |
239 | *rp++ = r; |
251 | *rp++ = r; |
240 | |
252 | |
241 | for (int x = w - 2; x-- > 0; ) |
253 | for (int x = w - 2; x-- > 0; ) |
242 | { |
254 | { |
243 | *tp++ = t1; |
255 | *tp++ = t1; |
244 | *rp++ = r; |
256 | *rp++ = r; |
245 | } |
257 | } |
246 | |
258 | |
247 | *tp = t2; |
259 | *tp = t2; |
248 | *rp = r; |
260 | *rp = r; |
249 | } |
261 | } |
250 | else |
262 | else |
251 | for (int x = w; x-- > 0; ) |
263 | for (int x = w; x-- > 0; ) |
252 | { |
264 | { |
253 | *tp++ = 0x0020; |
265 | *tp++ = 0x0020; |
254 | *rp++ = r; |
266 | *rp++ = r; |
255 | } |
267 | } |
256 | } |
268 | } |
257 | |
269 | |
258 | show (); |
270 | show (); |
259 | THIS->want_refresh = 1; |
271 | THIS->want_refresh = 1; |
260 | } |
272 | } |
261 | |
273 | |
… | |
… | |
308 | |
320 | |
309 | for (int y = ov_h; y--; ) |
321 | for (int y = ov_h; y--; ) |
310 | { |
322 | { |
311 | text_t *t1 = text [y]; |
323 | text_t *t1 = text [y]; |
312 | rend_t *r1 = rend [y]; |
324 | rend_t *r1 = rend [y]; |
313 | |
325 | |
314 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
326 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
315 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
327 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
316 | |
328 | |
317 | for (int x = ov_w; x--; ) |
329 | for (int x = ov_w; x--; ) |
318 | { |
330 | { |
319 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
331 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
320 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
332 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
321 | } |
333 | } |
322 | } |
334 | } |
323 | |
335 | |
… | |
… | |
333 | |
345 | |
334 | wchar_t *wtext = sv2wcs (text); |
346 | wchar_t *wtext = sv2wcs (text); |
335 | |
347 | |
336 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
348 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
337 | this->text [y][x + col] = wtext [col]; |
349 | this->text [y][x + col] = wtext [col]; |
338 | |
350 | |
339 | free (wtext); |
351 | free (wtext); |
340 | |
352 | |
341 | if (rend) |
353 | if (rend) |
342 | { |
354 | { |
343 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
355 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
… | |
… | |
400 | bool |
412 | bool |
401 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
402 | { |
414 | { |
403 | if (!perl) |
415 | if (!perl) |
404 | return false; |
416 | return false; |
405 | |
417 | |
406 | if (htype == HOOK_INIT) // first hook ever called |
418 | if (htype == HOOK_INIT) // first hook ever called |
407 | { |
419 | { |
408 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
409 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
410 | } |
422 | } |
… | |
… | |
453 | |
465 | |
454 | case DT_LONG: |
466 | case DT_LONG: |
455 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
456 | break; |
468 | break; |
457 | |
469 | |
458 | case DT_STRING: |
470 | case DT_STR: |
459 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
472 | break; |
|
|
473 | |
|
|
474 | case DT_STR_LEN: |
|
|
475 | { |
|
|
476 | char *str = va_arg (ap, char *); |
|
|
477 | int len = va_arg (ap, int); |
|
|
478 | |
|
|
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
480 | } |
|
|
481 | break; |
|
|
482 | |
|
|
483 | case DT_WCS_LEN: |
|
|
484 | { |
|
|
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
486 | int wlen = va_arg (ap, int); |
|
|
487 | |
|
|
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
489 | } |
|
|
490 | break; |
|
|
491 | |
|
|
492 | case DT_XEVENT: |
|
|
493 | { |
|
|
494 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
495 | HV *hv = newHV (); |
|
|
496 | |
|
|
497 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
498 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
499 | # undef set |
|
|
500 | |
|
|
501 | setiv (type, xe->type); |
|
|
502 | setiv (send_event, xe->xany.send_event); |
|
|
503 | setiv (serial, xe->xany.serial); |
|
|
504 | |
|
|
505 | switch (xe->type) |
|
|
506 | { |
|
|
507 | case KeyPress: |
|
|
508 | case KeyRelease: |
|
|
509 | case ButtonPress: |
|
|
510 | case ButtonRelease: |
|
|
511 | case MotionNotify: |
|
|
512 | setiv (time, xe->xmotion.time); |
|
|
513 | setiv (x, xe->xmotion.x); |
|
|
514 | setiv (y, xe->xmotion.y); |
|
|
515 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
516 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
517 | setiv (x_root, xe->xmotion.x_root); |
|
|
518 | setiv (y_root, xe->xmotion.y_root); |
|
|
519 | setiv (state, xe->xmotion.state); |
|
|
520 | break; |
|
|
521 | } |
|
|
522 | |
|
|
523 | switch (xe->type) |
|
|
524 | { |
|
|
525 | case KeyPress: |
|
|
526 | case KeyRelease: |
|
|
527 | setiv (keycode, xe->xkey.keycode); |
|
|
528 | break; |
|
|
529 | |
|
|
530 | case ButtonPress: |
|
|
531 | case ButtonRelease: |
|
|
532 | setiv (button, xe->xbutton.button); |
|
|
533 | break; |
|
|
534 | |
|
|
535 | case MotionNotify: |
|
|
536 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
537 | break; |
|
|
538 | } |
|
|
539 | |
|
|
540 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
541 | } |
460 | break; |
542 | break; |
461 | |
543 | |
462 | case DT_END: |
544 | case DT_END: |
463 | { |
545 | { |
464 | va_end (ap); |
546 | va_end (ap); |
… | |
… | |
518 | export_const (RS_Uline); |
600 | export_const (RS_Uline); |
519 | |
601 | |
520 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
602 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
521 | } |
603 | } |
522 | |
604 | |
|
|
605 | SV * |
|
|
606 | new (...) |
|
|
607 | CODE: |
|
|
608 | { |
|
|
609 | stringvec *argv = new stringvec; |
|
|
610 | bool success; |
|
|
611 | |
|
|
612 | for (int i = 0; i < items ;i++) |
|
|
613 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
614 | |
|
|
615 | rxvt_term *term = new rxvt_term; |
|
|
616 | |
|
|
617 | term->argv = argv; |
|
|
618 | |
|
|
619 | try |
|
|
620 | { |
|
|
621 | if (!term->init (argv->size (), argv->begin ())) |
|
|
622 | term = 0; |
|
|
623 | } |
|
|
624 | catch (const class rxvt_failure_exception &e) |
|
|
625 | { |
|
|
626 | term->destroy (); |
|
|
627 | croak ("exception caught while initializing new terminal instance"); |
|
|
628 | } |
|
|
629 | |
|
|
630 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
631 | } |
|
|
632 | OUTPUT: |
|
|
633 | RETVAL |
|
|
634 | |
523 | void |
635 | void |
524 | set_should_invoke (int htype, int value) |
636 | set_should_invoke (int htype, int value) |
525 | CODE: |
637 | CODE: |
526 | rxvt_perl.should_invoke [htype] = value; |
638 | rxvt_perl.should_invoke [htype] = value; |
527 | |
639 | |
… | |
… | |
589 | } |
701 | } |
590 | OUTPUT: |
702 | OUTPUT: |
591 | RETVAL |
703 | RETVAL |
592 | |
704 | |
593 | MODULE = urxvt PACKAGE = urxvt::term |
705 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
706 | |
|
|
707 | void |
|
|
708 | rxvt_term::destroy () |
594 | |
709 | |
595 | int |
710 | int |
596 | rxvt_term::strwidth (SV *str) |
711 | rxvt_term::strwidth (SV *str) |
597 | CODE: |
712 | CODE: |
598 | { |
713 | { |
… | |
… | |
634 | |
749 | |
635 | rxvt_push_locale (THIS->locale); |
750 | rxvt_push_locale (THIS->locale); |
636 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
751 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
637 | rxvt_pop_locale (); |
752 | rxvt_pop_locale (); |
638 | |
753 | |
639 | char *str = rxvt_wcstoutf8 (wstr); |
754 | RETVAL = wcs2sv (wstr); |
640 | free (wstr); |
755 | free (wstr); |
641 | |
|
|
642 | RETVAL = newSVpv (str, 0); |
|
|
643 | SvUTF8_on (RETVAL); |
|
|
644 | free (str); |
|
|
645 | } |
756 | } |
646 | OUTPUT: |
757 | OUTPUT: |
647 | RETVAL |
758 | RETVAL |
648 | |
759 | |
|
|
760 | # very portable, especially on objects as opposed to pods |
|
|
761 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
762 | |
|
|
763 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
764 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
765 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
766 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
767 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
768 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
769 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
770 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
771 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
772 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
773 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
774 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
|
|
775 | |
649 | int |
776 | int |
|
|
777 | rxvt_term::width () |
|
|
778 | ALIAS: |
|
|
779 | width = TERM_OFFSET_width |
|
|
780 | height = TERM_OFFSET_height |
|
|
781 | fwidth = TERM_OFFSET_fwidth |
|
|
782 | fheight = TERM_OFFSET_fheight |
|
|
783 | fbase = TERM_OFFSET_fbase |
|
|
784 | nrow = TERM_OFFSET_nrow |
|
|
785 | ncol = TERM_OFFSET_ncol |
|
|
786 | focus = TERM_OFFSET_focus |
|
|
787 | mapped = TERM_OFFSET_mapped |
|
|
788 | saveLines = TERM_OFFSET_saveLines |
|
|
789 | total_rows = TERM_OFFSET_total_rows |
|
|
790 | nsaved = TERM_OFFSET_nsaved |
|
|
791 | CODE: |
|
|
792 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
793 | OUTPUT: |
|
|
794 | RETVAL |
|
|
795 | |
|
|
796 | U32 |
|
|
797 | rxvt_term::parent () |
|
|
798 | CODE: |
|
|
799 | RETVAL = (U32)THIS->parent [0]; |
|
|
800 | OUTPUT: |
|
|
801 | RETVAL |
|
|
802 | |
|
|
803 | U32 |
650 | rxvt_term::nsaved () |
804 | rxvt_term::vt () |
651 | CODE: |
805 | CODE: |
|
|
806 | RETVAL = (U32)THIS->vt; |
|
|
807 | OUTPUT: |
|
|
808 | RETVAL |
|
|
809 | |
|
|
810 | U32 |
|
|
811 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
812 | CODE: |
|
|
813 | { |
652 | RETVAL = THIS->nsaved; |
814 | RETVAL = THIS->rstyle; |
|
|
815 | THIS->rstyle = new_rstyle; |
|
|
816 | } |
653 | OUTPUT: |
817 | OUTPUT: |
654 | RETVAL |
818 | RETVAL |
655 | |
819 | |
656 | int |
820 | int |
657 | rxvt_term::view_start (int newval = -1) |
821 | rxvt_term::view_start (int newval = -1) |
658 | CODE: |
822 | CODE: |
659 | { |
823 | { |
… | |
… | |
666 | } |
830 | } |
667 | } |
831 | } |
668 | OUTPUT: |
832 | OUTPUT: |
669 | RETVAL |
833 | RETVAL |
670 | |
834 | |
671 | int |
|
|
672 | rxvt_term::nrow () |
|
|
673 | CODE: |
|
|
674 | RETVAL = THIS->nrow; |
|
|
675 | OUTPUT: |
|
|
676 | RETVAL |
|
|
677 | |
|
|
678 | int |
|
|
679 | rxvt_term::ncol () |
|
|
680 | CODE: |
|
|
681 | RETVAL = THIS->ncol; |
|
|
682 | OUTPUT: |
|
|
683 | RETVAL |
|
|
684 | |
|
|
685 | void |
835 | void |
686 | rxvt_term::want_refresh () |
836 | rxvt_term::want_refresh () |
687 | CODE: |
837 | CODE: |
688 | THIS->want_refresh = 1; |
838 | THIS->want_refresh = 1; |
689 | |
839 | |
690 | void |
840 | void |
691 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
841 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
692 | PPCODE: |
842 | PPCODE: |
693 | { |
843 | { |
694 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
844 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
695 | XSRETURN_EMPTY; |
845 | XSRETURN_EMPTY; |
696 | |
846 | |
… | |
… | |
698 | |
848 | |
699 | if (GIMME_V != G_VOID) |
849 | if (GIMME_V != G_VOID) |
700 | { |
850 | { |
701 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
851 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
702 | |
852 | |
703 | for (int col = 0; col <THIS->ncol; col++) |
853 | for (int col = 0; col < THIS->ncol; col++) |
704 | wstr [col] = l.t [col]; |
854 | wstr [col] = l.t [col]; |
705 | |
855 | |
706 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
|
|
707 | free (wstr); |
|
|
708 | |
|
|
709 | SV *sv = newSVpv (str, 0); |
|
|
710 | SvUTF8_on (sv); |
|
|
711 | XPUSHs (sv_2mortal (sv)); |
856 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
712 | free (str); |
857 | |
|
|
858 | delete [] wstr; |
713 | } |
859 | } |
714 | |
860 | |
715 | if (new_text) |
861 | if (new_text) |
716 | { |
862 | { |
717 | wchar_t *wstr = sv2wcs (new_text); |
863 | wchar_t *wstr = sv2wcs (new_text); |
718 | |
864 | |
719 | int len = wcslen (wstr); |
865 | int len = min (wcslen (wstr) - start_ofs, max_len); |
720 | |
866 | |
721 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
867 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
722 | { |
868 | { |
723 | free (wstr); |
869 | free (wstr); |
724 | croak ("new_text extends beyond horizontal margins"); |
870 | croak ("new_text extends beyond horizontal margins"); |
725 | } |
871 | } |
726 | |
872 | |
727 | for (int col = start_col; col < start_col + len; col++) |
873 | for (int col = start_col; col < start_col + len; col++) |
728 | { |
874 | { |
729 | l.t [col] = wstr [col - start_col]; |
875 | l.t [col] = wstr [start_ofs + col - start_col]; |
730 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
876 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
731 | } |
877 | } |
732 | |
878 | |
733 | free (wstr); |
879 | free (wstr); |
734 | } |
880 | } |
735 | } |
881 | } |
736 | |
882 | |
737 | void |
883 | void |
738 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
884 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
739 | PPCODE: |
885 | PPCODE: |
740 | { |
886 | { |
741 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
887 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
742 | XSRETURN_EMPTY; |
888 | XSRETURN_EMPTY; |
743 | |
889 | |
… | |
… | |
758 | { |
904 | { |
759 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
905 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
760 | croak ("new_rend must be arrayref"); |
906 | croak ("new_rend must be arrayref"); |
761 | |
907 | |
762 | AV *av = (AV *)SvRV (new_rend); |
908 | AV *av = (AV *)SvRV (new_rend); |
763 | int len = av_len (av) + 1; |
909 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
764 | |
910 | |
765 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
911 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
766 | croak ("new_rend array extends beyond horizontal margins"); |
912 | croak ("new_rend array extends beyond horizontal margins"); |
767 | |
913 | |
768 | for (int col = start_col; col < start_col + len; col++) |
914 | for (int col = start_col; col < start_col + len; col++) |
769 | { |
915 | { |
770 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
916 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
771 | |
917 | |
772 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
918 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
773 | } |
919 | } |
774 | } |
920 | } |
775 | } |
921 | } |
776 | |
922 | |
777 | int |
923 | int |
778 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
924 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
779 | CODE: |
925 | CODE: |
780 | { |
926 | { |
781 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
927 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
782 | XSRETURN_EMPTY; |
928 | XSRETURN_EMPTY; |
783 | |
929 | |
784 | line_t &l = ROW(row_number); |
930 | line_t &l = ROW(row_number); |
785 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
931 | RETVAL = l.l; |
786 | |
932 | |
787 | if (new_length >= -1) |
933 | if (new_length >= 0) |
788 | l.l = new_length; |
934 | l.l = new_length; |
789 | } |
935 | } |
790 | OUTPUT: |
936 | OUTPUT: |
791 | RETVAL |
937 | RETVAL |
792 | |
938 | |
793 | bool |
939 | bool |
794 | rxvt_term::ROW_is_longer (int row_number) |
940 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
795 | CODE: |
941 | CODE: |
796 | { |
942 | { |
797 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
943 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
798 | XSRETURN_EMPTY; |
944 | XSRETURN_EMPTY; |
799 | |
945 | |
800 | line_t &l = ROW(row_number); |
946 | line_t &l = ROW(row_number); |
801 | RETVAL = l.l < 0; |
947 | RETVAL = l.is_longer (); |
|
|
948 | |
|
|
949 | if (new_is_longer >= 0) |
|
|
950 | l.is_longer (new_is_longer); |
802 | } |
951 | } |
803 | OUTPUT: |
952 | OUTPUT: |
804 | RETVAL |
953 | RETVAL |
805 | |
954 | |
806 | SV * |
955 | SV * |
807 | rxvt_term::special_encode (SV *str) |
956 | rxvt_term::special_encode (SV *string) |
808 | CODE: |
957 | CODE: |
809 | abort ();//TODO |
958 | { |
|
|
959 | wchar_t *wstr = sv2wcs (string); |
|
|
960 | int wlen = wcslen (wstr); |
|
|
961 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
962 | |
|
|
963 | rxvt_push_locale (THIS->locale); |
|
|
964 | |
|
|
965 | wchar_t *r = rstr; |
|
|
966 | for (wchar_t *s = wstr; *s; s++) |
|
|
967 | if (wcwidth (*s) == 0) |
|
|
968 | { |
|
|
969 | if (r == rstr) |
|
|
970 | croak ("leading combining character unencodable"); |
|
|
971 | |
|
|
972 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
973 | if (n == NOCHAR) |
|
|
974 | n = rxvt_composite.compose (r[-1], *s); |
|
|
975 | |
|
|
976 | r[-1] = n; |
|
|
977 | } |
|
|
978 | #if !UNICODE_3 |
|
|
979 | else if (*s >= 0x10000) |
|
|
980 | *r++ = rxvt_composite.compose (*s); |
|
|
981 | #endif |
|
|
982 | else |
|
|
983 | *r++ = *s; |
|
|
984 | |
|
|
985 | rxvt_pop_locale (); |
|
|
986 | |
|
|
987 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
988 | |
|
|
989 | delete [] rstr; |
|
|
990 | } |
|
|
991 | OUTPUT: |
|
|
992 | RETVAL |
810 | |
993 | |
811 | SV * |
994 | SV * |
812 | rxvt_term::special_decode (SV *str) |
995 | rxvt_term::special_decode (SV *text) |
813 | CODE: |
996 | CODE: |
814 | abort ();//TODO |
997 | { |
|
|
998 | wchar_t *wstr = sv2wcs (text); |
|
|
999 | int wlen = wcslen (wstr); |
|
|
1000 | int dlen = 0; |
|
|
1001 | |
|
|
1002 | // find length |
|
|
1003 | for (wchar_t *s = wstr; *s; s++) |
|
|
1004 | if (*s == NOCHAR) |
|
|
1005 | ; |
|
|
1006 | else if (IS_COMPOSE (*s)) |
|
|
1007 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1008 | else |
|
|
1009 | dlen++; |
|
|
1010 | |
|
|
1011 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1012 | |
|
|
1013 | // decode |
|
|
1014 | wchar_t *r = rstr; |
|
|
1015 | for (wchar_t *s = wstr; *s; s++) |
|
|
1016 | if (*s == NOCHAR) |
|
|
1017 | ; |
|
|
1018 | else if (IS_COMPOSE (*s)) |
|
|
1019 | r += rxvt_composite.expand (*s, r); |
|
|
1020 | else |
|
|
1021 | *r++ = *s; |
|
|
1022 | |
|
|
1023 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1024 | |
|
|
1025 | delete [] rstr; |
|
|
1026 | } |
|
|
1027 | OUTPUT: |
|
|
1028 | RETVAL |
815 | |
1029 | |
816 | void |
1030 | void |
817 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1031 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
818 | PPCODE: |
1032 | PPCODE: |
819 | { |
1033 | { |
… | |
… | |
852 | THIS->rs [index] = 0; |
1066 | THIS->rs [index] = 0; |
853 | } |
1067 | } |
854 | } |
1068 | } |
855 | |
1069 | |
856 | void |
1070 | void |
857 | rxvt_term::selection_mark (...) |
1071 | rxvt_term::cur (...) |
858 | PROTOTYPE: $;$$ |
1072 | PROTOTYPE: $;$$ |
859 | ALIAS: |
1073 | ALIAS: |
|
|
1074 | screen_cur = 0 |
860 | selection_beg = 1 |
1075 | selection_beg = 1 |
861 | selection_end = 2 |
1076 | selection_end = 2 |
|
|
1077 | selection_mark = 3 |
862 | PPCODE: |
1078 | PPCODE: |
863 | { |
1079 | { |
864 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1080 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1081 | : ix == 1 ? THIS->selection.beg |
865 | : ix == 2 ? THIS->selection.end |
1082 | : ix == 2 ? THIS->selection.end |
866 | : THIS->selection.mark; |
1083 | : THIS->selection.mark; |
867 | |
1084 | |
868 | if (GIMME_V != G_VOID) |
1085 | if (GIMME_V != G_VOID) |
869 | { |
1086 | { |
870 | EXTEND (SP, 2); |
1087 | EXTEND (SP, 2); |
871 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1088 | PUSHs (sv_2mortal (newSViv (rc.row))); |
872 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1089 | PUSHs (sv_2mortal (newSViv (rc.col))); |
873 | } |
1090 | } |
874 | |
1091 | |
875 | if (items == 3) |
1092 | if (items == 3) |
876 | { |
1093 | { |
877 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1094 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
878 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1095 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
879 | |
1096 | |
880 | if (ix) |
1097 | if (ix) |
881 | THIS->want_refresh = 1; |
1098 | THIS->want_refresh = 1; |
882 | } |
1099 | } |
883 | } |
1100 | } |
… | |
… | |
888 | void |
1105 | void |
889 | rxvt_term::selection (SV *newtext = 0) |
1106 | rxvt_term::selection (SV *newtext = 0) |
890 | PPCODE: |
1107 | PPCODE: |
891 | { |
1108 | { |
892 | if (GIMME_V != G_VOID) |
1109 | if (GIMME_V != G_VOID) |
893 | { |
1110 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
894 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
|
|
895 | SV *sv = newSVpv (sel, 0); |
|
|
896 | SvUTF8_on (sv); |
|
|
897 | free (sel); |
|
|
898 | XPUSHs (sv_2mortal (sv)); |
|
|
899 | } |
|
|
900 | |
1111 | |
901 | if (newtext) |
1112 | if (newtext) |
902 | { |
1113 | { |
903 | free (THIS->selection.text); |
1114 | free (THIS->selection.text); |
904 | |
1115 | |
905 | THIS->selection.text = sv2wcs (newtext); |
1116 | THIS->selection.text = sv2wcs (newtext); |
906 | THIS->selection.len = wcslen (THIS->selection.text); |
1117 | THIS->selection.len = wcslen (THIS->selection.text); |
907 | } |
1118 | } |
908 | } |
1119 | } |
909 | |
1120 | |
|
|
1121 | void |
|
|
1122 | rxvt_term::scr_add_lines (SV *string) |
|
|
1123 | CODE: |
|
|
1124 | { |
|
|
1125 | wchar_t *wstr = sv2wcs (string); |
|
|
1126 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
|
|
1127 | free (wstr); |
|
|
1128 | } |
|
|
1129 | |
910 | void |
1130 | void |
911 | rxvt_term::tt_write (SV *octets) |
1131 | rxvt_term::tt_write (SV *octets) |
912 | INIT: |
1132 | INIT: |
913 | STRLEN len; |
1133 | STRLEN len; |
914 | char *str = SvPVbyte (octets, len); |
1134 | char *str = SvPVbyte (octets, len); |
915 | C_ARGS: |
1135 | C_ARGS: |
916 | str, len |
1136 | str, len |
917 | |
1137 | |
|
|
1138 | void |
|
|
1139 | rxvt_term::cmd_parse (SV *octets) |
|
|
1140 | CODE: |
|
|
1141 | { |
|
|
1142 | STRLEN len; |
|
|
1143 | char *str = SvPVbyte (octets, len); |
|
|
1144 | |
|
|
1145 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1146 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1147 | |
|
|
1148 | THIS->cmdbuf_ptr = str; |
|
|
1149 | THIS->cmdbuf_endp = str + len; |
|
|
1150 | |
|
|
1151 | THIS->cmd_parse (); |
|
|
1152 | |
|
|
1153 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1154 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1155 | } |
|
|
1156 | |
918 | SV * |
1157 | SV * |
919 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1158 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
920 | CODE: |
1159 | CODE: |
921 | { |
1160 | { |
922 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1161 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |