Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/reline/io/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
class Reline::Windows < Reline::IO

attr_writer :output
attr_reader :jruby_p
alias jruby? jruby_p
alias flush_before_control? jruby_p

def initialize
@input_buf = []
Expand Down Expand Up @@ -32,6 +35,15 @@ def initialize
@WaitForSingleObject = Win32API.new('kernel32', 'WaitForSingleObject', ['L', 'L'], 'L')

@legacy_console = getconsolemode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0
@jruby_p = RUBY_ENGINE == 'jruby'
if @jruby_p && @legacy_console
setconsolemode(getconsolemode() | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
@legacy_console = getconsolemode & ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0
if @legacy_console
self.class.const_set(:RESET_COLOR, "")
ENV['RELINE_ALT_SCROLLBAR'] = '1'
end
end
end

def encoding
Expand Down Expand Up @@ -182,11 +194,6 @@ def call(*args)
call_with_console_handle(@SetConsoleMode, mode)
end

#if @legacy_console
# setconsolemode(getconsolemode() | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
# @legacy_console = (getconsolemode() & ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0)
#end

def msys_tty?(io = @hConsoleInputHandle)
# check if fd is a pipe
if @GetFileType.call(io) != FILE_TYPE_PIPE
Expand Down Expand Up @@ -366,22 +373,26 @@ def get_console_screen_buffer_info
ALTERNATIVE_CSBI = [80, 24, 0, 0, 7, 0, 0, 79, 23].freeze

def get_screen_size
@output.flush if flush_before_control?
width, _, _, _, _, _, top, _, bottom = get_console_screen_buffer_info || ALTERNATIVE_CSBI
[bottom - top + 1, width]
end

def cursor_pos
@output.flush if flush_before_control?
_, _, x, y, _, _, top, = get_console_screen_buffer_info || ALTERNATIVE_CSBI
Reline::CursorPos.new(x, y - top)
end

def move_cursor_column(val)
@output.flush if flush_before_control?
_, _, _, y, = get_console_screen_buffer_info
call_with_console_handle(@SetConsoleCursorPosition, y * 65536 + val) if y
end

def move_cursor_up(val)
if val > 0
@output.flush if flush_before_control?
_, _, x, y, _, _, top, = get_console_screen_buffer_info
return unless y
y = (y - top) - val
Expand All @@ -394,6 +405,7 @@ def move_cursor_up(val)

def move_cursor_down(val)
if val > 0
@output.flush if flush_before_control?
_, _, x, y, _, _, top, _, bottom = get_console_screen_buffer_info
return unless y
screen_height = bottom - top
Expand All @@ -406,6 +418,7 @@ def move_cursor_down(val)
end

def erase_after_cursor
@output.flush if flush_before_control?
width, _, x, y, attributes, = get_console_screen_buffer_info
return unless x
written = 0.chr * 4
Expand All @@ -423,6 +436,7 @@ def scroll_down(x)

def clear_screen
if @legacy_console
@output.flush if flush_before_control?
width, _, _, _, attributes, _, top, _, bottom = get_console_screen_buffer_info
return unless width
fill_length = width * (bottom - top + 1)
Expand Down
11 changes: 7 additions & 4 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ def add_dialog_proc(name, p, context = nil)
end

private def update_each_dialog(dialog, cursor_column, cursor_row, key = nil)
no_color = Reline::IOGate.win? && Reline::IOGate.win_legacy_console? && Reline::IOGate.jruby?
pointer_width = no_color ? 1 : 0
dialog.set_cursor_pos(cursor_column, cursor_row)
dialog_render_info = dialog.call(key)
if dialog_render_info.nil? or dialog_render_info.contents.nil? or dialog_render_info.contents.empty?
Expand Down Expand Up @@ -743,6 +745,7 @@ def add_dialog_proc(name, p, context = nil)
end
dialog.column = dialog_render_info.pos.x
dialog.width += @block_elem_width if scrollbar_pos
dialog.width += pointer_width
diff = (dialog.column + dialog.width) - screen_width
if diff > 0
dialog.column -= diff
Expand All @@ -759,12 +762,12 @@ def add_dialog_proc(name, p, context = nil)
dialog.width = screen_width
end
face = Reline::Face[dialog_render_info.face || :default]
scrollbar_sgr = face[:scrollbar]
default_sgr = face[:default]
enhanced_sgr = face[:enhanced]
scrollbar_sgr = no_color ? "" : face[:scrollbar]
default_sgr = no_color ? " " : face[:default]
enhanced_sgr = no_color ? "*" : face[:enhanced]
dialog.contents = contents.map.with_index do |item, i|
line_sgr = i == pointer ? enhanced_sgr : default_sgr
str_width = dialog.width - (scrollbar_pos.nil? ? 0 : @block_elem_width)
str_width = dialog.width - (scrollbar_pos.nil? ? 0 : @block_elem_width) - pointer_width
str, = Reline::Unicode.take_mbchar_range(item, 0, str_width, padding: true)
colored_content = "#{line_sgr}#{str}"
if scrollbar_pos
Expand Down