Skip to content

Commit

Permalink
Merge pull request #59 from lijenicol/command-history-update
Browse files Browse the repository at this point in the history
Only save user provided commands in history
  • Loading branch information
romanvm committed Feb 28, 2024
2 parents 3c6fdda + 6fec53b commit ccf83ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
18 changes: 5 additions & 13 deletions frontend/src/button_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ SOFTWARE.

import $ from 'jquery';

import { websocket, state } from './globals';
import { send_command } from './utils';
import { save_command_in_history, send_command } from './utils';

function bind_button_events() {
$('#next_btn').click(() => {
Expand Down Expand Up @@ -59,18 +58,11 @@ function bind_button_events() {
});

$('#send_btn').click(() => {
if (websocket.readyState === websocket.OPEN) {
const $stdin = $('#stdin');
let input = $stdin.val() + '\n';
const $stdin = $('#stdin');
let command = $stdin.val();
if (send_command(command)) {
save_command_in_history(command);
$stdin.val('');
state.history_index = -1;
if (input !== '' && input !== state.command_history[0]) {
state.command_history.unshift(input);
if (state.command_history.length > 10) {
state.command_history.pop();
}
}
websocket.send(input);
}
});
}
Expand Down
21 changes: 18 additions & 3 deletions frontend/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ SOFTWARE.

import $ from 'jquery';

import { websocket, state } from './globals';

function save_command_in_history(command) {
state.history_index = -1;
if (command !== '' && command !== state.command_history[0]) {
state.command_history.unshift(command);
if (state.command_history.length > 10) {
state.command_history.pop();
}
}
}

function send_command(command) {
$('#stdin').val(command);
$('#send_btn').click();
if (websocket.readyState === websocket.OPEN) {
websocket.send(command + '\n');
return true;
}
return false;
}

function resize_console() {
Expand All @@ -35,4 +50,4 @@ function resize_console() {
$('#console').height(con_height);
}

export { send_command, resize_console };
export { save_command_in_history, send_command, resize_console };
2 changes: 1 addition & 1 deletion web_pdb/static/bundle.min.js

Large diffs are not rendered by default.

0 comments on commit ccf83ec

Please sign in to comment.