summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-06-28 23:37:04 +0200
committerBoris Faure <billiob@gmail.com>2015-08-03 20:44:55 +0200
commit35c8fd79c014c4f51a23585f6f445f16bf165798 (patch)
tree1916d119318bd7437edf38224e6b6405870a5696 /src
parent34592ab5b3e01e473355c9cc0f370cee0731c40c (diff)
speed up browsing backlog
have a "beacon": single point where the link between an offset in the backlog and one in screen coordinates
Diffstat (limited to 'src')
-rw-r--r--src/bin/miniview.c8
-rw-r--r--src/bin/termio.c1
-rw-r--r--src/bin/termpty.c221
-rw-r--r--src/bin/termpty.h16
-rw-r--r--src/bin/termptyops.c3
5 files changed, 168 insertions, 81 deletions
diff --git a/src/bin/miniview.c b/src/bin/miniview.c
index 90b3477..477a7e9 100644
--- a/src/bin/miniview.c
+++ b/src/bin/miniview.c
@@ -140,11 +140,12 @@ Eina_Bool
140_is_top_bottom_reached(Miniview *mv) 140_is_top_bottom_reached(Miniview *mv)
141{ 141{
142 int history_len; 142 int history_len;
143 Termpty *ty;
143 144
144 EINA_SAFETY_ON_NULL_RETURN_VAL(mv, EINA_FALSE); 145 EINA_SAFETY_ON_NULL_RETURN_VAL(mv, EINA_FALSE);
145 146
146 /* TODO: RESIZE */ 147 ty = termio_pty_get(mv->termio);
147 history_len = 42; //termpty_backscroll_len_get(ty); 148 history_len = termpty_backscroll_length(ty);
148 149
149 if (( (- mv->img_hist) > (int)(mv->img_h - mv->rows - (mv->rows / 2))) && 150 if (( (- mv->img_hist) > (int)(mv->img_h - mv->rows - (mv->rows / 2))) &&
150 ( (- mv->img_hist) < (int)(history_len + (mv->rows / 2)))) 151 ( (- mv->img_hist) < (int)(history_len + (mv->rows / 2))))
@@ -522,8 +523,7 @@ _deferred_renderer(void *data)
522 evas_object_geometry_get(mv->termio, &ox, &oy, &ow, &oh); 523 evas_object_geometry_get(mv->termio, &ox, &oy, &ow, &oh);
523 if ((ow == 0) || (oh == 0)) return EINA_TRUE; 524 if ((ow == 0) || (oh == 0)) return EINA_TRUE;
524 525
525 /* TODO: RESIZE */ 526 history_len = termpty_backscroll_length(ty);
526 history_len = 42; //termpty_backscroll_len_get(ty);
527 527
528 evas_object_image_size_set(mv->img, mv->cols, mv->img_h); 528 evas_object_image_size_set(mv->img, mv->cols, mv->img_h);
529 ow = mv->cols; 529 ow = mv->cols;
diff --git a/src/bin/termio.c b/src/bin/termio.c
index c964079..c85fcca 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2041,7 +2041,6 @@ termio_selection_get(Evas_Object *obj, int c1x, int c1y, int c2x, int c2y,
2041 2041
2042 EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL); 2042 EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
2043 termpty_cellcomp_freeze(sd->pty); 2043 termpty_cellcomp_freeze(sd->pty);
2044 /* TODO: RESIZE use/save the reference point */
2045 for (y = c1y; y <= c2y; y++) 2044 for (y = c1y; y <= c2y; y++)
2046 { 2045 {
2047 Termcell *cells; 2046 Termcell *cells;
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 9a0a143..b72510d 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -626,7 +626,49 @@ termpty_line_length(const Termcell *cells, ssize_t nb_cells)
626} 626}
627 627
628#define BACKLOG_ROW_GET(Ty, Y) \ 628#define BACKLOG_ROW_GET(Ty, Y) \
629 (&Ty->back[(Ty->backsize + ty->backpos - (Y)) % Ty->backsize]) 629 (&Ty->back[(Ty->backsize + ty->backpos - ((Y) - 1 )) % Ty->backsize])
630
631
632#if 0
633static void
634verify_beacon(Termpty *ty)
635{
636 Termsave *ts;
637 int nb_lines;
638 int backlog_y = ty->backlog_beacon.backlog_y;
639 int screen_y = ty->backlog_beacon.screen_y;
640
641 assert(ty->backlog_beacon.screen_y >= 0);
642 assert(ty->backlog_beacon.backlog_y >= 0);
643 assert(ty->backlog_beacon.screen_y >= ty->backlog_beacon.backlog_y);
644
645 //ERR("FROM screen_y:%d backlog_y:%d",
646 // screen_y, backlog_y);
647 while (backlog_y > 0)
648 {
649 ts = BACKLOG_ROW_GET(ty, backlog_y);
650 if (!ts->cells)
651 {
652 ERR("went too far: screen_y:%d backlog_y:%d",
653 screen_y, backlog_y);
654 return;
655 }
656
657 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
658 screen_y -= nb_lines;
659 backlog_y--;
660 //ERR("nb_lines:%d screen_y:%d backlog_y:%d ts->w:%d ty->w:%d",
661 // nb_lines, screen_y, backlog_y, ts->w, ty->w);
662 assert(screen_y >= backlog_y);
663
664 }
665 //ERR("TO screen_y:%d backlog_y:%d",
666 // screen_y, backlog_y);
667 assert (backlog_y == 0);
668 assert (screen_y == 0);
669}
670#endif
671
630 672
631void 673void
632termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max) 674termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
@@ -643,19 +685,22 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
643 w = termpty_line_length(cells, w_max); 685 w = termpty_line_length(cells, w_max);
644 if (ty->backsize >= 1) 686 if (ty->backsize >= 1)
645 { 687 {
646 ts = BACKLOG_ROW_GET(ty, 0); 688 ts = BACKLOG_ROW_GET(ty, 1);
647 if (!ts->cells) 689 if (!ts->cells)
648 goto add_new_ts; 690 goto add_new_ts;
649 /* TODO: RESIZE uncompress ? */ 691 /* TODO: RESIZE uncompress ? */
650 if (ts->w && ts->cells[ts->w - 1].att.autowrapped) 692 if (ts->w && ts->cells[ts->w - 1].att.autowrapped)
651 { 693 {
694 int old_len = ts->w;
652 termpty_save_expand(ts, cells, w); 695 termpty_save_expand(ts, cells, w);
696 ty->backlog_beacon.screen_y += (ts->w + ty->w - 1) / ty->w
697 - (old_len + ty->w - 1) / ty->w;
653 return; 698 return;
654 } 699 }
655 } 700 }
656 701
657add_new_ts: 702add_new_ts:
658 ts = BACKLOG_ROW_GET(ty, -1); 703 ts = BACKLOG_ROW_GET(ty, 0);
659 ts = termpty_save_new(ts, w); 704 ts = termpty_save_new(ts, w);
660 if (!ts) 705 if (!ts)
661 return; 706 return;
@@ -664,6 +709,14 @@ add_new_ts:
664 if (ty->backpos >= ty->backsize) 709 if (ty->backpos >= ty->backsize)
665 ty->backpos = 0; 710 ty->backpos = 0;
666 termpty_save_thaw(); 711 termpty_save_thaw();
712
713 ty->backlog_beacon.screen_y++;
714 ty->backlog_beacon.backlog_y++;
715 if (ty->backlog_beacon.backlog_y >= ty->backsize)
716 {
717 ty->backlog_beacon.screen_y = 0;
718 ty->backlog_beacon.backlog_y = 0;
719 }
667} 720}
668 721
669 722
@@ -677,7 +730,7 @@ termpty_row_length(Termpty *ty, int y)
677 Termcell *cells; 730 Termcell *cells;
678 if (y >= ty->h) 731 if (y >= ty->h)
679 { 732 {
680 ERR("invalid row given"); 733 ERR("invalid row given: %d while ty->h=%d", y, ty->h);
681 return 0; 734 return 0;
682 } 735 }
683 cells = &(TERMPTY_SCREEN(ty, 0, y)); 736 cells = &(TERMPTY_SCREEN(ty, 0, y));
@@ -685,7 +738,8 @@ termpty_row_length(Termpty *ty, int y)
685 } 738 }
686 if ((y < -ty->backsize) || !ty->back) 739 if ((y < -ty->backsize) || !ty->back)
687 { 740 {
688 ERR("invalid row given"); 741 ERR("invalid row given: %d; ty->back:%p ty->backsize:%d",
742 y, ty->back, ty->backsize);
689 return 0; 743 return 0;
690 } 744 }
691 ts = BACKLOG_ROW_GET(ty, y); 745 ts = BACKLOG_ROW_GET(ty, y);
@@ -693,104 +747,133 @@ termpty_row_length(Termpty *ty, int y)
693 return ts->cells ? ts->w : 0; 747 return ts->cells ? ts->w : 0;
694} 748}
695 749
696/* TODO: RESIZE reference point */ 750ssize_t
751termpty_backscroll_length(Termpty *ty)
752{
753 int backlog_y = ty->backlog_beacon.backlog_y;
754 int screen_y = ty->backlog_beacon.screen_y;
755
756 if (!ty->backsize)
757 return 0;
758
759 while (42)
760 {
761 int nb_lines;
762 Termsave *ts;
763
764 ts = BACKLOG_ROW_GET(ty, backlog_y);
765 if (!ts->cells || backlog_y >= ty->backsize)
766 return ty->backlog_beacon.screen_y;
767
768 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
769 ty->backlog_beacon.screen_y = screen_y;
770 ty->backlog_beacon.backlog_y = backlog_y;
771 screen_y += nb_lines;
772 backlog_y++;
773 }
774}
697 775
698void 776void
699termpty_backscroll_adjust(Termpty *ty, int *scroll) 777termpty_backscroll_adjust(Termpty *ty, int *scroll)
700{ 778{
701 Termsave *ts; 779 int backlog_y = ty->backlog_beacon.backlog_y;
702 int y; 780 int screen_y = ty->backlog_beacon.screen_y;
703 int screen_y;
704 781
705 if (!ty->backsize || *scroll <= 0) 782 if (!ty->backsize || *scroll <= 0)
706 { 783 {
707 *scroll = 0; 784 *scroll = 0;
708 return; 785 return;
709 } 786 }
710 ERR("ty->backsize:%d ty->backpos:%d *scroll:%d", 787 if (*scroll < screen_y)
711 ty->backsize, ty->backpos, *scroll);
712 /* TODO: RESIZE have a reference point? */
713 y = ty->backsize;
714 do
715 {
716 y--;
717 ts = BACKLOG_ROW_GET(ty, y);
718 }
719 while (!ts->cells);
720 ERR("y:%d", y);
721 if (*scroll <= y)
722 return; 788 return;
723 screen_y = 0; 789
724 while (y >= 0) 790 while (42)
725 { 791 {
726 int nb_lines; 792 int nb_lines;
793 Termsave *ts;
727 794
728 ts = BACKLOG_ROW_GET(ty, y); 795 ts = BACKLOG_ROW_GET(ty, backlog_y);
729 assert(ts != NULL); 796 if (!ts->cells || backlog_y >= ty->backsize)
797 {
798 *scroll = ty->backlog_beacon.screen_y;
799 return;
800 }
730 801
731 nb_lines = (ts->w + ty->w) / ty->w; 802 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
732 ERR("[%d] ts->w:%d ty->w:%d, nb_lines:%d", 803 ty->backlog_beacon.screen_y = screen_y;
733 y, ts->w, ty->w, nb_lines); 804 ty->backlog_beacon.backlog_y = backlog_y;
734 screen_y += nb_lines; 805 screen_y += nb_lines;
735 y--; 806 backlog_y++;
736 } 807 }
737
738 ERR("screen_y:%d", screen_y);
739 *scroll = screen_y;
740} 808}
741 809
742 810static Termcell*
743Termcell * 811_termpty_cellrow_from_beacon_get(Termpty *ty, int requested_y, int *wret)
744termpty_cellrow_get(Termpty *ty, int y_requested, int *wret)
745{ 812{
746 int screen_y = 0; 813 int backlog_y = ty->backlog_beacon.backlog_y;
747 int backlog_y = 0; 814 int screen_y = ty->backlog_beacon.screen_y;
815 Eina_Bool going_forward = EINA_TRUE;
748 816
749 //ERR("y_requested:%d", y_requested); 817 requested_y = -requested_y;
750 if (y_requested >= 0)
751 {
752 if (y_requested >= ty->h)
753 return NULL;
754 *wret = ty->w;
755 return &(TERMPTY_SCREEN(ty, 0, y_requested));
756 }
757 if (!ty->back)
758 return NULL;
759 818
760 y_requested = -y_requested; 819 while (42) {
761 while (backlog_y <= ty->backsize)
762 {
763 Termsave *ts; 820 Termsave *ts;
764 int nb_lines; 821 int nb_lines;
765 822
766 ts = BACKLOG_ROW_GET(ty, backlog_y); 823 ts = BACKLOG_ROW_GET(ty, backlog_y);
824 assert (ts->cells);
767 if (!ts->cells) 825 if (!ts->cells)
768 { 826 {
769 //ERR("went too far: y_requested:%d screen_y:%d backlog_y:%d", 827 ERR("went too far: requested_y:%d screen_y:%d backlog_y:%d",
770 // y_requested, screen_y, backlog_y); 828 requested_y, screen_y, backlog_y);
771 return NULL; 829 return NULL;
772 } 830 }
773 nb_lines = (ts->w + ty->w) / ty->w; 831 nb_lines = (ts->w == 0) ? 1 : (ts->w + ty->w - 1) / ty->w;
774 832 if (!going_forward) {
775 /* TODO: uncompress */ 833 screen_y -= nb_lines;
776 /* TODO: optimize */ 834 }
777 835
778 //ERR("y_requested:%d screen_y:%d nb_lines:%d backlog_y:%d", 836 if ((screen_y <= requested_y) && (requested_y < screen_y + nb_lines))
779 // y_requested, screen_y, nb_lines, backlog_y);
780 if (screen_y + nb_lines >= y_requested)
781 { 837 {
782 int delta = screen_y + nb_lines - y_requested; 838 int delta = screen_y + nb_lines - 1 - requested_y;
783 *wret = ts->w - delta * ty->w; 839 *wret = ts->w - delta * ty->w;
784 if (*wret > ts->w) 840 if (*wret > ts->w)
785 *wret = ts->w; 841 *wret = ts->w;
786 return &ts->cells[delta * ty->w]; 842 return &ts->cells[delta * ty->w];
787 } 843 }
788 screen_y += nb_lines; 844
789 backlog_y++; 845 if (requested_y > screen_y)
790 } 846 {
847 screen_y += nb_lines;
848 backlog_y++;
849 }
850 else
851 {
852 backlog_y--;
853 going_forward = EINA_FALSE;
854 }
855 }
856
791 return NULL; 857 return NULL;
792} 858}
793 859
860Termcell *
861termpty_cellrow_get(Termpty *ty, int y_requested, int *wret)
862{
863 if (y_requested >= 0)
864 {
865 if (y_requested >= ty->h)
866 return NULL;
867 *wret = ty->w;
868 return &(TERMPTY_SCREEN(ty, 0, y_requested));
869 }
870 if (!ty->back)
871 return NULL;
872
873 return _termpty_cellrow_from_beacon_get(ty, y_requested, wret);
874
875}
876
794void 877void
795termpty_write(Termpty *ty, const char *input, int len) 878termpty_write(Termpty *ty, const char *input, int len)
796{ 879{
@@ -822,8 +905,6 @@ _check_screen_info(Termpty *ty, struct screen_info *si)
822 { 905 {
823 Termcell *cells = &SCREEN_INFO_GET_CELLS(si, 0, 0); 906 Termcell *cells = &SCREEN_INFO_GET_CELLS(si, 0, 0);
824 907
825 ERR("adjusting");
826
827 si->y--; 908 si->y--;
828 termpty_text_save_top(ty, cells, si->w); 909 termpty_text_save_top(ty, cells, si->w);
829 termpty_cells_clear(ty, cells, si->w); 910 termpty_cells_clear(ty, cells, si->w);
@@ -843,8 +924,6 @@ _termpty_line_rewrap(Termpty *ty, Termcell *cells, int len,
843{ 924{
844 int autowrapped = cells[len-1].att.autowrapped; 925 int autowrapped = cells[len-1].att.autowrapped;
845 926
846 ERR("si->x:%d si->y:%d si->cx:%d si->cy:%d",
847 si->x, si->y, si->cx, si->cy);
848 if (len == 0) 927 if (len == 0)
849 { 928 {
850 if (set_cursor) 929 if (set_cursor)
@@ -861,7 +940,6 @@ _termpty_line_rewrap(Termpty *ty, Termcell *cells, int len,
861 { 940 {
862 int copy_width = MIN(len, si->w - si->x); 941 int copy_width = MIN(len, si->w - si->x);
863 942
864 ERR("len:%d copy_width:%d", len, copy_width);
865 termpty_cell_copy(ty, 943 termpty_cell_copy(ty,
866 /*src*/ cells, 944 /*src*/ cells,
867 /*dst*/&SCREEN_INFO_GET_CELLS(si, si->x, si->y), 945 /*dst*/&SCREEN_INFO_GET_CELLS(si, si->x, si->y),
@@ -880,7 +958,6 @@ _termpty_line_rewrap(Termpty *ty, Termcell *cells, int len,
880 } 958 }
881 len -= copy_width; 959 len -= copy_width;
882 si->x += copy_width; 960 si->x += copy_width;
883 ERR("si->x:%d si->w:%d", si->x, si->w);
884 if (si->x >= si->w) 961 if (si->x >= si->w)
885 { 962 {
886 si->y++; 963 si->y++;
@@ -888,7 +965,6 @@ _termpty_line_rewrap(Termpty *ty, Termcell *cells, int len,
888 } 965 }
889 _check_screen_info(ty, si); 966 _check_screen_info(ty, si);
890 } 967 }
891 ERR("autowrapped:%d", autowrapped);
892 if (!autowrapped) 968 if (!autowrapped)
893 { 969 {
894 si->y++; 970 si->y++;
@@ -951,7 +1027,6 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
951 int len; 1027 int len;
952 1028
953 len = termpty_line_length(cells, old_w); 1029 len = termpty_line_length(cells, old_w);
954 ERR("[%d] len:%d", old_y, len);
955 _termpty_line_rewrap(ty, cells, len, &new_si, 1030 _termpty_line_rewrap(ty, cells, len, &new_si,
956 old_y == ty->cursor_state.cy); 1031 old_y == ty->cursor_state.cy);
957 } 1032 }
@@ -976,6 +1051,10 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
976 _pty_size(ty); 1051 _pty_size(ty);
977 1052
978 termpty_save_thaw(); 1053 termpty_save_thaw();
1054
1055 ty->backlog_beacon.backlog_y = 0;
1056 ty->backlog_beacon.screen_y = 0;
1057
979 return; 1058 return;
980 1059
981bad: 1060bad:
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 26c5de0..b9b339a 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -99,15 +99,19 @@ struct _Termpty
99 } prop; 99 } prop;
100 const char *cur_cmd; 100 const char *cur_cmd;
101 Termcell *screen, *screen2; 101 Termcell *screen, *screen2;
102 Termsave *back; 102 int circular_offset;
103 unsigned char oldbuf[4]; 103 int circular_offset2;
104 Eina_Unicode *buf; 104 Eina_Unicode *buf;
105 size_t buflen; 105 size_t buflen;
106 unsigned char oldbuf[4];
107 Termsave *back;
108 int backsize, backpos;
109 struct {
110 int screen_y;
111 int backlog_y;
112 } backlog_beacon;
106 int w, h; 113 int w, h;
107 int fd, slavefd; 114 int fd, slavefd;
108 int circular_offset;
109 int circular_offset2;
110 int backsize, backpos;
111 struct { 115 struct {
112 int curid; 116 int curid;
113 Eina_Hash *blocks; 117 Eina_Hash *blocks;
@@ -230,12 +234,14 @@ Termpty *termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
230void termpty_free(Termpty *ty); 234void termpty_free(Termpty *ty);
231void termpty_cellcomp_freeze(Termpty *ty); 235void termpty_cellcomp_freeze(Termpty *ty);
232void termpty_cellcomp_thaw(Termpty *ty); 236void termpty_cellcomp_thaw(Termpty *ty);
237
233Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret); 238Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret);
234ssize_t termpty_row_length(Termpty *ty, int y); 239ssize_t termpty_row_length(Termpty *ty, int y);
235void termpty_write(Termpty *ty, const char *input, int len); 240void termpty_write(Termpty *ty, const char *input, int len);
236void termpty_resize(Termpty *ty, int new_w, int new_h); 241void termpty_resize(Termpty *ty, int new_w, int new_h);
237void termpty_backscroll_set(Termpty *ty, int size); 242void termpty_backscroll_set(Termpty *ty, int size);
238void termpty_backscroll_adjust(Termpty *ty, int *scroll); 243void termpty_backscroll_adjust(Termpty *ty, int *scroll);
244ssize_t termpty_backscroll_length(Termpty *ty);
239 245
240pid_t termpty_pid_get(const Termpty *ty); 246pid_t termpty_pid_get(const Termpty *ty);
241void termpty_block_free(Termblock *tb); 247void termpty_block_free(Termblock *tb);
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 0df51f8..95b8922 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -381,6 +381,9 @@ termpty_reset_state(Termpty *ty)
381 ty->mouse_ext = MOUSE_EXT_NONE; 381 ty->mouse_ext = MOUSE_EXT_NONE;
382 ty->bracketed_paste = 0; 382 ty->bracketed_paste = 0;
383 383
384 ty->backlog_beacon.screen_y = 0;
385 ty->backlog_beacon.backlog_y = 0;
386
384 termpty_save_freeze(); 387 termpty_save_freeze();
385 if (ty->back) 388 if (ty->back)
386 { 389 {