@@ -105,8 +105,11 @@ module internal Utils =
105105 | _, _ -> nextWordFromIdx line ( idx + 1 , true )
106106
107107 /// An array stores ranges of full-width chars.
108- ///
109- /// Array [| [| a; b |]; [| c; d |] |] represents range [a, b] or [c, d], means chars in these ranges are full-width.
108+ ///
109+ /// The ranges are sorted by increasing order in the array, and each range are stored in the 2nth and 2n+1th
110+ /// position in the array (n is the ordinal number of the range)
111+ ///
112+ /// Array [| a; b; c; d |] represents range [a, b] or [c, d], means chars in these ranges are full-width.
110113 let private fullWidthCharRanges =
111114 Array.concat
112115 [|
@@ -165,11 +168,34 @@ module internal Utils =
165168 let isFullWidth ( char ) =
166169 // for array [| a; b; c; d |],
167170 // if a value is in (a, b) or (c, d), the result of Array.BinarySearch will be a negative even number
168- // if a value is a, b, c, d, the result will be a non- positive number
171+ // if a value is a, b, c, d, the result will be a positive number
169172 let n = Array.BinarySearch( fullWidthCharRanges, char)
170- ( n < 0 && n % 2 = 0 ) || n >= 0
173+ n >= 0 || n % 2 = 0
174+
171175
172- // don't write chars to the last 2 column to make sure that chars will not be print to wrong line.
176+ /// Limits BufferWidth to make sure that full-width characters will not be print to wrong position.
177+ ///
178+ /// The return value is Console.BufferWidth - 2.
179+ ///
180+ /// When printing full-width characters to the screen (such as 一二三四五六七八九零),
181+ ///
182+ /// if BufferWidth = Console.BufferWidth, the output will be
183+ ///
184+ /// #> 一二三四五六七八九零一二三四五六七八九 # (零 is missing)
185+ ///
186+ /// #一二三四五六七八九零 #
187+ ///
188+ /// if BufferWidth = Console.BufferWidth - 1, the output will be
189+ ///
190+ /// #> 一二三四五六七八九零一二三四五六七八九零# (零 is printed, but will not correctly cauculate cursor position)
191+ ///
192+ /// #一二三四五六七八九零 # (cursor may appear in the middle of the character)
193+ ///
194+ /// if BufferWidth = Console.BufferWidth - 2, the output will be
195+ ///
196+ /// #> 一二三四五六七八九零一二三四五六七八九 #
197+ ///
198+ /// #零一二三四五六七八九零 # (work correctly)
173199 let bufferWidth () = Console.BufferWidth - 2
174200
175201[<Sealed>]
@@ -179,8 +205,7 @@ type internal Cursor =
179205 Console.CursorTop <- min top ( Console.BufferHeight - 1 )
180206 Console.CursorLeft <- left)
181207
182- static member Move ( inset , delta ) =
183- ignore inset
208+ static member Move ( delta ) =
184209 let width = Utils.bufferWidth ()
185210 let position = Console.CursorTop * width + Console.CursorLeft + delta
186211
@@ -321,7 +346,7 @@ type internal ReadLineConsole() =
321346 if Console.CursorTop + 1 = Console.BufferHeight then
322347 Console.BufferHeight <- Console.BufferHeight + 1
323348
324- Cursor.Move( x.Inset , 0 )
349+ Cursor.Move( 0 )
325350
326351 let writeBlank () =
327352 moveCursorToNextLine ( ' ' )
@@ -389,13 +414,13 @@ type internal ReadLineConsole() =
389414 if current > 0 && ( current - 1 < input.Length) then
390415 current <- current - 1
391416 let c = input.Chars( current)
392- Cursor.Move( x.Inset , - x.GetCharacterSize c)
417+ Cursor.Move(- x.GetCharacterSize c)
393418
394419 let moveRight () =
395420 if current < input.Length then
396421 let c = input.Chars( current)
397422 current <- current + 1
398- Cursor.Move( x.Inset , x. GetCharacterSize c)
423+ Cursor.Move( x.GetCharacterSize c)
399424
400425 let moveWordLeft () =
401426 if current > 0 && ( current - 1 < input.Length) then
0 commit comments