Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Capture read command contents without displaying it with the silent flag #3947

Closed
wants to merge 5 commits into from

Conversation

Markcial
Copy link
Contributor

@Markcial Markcial commented Apr 9, 2017

Description

This PR updates the reader object adding a silent parameter.

If this parameter is set to true, it doesn't displays the commandline contents when the readline command is called. Allowing silent prompts for password or discrete command entries, the command can be modified to use a offuscation char like '*', but at the moment instead of masking the contents it doesn't displays them.

Fixes issue #838

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.md

@faho faho added this to the 2.6.0 milestone Apr 9, 2017
src/builtin.cpp Outdated
bool split_null = false;

const wchar_t *short_options = L"ac:ghlm:n:p:suxzP:UR:";
const wchar_t *short_options = L"ac:ghlm:n:p:siuxzP:UR:";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that we are trying to keep the flags sorted so adding the i between the hl pair is better.

P.S., Yes, there is lots of code elsewhere in fish that violates this best practice but Rome wasn't built in a day.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, next time I will know, thanks

@@ -168,6 +168,8 @@ class reader_data_t {
bool suppress_autosuggestion;
/// Whether abbreviations are expanded.
bool expand_abbreviations;
/// Silent mode used for password input on the read command
bool silent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where you are initializing this in the constructor for the class. Which means the initial value it undefined. See the /// Constructor comment a hundred lines below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check for it

src/reader.cpp Outdated
@@ -2044,6 +2051,8 @@ void reader_set_test_function(parser_test_error_bits_t (*f)(const wchar_t *)) {

void reader_set_exit_on_interrupt(bool i) { data->exit_on_interrupt = i; }

void reader_set_silent_status(bool f) { data->silent = f; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why f for the parameter name? Why not something like val?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was meant to be the abbreviation of flag, but if more meaning is needed i can write the whole word

src/reader.cpp Outdated
@@ -261,6 +261,7 @@ class reader_data_t {
: allow_autosuggestion(0),
suppress_autosuggestion(0),
expand_abbreviations(0),
silent(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/0/false/ please and you might as well fix the other bool initializers while you're touching this block of code 😄 Functionally it doesn't matter but it does make the intent clearer to a human reader.

@krader1961
Copy link
Contributor

This works but has an unpleasant behavior. With the first character I type the cursor jumps to the start of the line. It needs to either remain at the end of the prompt or, ideally, a * or # character is echoed for each character typed (and subsequently erased when backspacing).

@krader1961
Copy link
Contributor

@Markcial: Do you see the problem with the location of the cursor I noted in my previous comment? Your change to the code looks fine to me so there appears to be an unexpected tight coupling between the functions you modified that results in the cursor not being at the expected position.

@Markcial
Copy link
Contributor Author

Yeah, it's true, i need to dig a little more, maybe i find a way to get a more consistent behaviour, I will try to post an update for the weekend, thanks for your time on the review

@Markcial
Copy link
Contributor Author

Markcial commented Apr 11, 2017

I ended up using as the obfuscation character. But I am not much into it.

Do I parametrize the obfuscation char or use another char as the asterisk or the shebang?

What do you think i should do?

@Markcial
Copy link
Contributor Author

Trying to grasp the reason of the segmentation faults, will try to fix it if able.

@krader1961
Copy link
Contributor

I haven't reviewed your latest changes but it now seems to work fine. I like the solid circle if the environment supports unicode code points but we should fallback to # if it doesn't. You can mimic this line from src/common.cpp to pick which one to use:

omitted_newline_char = can_be_encoded(L'\x23CE') ? L'\x23CE' : L'~';

@krader1961
Copy link
Contributor

Merged as squashed commit 8213885.

Absolutely fantastic job, @Markcial. The only thing you missed was updating the documentation which I took care of. Looking forward to more changes from you.

@krader1961 krader1961 closed this Apr 12, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants