File 5111-ssh-Make-unicode-work-in-ssh-shell-printouts.patch of Package erlang
From 3d3c265f57d3168643ea94c168667b4d7072f43b Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans@erlang.org>
Date: Thu, 10 Sep 2020 15:49:31 +0200
Subject: [PATCH 11/11] ssh: Make unicode work in ssh:shell printouts
---
lib/ssh/src/ssh_shell.erl | 25 ++++++++++++++++++++++---
lib/ssh/test/ssh_test_lib.erl | 2 +-
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/lib/ssh/src/ssh_shell.erl b/lib/ssh/src/ssh_shell.erl
index 55ea6098c0..bd11afa080 100644
--- a/lib/ssh/src/ssh_shell.erl
+++ b/lib/ssh/src/ssh_shell.erl
@@ -92,7 +92,7 @@ handle_ssh_msg({ssh_cm, _, {data, _ChannelId, 0, Data}}, State) ->
%% TODO: When unicode support is ready
%% should we call this function or perhaps a new
%% function.
- io:put_chars(Data),
+ io:format("~ts", [Data]),
{ok, State};
handle_ssh_msg({ssh_cm, _,
@@ -101,7 +101,7 @@ handle_ssh_msg({ssh_cm, _,
%% TODO: When unicode support is ready
%% should we call this function or perhaps a new
%% function.
- io:put_chars(Data),
+ io:format("~ts", [Data]),
{ok, State};
handle_ssh_msg({ssh_cm, _, {eof, _ChannelId}}, State) ->
@@ -144,9 +144,18 @@ handle_msg({input, IoPid, eof}, #state{io = IoPid, channel = ChannelId,
ssh_connection:send_eof(ConnectionManager, ChannelId),
{ok, State};
-handle_msg({input, IoPid, Line}, #state{io = IoPid,
+handle_msg({input, IoPid, Line0}, #state{io = IoPid,
channel = ChannelId,
cm = ConnectionManager} = State) ->
+ %% Not nice, but it make it work somehow
+ Line = case encoding(Line0) of
+ utf8 ->
+ Line0;
+ unicode ->
+ unicode:characters_to_binary(Line0);
+ latin1 ->
+ unicode:characters_to_binary(Line0,latin1,utf8)
+ end,
ssh_connection:send(ConnectionManager, ChannelId, Line),
{ok, State}.
@@ -161,7 +170,17 @@ terminate(_Reason, #state{io = IoPid}) ->
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
+encoding(Bin) ->
+ case unicode:characters_to_binary(Bin,utf8,utf8) of
+ Bin ->
+ utf8;
+ Bin2 when is_binary(Bin2) ->
+ unicode;
+ _ ->
+ latin1
+ end.
+%%--------------------------------------------------------------------
input_loop(Fd, Pid) ->
case io:get_line(Fd, '') of
eof ->
diff --git a/lib/ssh/test/ssh_test_lib.erl b/lib/ssh/test/ssh_test_lib.erl
index d9e57042d2..a9591547dd 100644
--- a/lib/ssh/test/ssh_test_lib.erl
+++ b/lib/ssh/test/ssh_test_lib.erl
@@ -361,7 +361,7 @@ io_request({put_chars, unicode, Chars}, TestCase, _, _, Buff) when is_binary(Cha
reply(TestCase, Chars),
{ok, ok, Buff};
io_request({put_chars, unicode, io_lib, format, [Fmt,Args]}, TestCase, _, _, Buff) ->
- reply(TestCase, io_lib:format(Fmt,Args)),
+ reply(TestCase, unicode:characters_to_binary(io_lib:format(Fmt,Args))),
{ok, ok, Buff};
io_request({put_chars, Enc, Chars}, TestCase, _, _, Buff) ->
reply(TestCase, unicode:characters_to_binary(Chars,Enc,latin1)),
--
2.26.2