Skip to content

Commit

Permalink
check ENABLE_VIRTUAL_TERMINAL_PROCESSING flag and switch eof processing
Browse files Browse the repository at this point in the history
  • Loading branch information
YO4 committed Feb 17, 2021
1 parent 646587f commit 3535676
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def just_move_cursor
if line.nil?
if calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last
# reaches the end of line
if Reline::IOGate.win?
if Reline::IOGate.win? and Reline::IOGate.win_legacy_console?
# A newline is automatically inserted if a character is rendered at
# eol on command prompt.
else
Expand All @@ -744,7 +744,7 @@ def just_move_cursor
next
end
@output.write line
if Reline::IOGate.win? and calculate_width(line, true) == Reline::IOGate.get_screen_size.last
if Reline::IOGate.win? and Reline::IOGate.win_legacy_console? and calculate_width(line, true) == Reline::IOGate.get_screen_size.last
# A newline is automatically inserted if a character is rendered at eol on command prompt.
@rest_height -= 1 if @rest_height > 0
end
Expand Down
24 changes: 24 additions & 0 deletions lib/reline/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def self.win?
true
end

def self.win_legacy_console?
@@legacy_console
end

RAW_KEYSTROKE_CONFIG = {
[224, 72] => :ed_prev_history, # ↑
[224, 80] => :ed_next_history, # ↓
Expand Down Expand Up @@ -94,6 +98,26 @@ def call(*args)
@@GetFileInformationByHandleEx = Win32API.new('kernel32', 'GetFileInformationByHandleEx', ['L', 'I', 'P', 'L'], 'I')
@@FillConsoleOutputAttribute = Win32API.new('kernel32', 'FillConsoleOutputAttribute', ['L', 'L', 'L', 'L', 'P'], 'L')

@@GetConsoleMode = Win32API.new('kernel32', 'GetConsoleMode', ['L', 'P'], 'L')
@@SetConsoleMode = Win32API.new('kernel32', 'SetConsoleMode', ['L', 'L'], 'L')
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4

private_class_method def self.getconsolemode
mode = '\000\000\000\000'
@@GetConsoleMode.call(@@hConsoleHandle, mode)
mode.unpack1('L')
end

private_class_method def self.setconsolemode(mode)
@@SetConsoleMode.call(@@hConsoleHandle, mode)
end

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

@@input_buf = []
@@output_buf = []

Expand Down

0 comments on commit 3535676

Please sign in to comment.