1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-23 00:05:22 +03:00

Stop cli buffer from being displayed in cli output

This commit is contained in:
Adem Gaygusuz 2018-06-01 16:12:17 +01:00
parent 97775f2748
commit aff6f3c8a1
2 changed files with 51 additions and 29 deletions

View file

@ -19,6 +19,7 @@ TABS.cli.initialize = function (callback) {
} }
self.outputHistory = ""; self.outputHistory = "";
self.cliBuffer = "";
$('#content').load("./tabs/cli.html", function () { $('#content').load("./tabs/cli.html", function () {
// translate to user-selected language // translate to user-selected language
@ -198,12 +199,20 @@ TABS.cli.history.next = function () {
return this.history[this.index - 1]; return this.history[this.index - 1];
}; };
const backspaceCode = 8;
const lineFeedCode = 10;
const carriageReturnCode = 13;
function writeToOutput(text) { function writeToOutput(text) {
$('.tab-cli .window .wrapper').append(text); $('.tab-cli .window .wrapper').append(text);
$('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height()); $('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height());
} }
function writeToPrompt(text) { function writeLineToOutput(text) {
writeToOutput(text + "<br>");
}
function setPrompt(text) {
$('.tab-cli textarea').val(text); $('.tab-cli textarea').val(text);
} }
@ -219,7 +228,6 @@ TABS.cli.read = function (readInfo) {
Chrome OS currently unknown Chrome OS currently unknown
*/ */
var data = new Uint8Array(readInfo.data), var data = new Uint8Array(readInfo.data),
cliOutput = "",
validateText = "", validateText = "",
sequenceCharsToSkip = 0; sequenceCharsToSkip = 0;
@ -229,7 +237,7 @@ TABS.cli.read = function (readInfo) {
if (!CONFIGURATOR.cliValid) { if (!CONFIGURATOR.cliValid) {
// try to catch part of valid CLI enter message // try to catch part of valid CLI enter message
validateText += currentChar; validateText += currentChar;
cliOutput += currentChar; writeToOutput(currentChar);
continue; continue;
} }
@ -244,35 +252,30 @@ TABS.cli.read = function (readInfo) {
continue; continue;
} }
const lineFeedCode = 10;
const carriageReturnCode = 13;
const backspaceCode = 8;
switch (data[i]) { switch (data[i]) {
case lineFeedCode: case lineFeedCode:
if (GUI.operating_system != "MacOS") { if (GUI.operating_system != "MacOS") {
cliOutput += "<br />"; writeLineToOutput(this.cliBuffer);
} }
this.cliBuffer = ""; this.cliBuffer = "";
break; break;
case carriageReturnCode: case carriageReturnCode:
if (GUI.operating_system == "MacOS") { if (GUI.operating_system == "MacOS") {
cliOutput += "<br />"; writeLineToOutput(this.cliBuffer);
} }
this.cliBuffer = ""; this.cliBuffer = "";
break; break;
case 60: case 60:
cliOutput += '&lt'; this.cliBuffer += '&lt';
break; break;
case 62: case 62:
cliOutput += '&gt'; this.cliBuffer += '&gt';
break; break;
case backspaceCode: case backspaceCode:
cliOutput = cliOutput.slice(0, -1);
this.cliBuffer = this.cliBuffer.slice(0, -1); this.cliBuffer = this.cliBuffer.slice(0, -1);
break; break;
default: default:
cliOutput += currentChar;
this.cliBuffer += currentChar; this.cliBuffer += currentChar;
} }
@ -310,8 +313,7 @@ TABS.cli.read = function (readInfo) {
validateText = ""; validateText = "";
} }
writeToOutput(cliOutput); setPrompt(removePromptHash(this.cliBuffer));
writeToPrompt(removePromptHash(this.cliBuffer));
}; };
TABS.cli.sendLine = function (line, callback) { TABS.cli.sendLine = function (line, callback) {

View file

@ -39,16 +39,27 @@ describe('TABS.cli', () => {
data: toArrayBuffer('\r\033[Kserialpassthrough\tservo\r\n# ser') data: toArrayBuffer('\r\033[Kserialpassthrough\tservo\r\n# ser')
}); });
expect(cliOutput.html()).to.equal('<br>serialpassthrough\tservo<br># ser'); expect(cliOutput.html()).to.equal('<br>serialpassthrough\tservo<br>');
expect(cliPrompt.val()).to.equal('ser'); expect(cliPrompt.val()).to.equal('ser');
}); });
it('unambiguous auto-complete result', () => { it('unambiguous auto-complete result', () => {
TABS.cli.read({ TABS.cli.read({
data: toArrayBuffer('serialpassthrough\r\n# serialpassthrough') data: toArrayBuffer('serialpassthrough')
}); });
expect(cliOutput.html()).to.equal('serialpassthrough<br># serialpassthrough'); expect(cliOutput.html()).to.equal('');
expect(cliPrompt.val()).to.equal('serialpassthrough');
});
it('unambiguous auto-complete result with partial buffer', () => {
TABS.cli.cliBuffer = 'serial';
TABS.cli.read({
data: toArrayBuffer('passthrough')
});
expect(cliOutput.html()).to.equal('');
expect(cliPrompt.val()).to.equal('serialpassthrough'); expect(cliPrompt.val()).to.equal('serialpassthrough');
}); });
@ -131,9 +142,9 @@ describe('TABS.cli', () => {
}); });
it('second auto complete in row', done => { it('second auto complete in row', done => {
TABS.cli.cliBuffer = '# ser';
TABS.cli.initialize(() => { TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# ser';
cliPrompt.val('seri'); cliPrompt.val('seri');
triggerTabKey(cliPrompt); triggerTabKey(cliPrompt);
@ -145,9 +156,9 @@ describe('TABS.cli', () => {
}); });
it('auto-complete command with trailing space', done => { it('auto-complete command with trailing space', done => {
TABS.cli.cliBuffer = '# get ';
TABS.cli.initialize(() => { TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# get ';
cliPrompt.val('get r'); cliPrompt.val('get r');
triggerTabKey(cliPrompt); triggerTabKey(cliPrompt);
@ -159,9 +170,9 @@ describe('TABS.cli', () => {
}); });
it('auto-complete after delete characters', done => { it('auto-complete after delete characters', done => {
TABS.cli.cliBuffer = '# serial';
TABS.cli.initialize(() => { TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# serial';
cliPrompt.val('ser'); cliPrompt.val('ser');
triggerTabKey(cliPrompt); triggerTabKey(cliPrompt);
@ -175,9 +186,9 @@ describe('TABS.cli', () => {
}); });
it('enter after autocomplete', done => { it('enter after autocomplete', done => {
TABS.cli.cliBuffer = '# servo';
TABS.cli.initialize(() => { TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# servo';
cliPrompt.val('servo'); cliPrompt.val('servo');
triggerEnterKey(cliPrompt); triggerEnterKey(cliPrompt);
@ -189,9 +200,9 @@ describe('TABS.cli', () => {
}); });
it('enter after autocomplete', done => { it('enter after autocomplete', done => {
TABS.cli.cliBuffer = '# ser';
TABS.cli.initialize(() => { TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# ser';
cliPrompt.val('servo'); cliPrompt.val('servo');
triggerEnterKey(cliPrompt); triggerEnterKey(cliPrompt);
@ -203,9 +214,9 @@ describe('TABS.cli', () => {
}); });
it('enter after deleting characters', done => { it('enter after deleting characters', done => {
TABS.cli.cliBuffer = '# serial';
TABS.cli.initialize(() => { TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# serial';
cliPrompt.val('ser'); cliPrompt.val('ser');
triggerEnterKey(cliPrompt); triggerEnterKey(cliPrompt);
@ -217,5 +228,14 @@ describe('TABS.cli', () => {
done(); done();
}); });
}); });
it('cliBufer is cleared on startup', done => {
TABS.cli.cliBuffer = '# serial';
TABS.cli.initialize(() => {
expect(TABS.cli.cliBuffer).to.equal('');
done();
});
});
}); });
}); });