copy to clipboard and past settings via CLI
parent
150038e65a
commit
e3aaa710ae
|
@ -850,14 +850,40 @@ a:hover {
|
|||
border: 1px solid silver;
|
||||
background-color: black;
|
||||
}
|
||||
.tab-cli input {
|
||||
margin-top: 10px;
|
||||
.tab-cli textarea {
|
||||
margin-top: 8px;
|
||||
display: block;
|
||||
|
||||
width: 911px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
|
||||
padding-left: 5px;
|
||||
|
||||
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 {
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
"serial",
|
||||
"storage",
|
||||
"fileSystem",
|
||||
"fileSystem.write"
|
||||
"fileSystem.write",
|
||||
"clipboardWrite"
|
||||
],
|
||||
|
||||
"icons": {
|
||||
|
|
|
@ -7,5 +7,6 @@
|
|||
<div class="wrapper">
|
||||
</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>
|
51
tabs/cli.js
51
tabs/cli.js
|
@ -12,32 +12,55 @@ function tab_initialize_cli() {
|
|||
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
|
||||
});
|
||||
|
||||
$('.tab-cli input').keypress(function(event) {
|
||||
$('.tab-cli textarea').keypress(function(event) {
|
||||
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
|
||||
var bufView = new Uint8Array(bufferOut);
|
||||
|
||||
for (var i = 0; i < out_string.length; i++) {
|
||||
bufView[i] = out_string.charCodeAt(i);
|
||||
for (var i = 0; i < out_arr.length; i++) {
|
||||
send_slowly(out_arr, i, timeout_needle++);
|
||||
}
|
||||
|
||||
bufView[out_string.length] = 0x0D; // enter
|
||||
|
||||
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
|
||||
$('.tab-cli input').val('');
|
||||
});
|
||||
$('.tab-cli textarea').val('');
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
$('.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) {
|
||||
|
|
Loading…
Reference in New Issue