1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] Move #pointer from DialogRenderInfo to Dialog

https://github.com/ruby/reline/commit/92dbac0bff
This commit is contained in:
aycabta 2021-09-10 11:23:42 +09:00 committed by git
parent 01a364a36a
commit 5dc753df47
3 changed files with 19 additions and 18 deletions

View file

@ -37,7 +37,7 @@ module Reline
alias_method :==, :match?
end
CursorPos = Struct.new(:x, :y)
DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, :scrollbar, keyword_init: true)
DialogRenderInfo = Struct.new(:pos, :contents, :bg_color, :width, :height, :scrollbar, keyword_init: true)
class Core
ATTR_READER_NAMES = %i(
@ -241,7 +241,8 @@ module Reline
context.clear
context.push(cursor_pos_to_render, result, pointer, dialog)
end
DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, scrollbar: true, height: 15)
dialog.pointer = pointer
DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, scrollbar: true, height: 15)
}
Reline::DEFAULT_DIALOG_CONTEXT = Array.new

View file

@ -560,7 +560,7 @@ class Reline::LineEditor
class Dialog
attr_reader :name, :contents, :width
attr_accessor :scroll_top, :scrollbar_pos, :column, :vertical_offset, :lines_backup, :trap_key
attr_accessor :scroll_top, :scrollbar_pos, :pointer, :column, :vertical_offset, :lines_backup, :trap_key
def initialize(name, config, proc_scope)
@name = name
@ -643,7 +643,7 @@ class Reline::LineEditor
end
old_dialog = dialog.clone
dialog.contents = dialog_render_info.contents
pointer = dialog_render_info.pointer
pointer = dialog.pointer
if dialog_render_info.width
dialog.width = dialog_render_info.width
else
@ -652,15 +652,15 @@ class Reline::LineEditor
height = dialog_render_info.height || DIALOG_HEIGHT
height = dialog.contents.size if dialog.contents.size < height
if dialog.contents.size > height
if dialog_render_info.pointer
if dialog_render_info.pointer < 0
if dialog.pointer
if dialog.pointer < 0
dialog.scroll_top = 0
elsif (dialog_render_info.pointer - dialog.scroll_top) >= (height - 1)
dialog.scroll_top = dialog_render_info.pointer - (height - 1)
elsif (dialog_render_info.pointer - dialog.scroll_top) < 0
dialog.scroll_top = dialog_render_info.pointer
elsif (dialog.pointer - dialog.scroll_top) >= (height - 1)
dialog.scroll_top = dialog.pointer - (height - 1)
elsif (dialog.pointer - dialog.scroll_top) < 0
dialog.scroll_top = dialog.pointer
end
pointer = dialog_render_info.pointer - dialog.scroll_top
pointer = dialog.pointer - dialog.scroll_top
end
dialog.contents = dialog.contents[dialog.scroll_top, height]
end

View file

@ -59,12 +59,12 @@ opt.on('--dialog VAL') { |v|
if v.include?('scrollkey')
dialog.trap_key = nil
if key and key.match?(dialog.name)
if context.pointer.nil?
context.pointer = 0
elsif context.pointer >= (contents.size - 1)
context.pointer = 0
if dialog.pointer.nil?
dialog.pointer = 0
elsif dialog.pointer >= (contents.size - 1)
dialog.pointer = 0
else
context.pointer += 1
dialog.pointer += 1
end
end
dialog.trap_key = [?j.ord]
@ -74,8 +74,8 @@ opt.on('--dialog VAL') { |v|
if v.include?('scrollbar')
scrollbar = true
end
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, pointer: context.pointer, scrollbar: scrollbar)
}, Struct.new(:pointer).new)
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, scrollbar: scrollbar)
})
}
opt.on('--complete') {
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|