reline 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8da8b8b73cb81c8d6288188ba05a0ea83a7dade5e60a54c5e9a591cdaa6ce729
4
- data.tar.gz: b810a0521daf74369007cd0195f861e30f66cb75c86c29630216691ceb3cfd64
3
+ metadata.gz: f165aeb5368335d41b08932f34d0457d612fe4dbe334748964c2bafaaa518b54
4
+ data.tar.gz: 4e268dfea3a18f61b6f0bdbbf4d7dd292b3f2d62e178835c971f7b9d3da96613
5
5
  SHA512:
6
- metadata.gz: bcdfacec31f8a2a672629b6a709cc9378d215758156ba11490a02d9372fa349706a3d7129db08832969baf3de823c5f553062e536dce69dd524f24e602807fc1
7
- data.tar.gz: e7eb36a5936ff7ad3642b27869a57b766f33c77b149296d06e2c34b3ab1676b21880ba3dde12f1a5faae0f6280e662adc29fa1fd0daf43e6a394e5c1569765a8
6
+ metadata.gz: 7c56912f662f9c0e53d793ff108ad44fa2ef231b07fa579ab11e793639b27dd076b6dcb54c7dcc1f68c52a73fbabddf8f41a9d8ea8ea53c06cee481628ea9e18
7
+ data.tar.gz: acc258dcbe8b5a3dbe536cc3084906bae2006972f7a3e34353f7f87bbb9b78d692e68b479abb412aae18c396efa2f8dc0210fabc04451cce3f48e7ac8a572093
@@ -124,6 +124,7 @@ class Reline::LineEditor
124
124
  @prompt_cache_time = Time.now.to_f
125
125
  end
126
126
  prompt_list.map!{ prompt } if @vi_arg or @searching_prompt
127
+ prompt_list = [prompt] if prompt_list.empty?
127
128
  mode_string = check_mode_string
128
129
  prompt_list = prompt_list.map{ |pr| mode_string + pr } if mode_string
129
130
  prompt = prompt_list[@line_index]
@@ -343,8 +344,9 @@ class Reline::LineEditor
343
344
  else
344
345
  end_of_line_cursor = new_cursor_max
345
346
  end
346
- line_to_calc.encode(Encoding::UTF_8).grapheme_clusters.each do |gc|
347
- mbchar_width = Reline::Unicode.get_mbchar_width(gc)
347
+ line_to_calc.grapheme_clusters.each do |gc|
348
+ mbchar = gc.encode(Encoding::UTF_8)
349
+ mbchar_width = Reline::Unicode.get_mbchar_width(mbchar)
348
350
  now = new_cursor + mbchar_width
349
351
  if now > end_of_line_cursor or now > cursor
350
352
  break
@@ -724,13 +726,17 @@ class Reline::LineEditor
724
726
  Reline::IOGate.move_cursor_column(0)
725
727
  if line.nil?
726
728
  if calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last
727
- # Reaches the end of line.
728
- #
729
- # When the cursor is at the end of the line and erases characters
730
- # after the cursor, some terminals delete the character at the
731
- # cursor position.
732
- move_cursor_down(1)
733
- Reline::IOGate.move_cursor_column(0)
729
+ # reaches the end of line
730
+ if Reline::IOGate.win? and Reline::IOGate.win_legacy_console?
731
+ # A newline is automatically inserted if a character is rendered at
732
+ # eol on command prompt.
733
+ else
734
+ # When the cursor is at the end of the line and erases characters
735
+ # after the cursor, some terminals delete the character at the
736
+ # cursor position.
737
+ move_cursor_down(1)
738
+ Reline::IOGate.move_cursor_column(0)
739
+ end
734
740
  else
735
741
  Reline::IOGate.erase_after_cursor
736
742
  move_cursor_down(1)
@@ -739,6 +745,10 @@ class Reline::LineEditor
739
745
  next
740
746
  end
741
747
  @output.write line
748
+ if Reline::IOGate.win? and Reline::IOGate.win_legacy_console? and calculate_width(line, true) == Reline::IOGate.get_screen_size.last
749
+ # A newline is automatically inserted if a character is rendered at eol on command prompt.
750
+ @rest_height -= 1 if @rest_height > 0
751
+ end
742
752
  @output.flush
743
753
  if @first_prompt
744
754
  @first_prompt = false
@@ -108,6 +108,7 @@ class Reline::Unicode
108
108
  end
109
109
  m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
110
110
  case
111
+ when m.nil? then 1 # TODO should be U+FFFD � REPLACEMENT CHARACTER
111
112
  when m[:width_2_1], m[:width_2_2] then 2
112
113
  when m[:width_3] then 3
113
114
  when m[:width_0] then 0
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -9,6 +9,10 @@ class Reline::Windows
9
9
  true
10
10
  end
11
11
 
12
+ def self.win_legacy_console?
13
+ @@legacy_console
14
+ end
15
+
12
16
  RAW_KEYSTROKE_CONFIG = {
13
17
  [224, 72] => :ed_prev_history, # ↑
14
18
  [224, 80] => :ed_next_history, # ↓
@@ -94,6 +98,26 @@ class Reline::Windows
94
98
  @@GetFileInformationByHandleEx = Win32API.new('kernel32', 'GetFileInformationByHandleEx', ['L', 'I', 'P', 'L'], 'I')
95
99
  @@FillConsoleOutputAttribute = Win32API.new('kernel32', 'FillConsoleOutputAttribute', ['L', 'L', 'L', 'L', 'P'], 'L')
96
100
 
101
+ @@GetConsoleMode = Win32API.new('kernel32', 'GetConsoleMode', ['L', 'P'], 'L')
102
+ @@SetConsoleMode = Win32API.new('kernel32', 'SetConsoleMode', ['L', 'L'], 'L')
103
+ ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
104
+
105
+ private_class_method def self.getconsolemode
106
+ mode = "\000\000\000\000"
107
+ @@GetConsoleMode.call(@@hConsoleHandle, mode)
108
+ mode.unpack1('L')
109
+ end
110
+
111
+ private_class_method def self.setconsolemode(mode)
112
+ @@SetConsoleMode.call(@@hConsoleHandle, mode)
113
+ end
114
+
115
+ @@legacy_console = (getconsolemode() & ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0)
116
+ #if @@legacy_console
117
+ # setconsolemode(getconsolemode() | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
118
+ # @@legacy_console = (getconsolemode() & ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0)
119
+ #end
120
+
97
121
  @@input_buf = []
98
122
  @@output_buf = []
99
123
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console