Skip to content

Commit 17a6277

Browse files
committed
expand zchar before writing to windows console (#75)
1 parent cabb8aa commit 17a6277

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/lTerm_windows.ml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,26 @@ type char_info = {
138138
ci_background : int;
139139
}
140140

141-
external write_console_output : Unix.file_descr -> char_info array array -> LTerm_geom.size -> LTerm_geom.coord -> LTerm_geom.rect -> LTerm_geom.rect = "lt_windows_write_console_output"
141+
type char_info_raw = {
142+
cir_char : UChar.t;
143+
cir_foreground : int;
144+
cir_background : int;
145+
}
146+
147+
let char_info_to_raw ci=
148+
Zed_char.to_array ci.ci_char
149+
|> Array.map (fun char->
150+
{ cir_char= char;
151+
cir_foreground= ci.ci_foreground;
152+
cir_background= ci.ci_background
153+
})
154+
155+
external write_console_output : Unix.file_descr -> char_info_raw array array -> LTerm_geom.size -> LTerm_geom.coord -> LTerm_geom.rect -> LTerm_geom.rect = "lt_windows_write_console_output"
156+
157+
let chars_to_raw chars=
158+
Array.map
159+
(fun line-> List.map (fun ci-> char_info_to_raw ci) (Array.to_list line) |> Array.concat)
160+
chars
142161

143162
let write_console_output fd chars size coord rect =
144163
Lwt_unix.check_descriptor fd;
@@ -147,6 +166,7 @@ let write_console_output fd chars size coord rect =
147166
(fun line ->
148167
if Array.length line <> size.LTerm_geom.cols then invalid_arg "LTerm_windows.write_console_output")
149168
chars;
169+
let chars= chars_to_raw chars in
150170
write_console_output (Lwt_unix.unix_file_descr fd) chars size coord rect
151171

152172
external fill_console_output_character : Unix.file_descr -> UChar.t -> int -> LTerm_geom.coord -> int = "lt_windows_fill_console_output_character"

0 commit comments

Comments
 (0)