Clear text typed with input() from the command history

7 vues (au cours des 30 derniers jours)
Oleg Komarov
Oleg Komarov le 10 Juin 2014
Modifié(e) : Oleg Komarov le 25 Nov 2014
The case scenario is very simple, I am asking for a password to be typed in the command window.
I am using
s = input('Password: ','s')
I can clear the text from the command window with something like fprintf(char(8)), but how do I clear the last typed command from the command history ?
I am aware that inputdlg() would solve the problem but I would be interested in finding some way for editing the history.
I personally changed approach from cmd window input to GUI input and wrote a submission for the purpose:
  2 commentaires
Oleg Komarov
Oleg Komarov le 10 Juin 2014
I cannot afford to terminate the session, it's either disruptive or discretionary.
I am exactly looking for a way to refresh the IDE and I suspect that by digging into the java of the command history pane, it should be possible to find the callback for deleting one row which you can do if you select and right-click.

Connectez-vous pour commenter.

Réponse acceptée

Oleg Komarov
Oleg Komarov le 13 Juin 2014
After digging into the Java internals with the help of Yair's toolkit (see findJObj, uiinspect and checkClass), I found a relatively simple way to manipulate entries in the Command History:
% Get instance to the Command History
cmdhist = com.mathworks.mde.cmdhist.AltHistory.getInstance;
% Retrieve the Command History Table
chtable = findjobj(cmdhist,'property',{'name', 'CommandHistoryTable'});
% Select last row row
nrows = chtable.getRowCount
chtable.setRowSelectionInterval(nrows, nrows)
% Delete selected rows
  3 commentaires
Oleg Komarov
Oleg Komarov le 25 Nov 2014
I recommend to use for password related input in a GUI.

Connectez-vous pour commenter.

Plus de réponses (1)

Cedric Wannaz
Cedric Wannaz le 10 Juin 2014
Modifié(e) : Cedric Wannaz le 10 Juin 2014
It may be a bit violent but
would work.
And welcome back! ;-)
  1 commentaire
Oleg Komarov
Oleg Komarov le 10 Juin 2014
Thanks Cedric! Yes, a bit violent. Can't afford to lose the whole history :).

Connectez-vous pour commenter.


En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by