Mercurial > vim
comparison src/libvterm/src/state.c @ 20480:d0bf39eb2b07 v8.2.0794
patch 8.2.0794: libvterm code lags behind the upstream version
Commit: https://github.com/vim/vim/commit/d098b824c10cc20dc55e18c22c4991f61826006e
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon May 18 21:12:59 2020 +0200
patch 8.2.0794: libvterm code lags behind the upstream version
Problem: Libvterm code lags behind the upstream version.
Solution: Include revisions 743 - 747.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 18 May 2020 21:15:04 +0200 |
parents | c15dd3da4f47 |
children | dc88c690f19b |
comparison
equal
deleted
inserted
replaced
20479:c4b13b8932fb | 20480:d0bf39eb2b07 |
---|---|
71 | 71 |
72 vterm_state_newpen(state); | 72 vterm_state_newpen(state); |
73 | 73 |
74 state->bold_is_highbright = 0; | 74 state->bold_is_highbright = 0; |
75 | 75 |
76 state->combine_chars_size = 16; | |
77 state->combine_chars = vterm_allocator_malloc(state->vt, state->combine_chars_size * sizeof(state->combine_chars[0])); | |
78 | |
79 state->tabstops = vterm_allocator_malloc(state->vt, (state->cols + 7) / 8); | |
80 | |
81 state->lineinfos[BUFIDX_PRIMARY] = vterm_allocator_malloc(state->vt, state->rows * sizeof(VTermLineInfo)); | |
82 state->lineinfo = state->lineinfos[BUFIDX_PRIMARY]; | |
83 | |
84 state->encoding_utf8.enc = vterm_lookup_encoding(ENC_UTF8, 'u'); | |
85 if(*state->encoding_utf8.enc->init) | |
86 (*state->encoding_utf8.enc->init)(state->encoding_utf8.enc, state->encoding_utf8.data); | |
87 | |
76 return state; | 88 return state; |
77 } | 89 } |
78 | 90 |
79 INTERNAL void vterm_state_free(VTermState *state) | 91 INTERNAL void vterm_state_free(VTermState *state) |
80 { | 92 { |
81 vterm_allocator_free(state->vt, state->tabstops); | 93 vterm_allocator_free(state->vt, state->tabstops); |
82 vterm_allocator_free(state->vt, state->lineinfo); | 94 vterm_allocator_free(state->vt, state->lineinfos[BUFIDX_PRIMARY]); |
95 if(state->lineinfos[BUFIDX_ALTSCREEN]) | |
96 vterm_allocator_free(state->vt, state->lineinfos[BUFIDX_ALTSCREEN]); | |
83 vterm_allocator_free(state->vt, state->combine_chars); | 97 vterm_allocator_free(state->vt, state->combine_chars); |
84 vterm_allocator_free(state->vt, state); | 98 vterm_allocator_free(state->vt, state); |
85 } | 99 } |
86 | 100 |
87 static void scroll(VTermState *state, VTermRect rect, int downward, int rightward) | 101 static void scroll(VTermState *state, VTermRect rect, int downward, int rightward) |
104 rightward = -cols; | 118 rightward = -cols; |
105 | 119 |
106 // Update lineinfo if full line | 120 // Update lineinfo if full line |
107 if(rect.start_col == 0 && rect.end_col == state->cols && rightward == 0) { | 121 if(rect.start_col == 0 && rect.end_col == state->cols && rightward == 0) { |
108 int height = rect.end_row - rect.start_row - abs(downward); | 122 int height = rect.end_row - rect.start_row - abs(downward); |
109 | 123 int row; |
110 if(downward > 0) | 124 |
125 if(downward > 0) { | |
111 memmove(state->lineinfo + rect.start_row, | 126 memmove(state->lineinfo + rect.start_row, |
112 state->lineinfo + rect.start_row + downward, | 127 state->lineinfo + rect.start_row + downward, |
113 height * sizeof(state->lineinfo[0])); | 128 height * sizeof(state->lineinfo[0])); |
114 else | 129 for(row = rect.end_row - downward; row < rect.end_row; row++) |
130 state->lineinfo[row] = (VTermLineInfo){ 0 }; | |
131 } | |
132 else { | |
115 memmove(state->lineinfo + rect.start_row - downward, | 133 memmove(state->lineinfo + rect.start_row - downward, |
116 state->lineinfo + rect.start_row, | 134 state->lineinfo + rect.start_row, |
117 height * sizeof(state->lineinfo[0])); | 135 height * sizeof(state->lineinfo[0])); |
136 for(row = rect.start_row; row < rect.start_row - downward; row++) | |
137 state->lineinfo[row] = (VTermLineInfo){ 0 }; | |
138 } | |
118 } | 139 } |
119 | 140 |
120 if(state->callbacks && state->callbacks->scrollrect) | 141 if(state->callbacks && state->callbacks->scrollrect) |
121 if((*state->callbacks->scrollrect)(rect, downward, rightward, state->cbdata)) | 142 if((*state->callbacks->scrollrect)(rect, downward, rightward, state->cbdata)) |
122 return; | 143 return; |
1699 | 1720 |
1700 static int on_resize(int rows, int cols, void *user) | 1721 static int on_resize(int rows, int cols, void *user) |
1701 { | 1722 { |
1702 VTermState *state = user; | 1723 VTermState *state = user; |
1703 VTermPos oldpos = state->pos; | 1724 VTermPos oldpos = state->pos; |
1704 VTermPos delta = { 0, 0 }; | 1725 VTermStateFields fields; |
1705 | 1726 |
1706 if(cols != state->cols) { | 1727 if(cols != state->cols) { |
1707 int col; | 1728 int col; |
1708 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8); | 1729 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8); |
1709 if (newtabstops == NULL) | 1730 if (newtabstops == NULL) |
1729 vterm_allocator_free(state->vt, state->tabstops); | 1750 vterm_allocator_free(state->vt, state->tabstops); |
1730 state->tabstops = newtabstops; | 1751 state->tabstops = newtabstops; |
1731 } | 1752 } |
1732 | 1753 |
1733 if(rows != state->rows) { | 1754 if(rows != state->rows) { |
1734 int row; | 1755 for(int bufidx = BUFIDX_PRIMARY; bufidx <= BUFIDX_ALTSCREEN; bufidx++) { |
1735 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); | 1756 int row; |
1736 if (newlineinfo == NULL) | 1757 VTermLineInfo *oldlineinfo = state->lineinfos[bufidx]; |
1737 return 0; | 1758 if(!oldlineinfo) |
1738 | 1759 continue; |
1739 for(row = 0; row < state->rows && row < rows; row++) { | 1760 |
1740 newlineinfo[row] = state->lineinfo[row]; | 1761 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); |
1741 } | 1762 |
1742 | 1763 for(row = 0; row < state->rows && row < rows; row++) { |
1743 for( ; row < rows; row++) { | 1764 newlineinfo[row] = oldlineinfo[row]; |
1744 newlineinfo[row].doublewidth = 0; | 1765 } |
1745 newlineinfo[row].doubleheight = 0; | 1766 |
1746 } | 1767 for( ; row < rows; row++) { |
1747 | 1768 newlineinfo[row] = (VTermLineInfo){ |
1748 vterm_allocator_free(state->vt, state->lineinfo); | 1769 .doublewidth = 0, |
1749 state->lineinfo = newlineinfo; | 1770 }; |
1771 } | |
1772 | |
1773 vterm_allocator_free(state->vt, state->lineinfos[bufidx]); | |
1774 state->lineinfos[bufidx] = newlineinfo; | |
1775 } | |
1776 | |
1777 state->lineinfo = state->lineinfos[state->mode.alt_screen ? BUFIDX_ALTSCREEN : BUFIDX_PRIMARY]; | |
1750 } | 1778 } |
1751 | 1779 |
1752 state->rows = rows; | 1780 state->rows = rows; |
1753 state->cols = cols; | 1781 state->cols = cols; |
1754 | 1782 |
1755 if(state->scrollregion_bottom > -1) | 1783 if(state->scrollregion_bottom > -1) |
1756 UBOUND(state->scrollregion_bottom, state->rows); | 1784 UBOUND(state->scrollregion_bottom, state->rows); |
1757 if(state->scrollregion_right > -1) | 1785 if(state->scrollregion_right > -1) |
1758 UBOUND(state->scrollregion_right, state->cols); | 1786 UBOUND(state->scrollregion_right, state->cols); |
1759 | 1787 |
1788 fields.pos = state->pos; | |
1789 | |
1760 if(state->callbacks && state->callbacks->resize) | 1790 if(state->callbacks && state->callbacks->resize) |
1761 (*state->callbacks->resize)(rows, cols, &delta, state->cbdata); | 1791 (*state->callbacks->resize)(rows, cols, &fields, state->cbdata); |
1792 | |
1793 state->pos = fields.pos; | |
1762 | 1794 |
1763 if(state->at_phantom && state->pos.col < cols-1) { | 1795 if(state->at_phantom && state->pos.col < cols-1) { |
1764 state->at_phantom = 0; | 1796 state->at_phantom = 0; |
1765 state->pos.col++; | 1797 state->pos.col++; |
1766 } | 1798 } |
1767 | |
1768 state->pos.row += delta.row; | |
1769 state->pos.col += delta.col; | |
1770 | 1799 |
1771 if(state->pos.row >= rows) | 1800 if(state->pos.row >= rows) |
1772 state->pos.row = rows - 1; | 1801 state->pos.row = rows - 1; |
1773 if(state->pos.col >= cols) | 1802 if(state->pos.col >= cols) |
1774 state->pos.col = cols - 1; | 1803 state->pos.col = cols - 1; |
1800 | 1829 |
1801 state = vterm_state_new(vt); | 1830 state = vterm_state_new(vt); |
1802 if (state == NULL) | 1831 if (state == NULL) |
1803 return NULL; | 1832 return NULL; |
1804 vt->state = state; | 1833 vt->state = state; |
1805 | |
1806 state->combine_chars_size = 16; | |
1807 state->combine_chars = vterm_allocator_malloc(state->vt, state->combine_chars_size * sizeof(state->combine_chars[0])); | |
1808 | |
1809 state->tabstops = vterm_allocator_malloc(state->vt, (state->cols + 7) / 8); | |
1810 | |
1811 state->lineinfo = vterm_allocator_malloc(state->vt, state->rows * sizeof(VTermLineInfo)); | |
1812 | |
1813 state->encoding_utf8.enc = vterm_lookup_encoding(ENC_UTF8, 'u'); | |
1814 if(*state->encoding_utf8.enc->init != NULL) | |
1815 (*state->encoding_utf8.enc->init)(state->encoding_utf8.enc, state->encoding_utf8.data); | |
1816 | 1834 |
1817 vterm_parser_set_callbacks(vt, &parser_callbacks, state); | 1835 vterm_parser_set_callbacks(vt, &parser_callbacks, state); |
1818 | 1836 |
1819 return state; | 1837 return state; |
1820 } | 1838 } |
1974 case VTERM_PROP_REVERSE: | 1992 case VTERM_PROP_REVERSE: |
1975 state->mode.screen = val->boolean; | 1993 state->mode.screen = val->boolean; |
1976 return 1; | 1994 return 1; |
1977 case VTERM_PROP_ALTSCREEN: | 1995 case VTERM_PROP_ALTSCREEN: |
1978 state->mode.alt_screen = val->boolean; | 1996 state->mode.alt_screen = val->boolean; |
1997 if(state->mode.alt_screen && !state->lineinfos[BUFIDX_ALTSCREEN]) | |
1998 state->lineinfos[BUFIDX_ALTSCREEN] = vterm_allocator_malloc(state->vt, state->rows * sizeof(VTermLineInfo)); | |
1999 state->lineinfo = state->lineinfos[state->mode.alt_screen ? BUFIDX_ALTSCREEN : BUFIDX_PRIMARY]; | |
1979 if(state->mode.alt_screen) { | 2000 if(state->mode.alt_screen) { |
1980 VTermRect rect = {0, 0, 0, 0}; | 2001 VTermRect rect = {0, 0, 0, 0}; |
1981 rect.end_row = state->rows; | 2002 rect.end_row = state->rows; |
1982 rect.end_col = state->cols; | 2003 rect.end_col = state->cols; |
1983 erase(state, rect, 0); | 2004 erase(state, rect, 0); |