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

View file

@ -39,16 +39,27 @@ describe('TABS.cli', () => {
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');
});
it('unambiguous auto-complete result', () => {
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');
});
@ -131,9 +142,9 @@ describe('TABS.cli', () => {
});
it('second auto complete in row', done => {
TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# ser';
TABS.cli.initialize(() => {
cliPrompt.val('seri');
triggerTabKey(cliPrompt);
@ -145,9 +156,9 @@ describe('TABS.cli', () => {
});
it('auto-complete command with trailing space', done => {
TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# get ';
TABS.cli.initialize(() => {
cliPrompt.val('get r');
triggerTabKey(cliPrompt);
@ -159,9 +170,9 @@ describe('TABS.cli', () => {
});
it('auto-complete after delete characters', done => {
TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# serial';
TABS.cli.initialize(() => {
cliPrompt.val('ser');
triggerTabKey(cliPrompt);
@ -175,9 +186,9 @@ describe('TABS.cli', () => {
});
it('enter after autocomplete', done => {
TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# servo';
TABS.cli.initialize(() => {
cliPrompt.val('servo');
triggerEnterKey(cliPrompt);
@ -189,9 +200,9 @@ describe('TABS.cli', () => {
});
it('enter after autocomplete', done => {
TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# ser';
TABS.cli.initialize(() => {
cliPrompt.val('servo');
triggerEnterKey(cliPrompt);
@ -203,9 +214,9 @@ describe('TABS.cli', () => {
});
it('enter after deleting characters', done => {
TABS.cli.initialize(() => {
TABS.cli.cliBuffer = '# serial';
TABS.cli.initialize(() => {
cliPrompt.val('ser');
triggerEnterKey(cliPrompt);
@ -217,5 +228,14 @@ describe('TABS.cli', () => {
done();
});
});
it('cliBufer is cleared on startup', done => {
TABS.cli.cliBuffer = '# serial';
TABS.cli.initialize(() => {
expect(TABS.cli.cliBuffer).to.equal('');
done();
});
});
});
});