diff --git a/app/docker/views/containers/console/containerConsoleController.js b/app/docker/views/containers/console/containerConsoleController.js index 59abf95f9..8de730cad 100644 --- a/app/docker/views/containers/console/containerConsoleController.js +++ b/app/docker/views/containers/console/containerConsoleController.js @@ -121,7 +121,8 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ .map((k) => k + '=' + params[k]) .join('&'); - initTerm(url, ExecService.resizeTTY.bind(this, endpoint.Id, params.id)); + const isLinuxCommand = execConfig.Cmd ? isLinuxTerminalCommand(execConfig.Cmd[0]) : false; + initTerm(url, ExecService.resizeTTY.bind(this, params.id), isLinuxCommand); }) .catch(function error(err) { Notifications.error('Failure', err, 'Unable to exec into container'); @@ -165,7 +166,12 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ restcall(termWidth + add, termHeight + add, 1); } - function initTerm(url, resizeRestCall) { + function isLinuxTerminalCommand(command) { + const validShellCommands = ['ash', 'bash', 'dash', 'sh']; + return validShellCommands.includes(command); + } + + function initTerm(url, resizeRestCall, isLinuxTerm = false) { let resizefun = resize.bind(this, resizeRestCall); if ($transition$.params().nodeName) { @@ -186,15 +192,21 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ $scope.state = states.connected; term = new Terminal(); - socket.send('export LANG=C.UTF-8\n'); - socket.send('export LC_ALL=C.UTF-8\n'); - socket.send('clear\n'); + + if (isLinuxTerm) { + // linux terminals support xterm + socket.send('export LANG=C.UTF-8\n'); + socket.send('export LC_ALL=C.UTF-8\n'); + socket.send('export TERM="xterm-256color"\n'); + socket.send('alias ls="ls --color=auto"\n'); + socket.send('echo -e "\\033[2J\\033[H"\n'); + } term.onData(function (data) { socket.send(data); - // This code is detect whether the user has typed CTRL+D - // or exit in the terminal + // This code is detect whether the user has + // typed CTRL+D or exit in the terminal if (data === '\x04') { // If the user types CTRL+D, close the terminal closeTerminal = true; diff --git a/app/docker/views/containers/console/exec.html b/app/docker/views/containers/console/exec.html index e92d8ba45..9db38241d 100644 --- a/app/docker/views/containers/console/exec.html +++ b/app/docker/views/containers/console/exec.html @@ -29,6 +29,7 @@