@@ -178,43 +178,49 @@ def reset(prompt = '', encoding:)
178
178
rescue ArgumentError
179
179
end
180
180
Reline ::IOGate . set_winch_handler do
181
- @rest_height = ( Reline ::IOGate . get_screen_size . first - 1 ) - Reline ::IOGate . cursor_pos . y
182
- old_screen_size = @screen_size
183
- @screen_size = Reline ::IOGate . get_screen_size
184
- @screen_height = @screen_size . first
185
- if old_screen_size . last < @screen_size . last # columns increase
186
- @rerender_all = true
187
- rerender
188
- else
189
- back = 0
190
- new_buffer = whole_lines
191
- prompt , prompt_width , prompt_list = check_multiline_prompt ( new_buffer , prompt )
192
- new_buffer . each_with_index do |line , index |
193
- prompt_width = calculate_width ( prompt_list [ index ] , true ) if @prompt_proc
194
- width = prompt_width + calculate_width ( line )
195
- height = calculate_height_by_width ( width )
196
- back += height
197
- end
198
- @highest_in_all = back
199
- @highest_in_this = calculate_height_by_width ( prompt_width + @cursor_max )
200
- @first_line_started_from =
201
- if @line_index . zero?
202
- 0
203
- else
204
- calculate_height_by_lines ( @buffer_of_lines [ 0 ..( @line_index - 1 ) ] , prompt_list || prompt )
205
- end
206
- if @prompt_proc
207
- prompt = prompt_list [ @line_index ]
208
- prompt_width = calculate_width ( prompt , true )
181
+ @resized = true
182
+ end
183
+ @block_elem_width = Reline ::Unicode . calculate_width ( '█' )
184
+ end
185
+
186
+ def resize
187
+ return unless @resized
188
+ @resized = false
189
+ @rest_height = ( Reline ::IOGate . get_screen_size . first - 1 ) - Reline ::IOGate . cursor_pos . y
190
+ old_screen_size = @screen_size
191
+ @screen_size = Reline ::IOGate . get_screen_size
192
+ @screen_height = @screen_size . first
193
+ if old_screen_size . last < @screen_size . last # columns increase
194
+ @rerender_all = true
195
+ rerender
196
+ else
197
+ back = 0
198
+ new_buffer = whole_lines
199
+ prompt , prompt_width , prompt_list = check_multiline_prompt ( new_buffer , prompt )
200
+ new_buffer . each_with_index do |line , index |
201
+ prompt_width = calculate_width ( prompt_list [ index ] , true ) if @prompt_proc
202
+ width = prompt_width + calculate_width ( line )
203
+ height = calculate_height_by_width ( width )
204
+ back += height
205
+ end
206
+ @highest_in_all = back
207
+ @highest_in_this = calculate_height_by_width ( prompt_width + @cursor_max )
208
+ @first_line_started_from =
209
+ if @line_index . zero?
210
+ 0
211
+ else
212
+ calculate_height_by_lines ( @buffer_of_lines [ 0 ..( @line_index - 1 ) ] , prompt_list || prompt )
209
213
end
210
- calculate_nearest_cursor
211
- @started_from = calculate_height_by_width ( prompt_width + @cursor ) - 1
212
- Reline ::IOGate . move_cursor_column ( ( prompt_width + @cursor ) % @screen_size . last )
213
- @highest_in_this = calculate_height_by_width ( prompt_width + @cursor_max )
214
- @rerender_all = true
214
+ if @prompt_proc
215
+ prompt = prompt_list [ @line_index ]
216
+ prompt_width = calculate_width ( prompt , true )
215
217
end
218
+ calculate_nearest_cursor
219
+ @started_from = calculate_height_by_width ( prompt_width + @cursor ) - 1
220
+ Reline ::IOGate . move_cursor_column ( ( prompt_width + @cursor ) % @screen_size . last )
221
+ @highest_in_this = calculate_height_by_width ( prompt_width + @cursor_max )
222
+ @rerender_all = true
216
223
end
217
- @block_elem_width = Reline ::Unicode . calculate_width ( '█' )
218
224
end
219
225
220
226
def finalize
@@ -264,6 +270,7 @@ def reset_variables(prompt = '', encoding:)
264
270
@auto_indent_proc = nil
265
271
@dialogs = [ ]
266
272
@last_key = nil
273
+ @resized = false
267
274
reset_line
268
275
end
269
276
0 commit comments