Преглед изворни кода

[shell] Can copy/paste shell output

Fix copy/paste of shell output
Fix prompt focus
Remove extra \n in shell output
Romain Rigaux пре 13 година
родитељ
комит
7f3b2d3
2 измењених фајлова са 19 додато и 18 уклоњено
  1. 18 17
      apps/shell/src/shell/templates/index.mako
  2. 1 1
      apps/shell/src/shell/tests.py

+ 18 - 17
apps/shell/src/shell/templates/index.mako

@@ -102,7 +102,7 @@ from desktop.views import commonheader, commonfooter
 		<span id="shellContent"></span>
 		<input type="text" id="shellInput" class="shell" />
 	</div>
-	<span id="shell_id" class="hidden">${shell_id}</span>
+	<span id="shell_id" class="hide">${shell_id}</span>
   % else:
 	<div>
 		<h3>Please select one of the available shells from the toolbar above.</h3>
@@ -131,7 +131,6 @@ from desktop.views import commonheader, commonfooter
 		}();
 
 		if ($("#shell_id").length){
-
 			var shell = {};
 			shell.id = $("#shell_id").text();
 			shell.get = function(offset){
@@ -154,12 +153,14 @@ from desktop.views import commonheader, commonfooter
 								shell.get(offset);
 							}
 							else {
-								var _out = data[_shell.id].output;
-								_out = _out.replace(/>/g, '&gt;');
-								_out = _out.replace(/</g, '&lt;');
-								_out = _out.replace(/\n/g, '<br />');
-								$("#shellContent").html($("#shellContent").html()+"<br/>"+_out);
-								if (_out.indexOf("Disconnected!")>-1){
+								var output = data[_shell.id].output;
+								output = output.replace(/&/g, '&amp;')
+								               .replace(/</g, '&lt;')
+								               .replace(/>/g, '&gt;')
+								               .replace(/"/g, '&quot;')
+								               .replace(/\n/g, '<br/>');
+								$("#shellContent").append(output);
+								if (output.indexOf("Disconnected!")>-1){
 									window.setTimeout(function(){
 										$.ajax({
 											type: "POST",
@@ -176,7 +177,7 @@ from desktop.views import commonheader, commonfooter
 										});
 									},500);
 								}
-								$("body").animate({ scrollTop: $("#shellInput").offset().top }, "fast");
+								$('html').animate({scrollTop: $(document).height()}, 'slow');
 								_shell.get(data[_shell.id].nextOffset);
 							}
 						}
@@ -222,13 +223,9 @@ from desktop.views import commonheader, commonfooter
 			shell.get(0);
 
 			$("#shellInput").val("");
+
 			$("#shellInput").focus();
 
-			$("#shellInput").blur(function(){
-				window.setTimeout(function(){
-					$("#shellInput").focus();
-				}, 50);
-			});
 			$("#shellInput").keydown(function(e){
 				$(this).width($(document).width()-100-$(this).position().left);
 				if ((e.keyCode ? e.keyCode : e.which) == 13){
@@ -237,10 +234,14 @@ from desktop.views import commonheader, commonfooter
 				}
 			});
 
-		}
-
-
+            $(document).keypress(function(e){
+                if (! $("#shellInput").is(":focus")) {
+                    $("#shellInput").focus();
+                }
+            });
+        }
 	});
 </script>
 </div>
+
 ${commonfooter()}

+ 1 - 1
apps/shell/src/shell/tests.py

@@ -128,7 +128,7 @@ def test_rest():
   assert "There is no Unix user account for you." in response.content
 
   response = client.get("/shell/create?keyName=%s" % (shell_types_available[0],), follow=True, **d)
-  fragment = '<span id="shell_id" class="hidden">'
+  fragment = '<span id="shell_id" class="hide">'
   assert fragment in response.content
 
   shell_id_start = response.content.index(fragment) + len(fragment)