copy to clipboard and past settings via CLI

10.3.x-maintenance
cTn 2013-09-05 12:34:02 +02:00
parent 150038e65a
commit e3aaa710ae
4 changed files with 69 additions and 18 deletions

View File

@ -850,14 +850,40 @@ a:hover {
border: 1px solid silver; border: 1px solid silver;
background-color: black; background-color: black;
} }
.tab-cli input { .tab-cli textarea {
margin-top: 10px; margin-top: 8px;
display: block; display: block;
width: 911px; width: 911px;
height: 20px;
line-height: 20px;
padding-left: 5px; padding-left: 5px;
border: 1px solid silver; border: 1px solid silver;
resize: none;
}
.tab-cli .copy {
display: block;
position: absolute;
bottom: 55px;
right: 40px;
height: 28px;
line-height: 28px;
padding: 0 15px 0 15px;
text-align: center;
font-weight: bold;
border: 1px solid silver;
background-color: #ececec;
}
.tab-cli .copy:hover {
background-color: #dedcdc;
} }
.tab-about { .tab-about {
} }

View File

@ -16,7 +16,8 @@
"serial", "serial",
"storage", "storage",
"fileSystem", "fileSystem",
"fileSystem.write" "fileSystem.write",
"clipboardWrite"
], ],
"icons": { "icons": {

View File

@ -7,5 +7,6 @@
<div class="wrapper"> <div class="wrapper">
</div> </div>
</div> </div>
<input type="text" name="commands" placeholder="Write your command here" value="" /> <textarea name="commands" placeholder="Write your command here" rows="0" cols="0"></textarea>
<a class="copy" href="#">Copy to Clipboard</a>
</div> </div>

View File

@ -12,32 +12,55 @@ function tab_initialize_cli() {
chrome.serial.write(connectionId, bufferOut, function(writeInfo) { chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
}); });
$('.tab-cli input').keypress(function(event) { $('.tab-cli textarea').keypress(function(event) {
if (event.which == 13) { // enter if (event.which == 13) { // enter
var out_string = $('.tab-cli input').val(); var out_string = $('.tab-cli textarea').val();
var out_arr = out_string.split("\n");
var timeout_needle = 0;
var bufferOut = new ArrayBuffer(out_string.length + 1); // +1 for enter character for (var i = 0; i < out_arr.length; i++) {
var bufView = new Uint8Array(bufferOut); send_slowly(out_arr, i, timeout_needle++);
for (var i = 0; i < out_string.length; i++) {
bufView[i] = out_string.charCodeAt(i);
} }
bufView[out_string.length] = 0x0D; // enter $('.tab-cli textarea').val('');
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
$('.tab-cli input').val('');
});
} }
}); });
// give input element user focus // give input element user focus
$('.tab-cli input').focus(); $('.tab-cli textarea').focus();
// if user clicks inside the console window, input element gets re-focused // if user clicks inside the console window, input element gets re-focused
$('.tab-cli .window').click(function() { $('.tab-cli .window').click(function() {
$('.tab-cli input').focus(); $('.tab-cli textarea').focus();
}); });
$('.tab-cli .copy').click(function() {
var text = $('.tab-cli .window .wrapper').html();
text = text.replace(/<br\s*\/?>/mg,"\n"); // replacing br tags with \n to keep some of the formating
var copyFrom = $('<textarea/>');
copyFrom.text(text);
$('body').append(copyFrom);
copyFrom.select();
document.execCommand('copy');
copyFrom.remove();
});
}
function send_slowly(out_arr, i, timeout_needle) {
setTimeout(function() {
var bufferOut = new ArrayBuffer(out_arr[i].length + 1);
var bufView = new Uint8Array(bufferOut);
for (var c_key = 0; c_key < out_arr[i].length; c_key++) {
bufView[c_key] = out_arr[i].charCodeAt(c_key);
}
bufView[out_arr[i].length] = 0x0D; // enter (\n)
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {});
}, timeout_needle * 5);
} }
function leave_CLI(callback) { function leave_CLI(callback) {