You are not logged in.

#1 2016-12-17 10:05:44

shulamy
Member
From: israel
Registered: 2010-09-11
Posts: 453

pacman behavior

where do i ask to chnge pacman behavior ?

i whant that if i say "y" but in other language,

that pacman will promt me again and not exit like now.

ezik

Offline

#2 2016-12-17 10:31:15

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: pacman behavior

There are cases where "Y" in another language is "n".   So how would that work?

Offline

#3 2016-12-17 15:36:07

shulamy
Member
From: israel
Registered: 2010-09-11
Posts: 453

Re: pacman behavior

i don't know but it works in fedora

ezik

doesn't other language have different ascii  or something else to differ them from english ?

or may be by checking the layout.

ezik

Last edited by shulamy (2016-12-17 15:44:24)

Offline

#4 2016-12-17 15:53:10

apg
Developer
Registered: 2012-11-10
Posts: 211

Re: pacman behavior

I am going to hazard a guess that what fedora does, and what you actually want, is to prompt again on invalid input.  Currently, any unrecognized response is treated as a no.

Offline

#5 2016-12-18 19:24:32

shulamy
Member
From: israel
Registered: 2010-09-11
Posts: 453

Re: pacman behavior

i think you are right.

it's only a minor change in the existing if statement.

ezik

Offline

#6 2016-12-19 18:46:29

shulamy
Member
From: israel
Registered: 2010-09-11
Posts: 453

Re: pacman behavior

	int confirm;
	if(config->op_s_downloadonly) {
		confirm = yesno(_("Proceed with download?"));
	} else {
		confirm = yesno(_("Proceed with installation?"));
	}
	if(!confirm) {
		retval = 1;
		goto cleanup;
	}

ezik

Offline

#7 2016-12-19 22:36:16

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: pacman behavior

apg wrote:

I am going to hazard a guess that what fedora does, and what you actually want, is to prompt again on invalid input.  Currently, any unrecognized response is treated as a no.

I've not been bit by this before, but I would have thought that invalid input would indeed result in reprompting (or error-out) rather than assuming a no or a default.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#8 2016-12-20 11:21:20

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: pacman behavior

shulamy, to make it more consistent, you'd need to modify the question() function in util.c.

If there was tail recursion in C, I'd replace the `return 0` on the last line by a call to question() itself. But for that kind of stuff, recursion might cause issues, so using a do...while might make more sense?

/* presents a prompt and gets a Y/N answer */
__attribute__((format(printf, 2, 0)))
static int question(short preset, const char *format, va_list args)
{
	char response[32];
	int retval;
	FILE *stream;
	int fd_in = fileno(stdin);

	if(config->noconfirm) {
		stream = stdout;
	} else {
		/* Use stderr so questions are always displayed when redirecting output */
		stream = stderr;
	}

	/* ensure all text makes it to the screen before we prompt the user */
	fflush(stdout);
	fflush(stderr);

	do {
		retval = -1;

		fputs(config->colstr.colon, stream);
		vfprintf(stream, format, args);

		if(preset) {
			fprintf(stream, " %s ", _("[Y/n]"));
		} else {
			fprintf(stream, " %s ", _("[y/N]"));
		}

		fputs(config->colstr.nocolor, stream);
		fflush(stream);

		if(config->noconfirm) {
			fprintf(stream, "\n");
			return preset;
		}

		flush_term_input(fd_in);

		if(safe_fgets(response, sizeof(response), stdin)) {
			size_t len = strtrim(response);
			if(len == 0) {
				return preset;
			}

			/* if stdin is piped, response does not get printed out, and as a result
			 * a \n is missing, resulting in broken output */
			if(!isatty(fd_in)) {
				fprintf(stream, "%s\n", response);
			}

			if(mbscasecmp(response, _("Y")) == 0 || mbscasecmp(response, _("YES")) == 0) {
				retval = 1;
			} else if(mbscasecmp(response, _("N")) == 0 || mbscasecmp(response, _("NO")) == 0) {
				retval = 0;
			}
		}
	} while(retval == -1);
	return retval;
}

--edit--
Noticed I was working on an older commit of pacman, fixed.

--edit2--
Actually, I'm not quite sure if this is a good idea - if something goes wrong (e.g. invalid input piped into pacman), infinite loops might occur.

--edit3--
To avoid an infinite loop, pacman could abort after three invalid inputs. However, I'd say that implementing the aborting mechanism is pretty non-trivial, as pacman would still need to do cleanup work.

Last edited by ayekat (2016-12-23 15:30:16)


pkgshackscfgblag

Offline

#9 2016-12-20 19:54:49

shulamy
Member
From: israel
Registered: 2010-09-11
Posts: 453

Re: pacman behavior

@ayekat - i will look into it when i have time

ezik

Offline

Board footer

Powered by FluxBB