~herrhotzenplotz/gcli-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH gcli] ui: teach gcli when to disable the progress spinner

Details
Message ID
<20240613171044.15951-1-mail@gjnoonan.co.uk>
DKIM signature
pass
Download raw message
Patch: +47 -2
GCLI will display a progress spinner whilst processing, and making
external requests via curl. This can be quite jarring when both not
running in a TTY, or using a dumb terminal. Some people may just wish
to not see it.

gcli has been taught to disable the progress spinenr when configured to
to so. This can be configured in one of three ways.

  1) setting GCLI_NOSPINNER to 1/true in the ENV
  2) passing --no-spinner as an argument to the `gcli` command
  3) in your global .gcli. config you can set `disable-spinner=true` in
     the default section

Signed-off-by: Gavin-John Noonan <mail@gjnoonan.co.uk>
---
 docs/gcli.1.in               |  9 +++++++++
 docs/gcli.5.in               |  5 +++++
 include/gcli/cmd/cmdconfig.h |  1 +
 src/cmd/cmdconfig.c          | 29 +++++++++++++++++++++++++++++
 src/cmd/gcli.c               |  5 +++--
 5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/docs/gcli.1.in b/docs/gcli.1.in
index 09f8835..2997de8 100644
--- a/docs/gcli.1.in
+++ b/docs/gcli.1.in
@@ -181,6 +181,15 @@ If set to
escape sequences. See
.Sx OPTIONS
(--colours).
.It Ev GCLI_NOSPINNER
If set to
.Sq 1 ,
.Sq y or
.Sq yes
(capitalization ignored) this will disable the animated spinnner when
gcli is making requests. See
.Sx OPTIONS
(--disable-spinner)
.El
.Sh FILES
.Bl -tag -width ${XDG_CONFIG_HOME}/gcli/config -compact
diff --git a/docs/gcli.5.in b/docs/gcli.5.in
index 64f33b8..1d94aee 100644
--- a/docs/gcli.5.in
+++ b/docs/gcli.5.in
@@ -55,6 +55,11 @@ Section name of a default Gitea account to use whenever the account
is unspecified on the command line or in the environment. See
.Ev GCLI_ACCOUNT in
.Xr gcli 1 .
.It disable-spinner
Disable the progress spinner in the ui, GCLU uses this when making requests.
this can also be set, and overriden with the
.Ev GCLI_NOSPINNER
environment variable.
.El
.Pp
All other sections define accounts for forges. Each of these account
diff --git a/include/gcli/cmd/cmdconfig.h b/include/gcli/cmd/cmdconfig.h
index b60fbe7..8a26543 100644
--- a/include/gcli/cmd/cmdconfig.h
+++ b/include/gcli/cmd/cmdconfig.h
@@ -66,6 +66,7 @@ sn_sv gcli_config_get_override_default_account(struct gcli_ctx *ctx);
bool gcli_config_pr_inhibit_delete_source_branch(struct gcli_ctx *ctx);
int gcli_config_get_repo(struct gcli_ctx *ctx, char const **, char const **);
int gcli_config_have_colours(struct gcli_ctx *ctx);
int gcli_config_display_progress_spinner(struct gcli_ctx *ctx);
struct gcli_config_entries const *gcli_config_get_section_entries(
	struct gcli_ctx *ctx, char const *section_name);

diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c
index d874513..5df9a32 100644
--- a/src/cmd/cmdconfig.c
+++ b/src/cmd/cmdconfig.c
@@ -64,6 +64,7 @@ struct gcli_config {
	int override_forgetype;
	int colours_disabled;       /* NO_COLOR set or output is not a TTY */
	int force_colours;          /* -c option was given */
	int no_spinner;            	/* don't show a progress spinner */

	sn_sv  buffer;
	void  *mmap_pointer;
@@ -472,6 +473,9 @@ readenv(struct gcli_config *cfg)
	tmp = getenv("NO_COLOR");
	if (tmp && tmp[0] != '\0')
		cfg->colours_disabled = checkyes(tmp);

	if ((tmp = getenv("GCLI_NOSPINNER")))
		cfg->no_spinner = checkyes(tmp);
}

int
@@ -515,6 +519,10 @@ gcli_config_parse_args(struct gcli_ctx *ctx, int *argc, char ***argv)
		  .has_arg = no_argument,
		  .flag    = &cfg->colours_disabled,
		  .val     = 0 },
		{ .name    = "no-spinner",
		  .has_arg = no_argument,
		  .flag    = &cfg->no_spinner,
		  .val     = 1 },
		{ .name    = "type",
		  .has_arg = required_argument,
		  .flag    = NULL,
@@ -974,3 +982,24 @@ gcli_config_have_colours(struct gcli_ctx *ctx)

	return !cfg->colours_disabled;
}

int
gcli_config_display_progress_spinner(struct gcli_ctx *ctx)
{
	ensure_config(ctx);

	struct gcli_config *cfg;
	cfg = ctx_config(ctx);

	if (cfg->no_spinner)
		return 0;

	sn_sv cfg_entry = gcli_config_find_by_key(ctx, "defaults", "disable-spinner");
	if (sn_sv_null(cfg_entry))
		return 1;

	if (!checkyes(sn_sv_to_cstr(cfg_entry)))
		return 0;

	return 1;
}
diff --git a/src/cmd/gcli.c b/src/cmd/gcli.c
index 853b0a5..d6a4af4 100644
--- a/src/cmd/gcli.c
+++ b/src/cmd/gcli.c
@@ -344,8 +344,6 @@ main(int argc, char *argv[])
	if (gcli_config_init_ctx(g_clictx) < 0)
		errx(1, "gcli: error: failed to init context: %s", gcli_get_error(g_clictx));

	gcli_set_progress_func(g_clictx, gcli_progress_func);

	/* Initial setup */
	setup_subcommand_table();

@@ -379,5 +377,8 @@ main(int argc, char *argv[])
		return EXIT_FAILURE;
	}

	if(gcli_config_display_progress_spinner(g_clictx))
		gcli_set_progress_func(g_clictx, gcli_progress_func);

	return sc->fn(argc, argv);
}
-- 
2.45.1
Details
Message ID
<2328915.mfXeX5GmMH@triton>
In-Reply-To
<20240613171044.15951-1-mail@gjnoonan.co.uk> (view parent)
DKIM signature
pass
Download raw message
On Thursday, 13 June 2024 19:10:42 CEST Gavin-John Noonan wrote:

> diff --git a/docs/gcli.1.in b/docs/gcli.1.in
> index 09f8835..2997de8 100644
> --- a/docs/gcli.1.in
> +++ b/docs/gcli.1.in
> @@ -181,6 +181,15 @@ If set to
>  escape sequences. See
>  .Sx OPTIONS
>  (--colours).
> +.It Ev GCLI_NOSPINNER
> +If set to
> +.Sq 1 ,
> +.Sq y or
> +.Sq yes
> +(capitalization ignored) this will disable the animated spinnner when
> +gcli is making requests. See
> +.Sx OPTIONS
> +(--disable-spinner)
The documentation for this reference is missing. This also applies to the 
internal usage printed by gcli's help. I will add/update.

> diff --git a/docs/gcli.5.in b/docs/gcli.5.in
> index 64f33b8..1d94aee 100644
> --- a/docs/gcli.5.in
> +++ b/docs/gcli.5.in
> @@ -55,6 +55,11 @@ Section name of a default Gitea account to use whenever
> the account is unspecified on the command line or in the environment. See
>  .Ev GCLI_ACCOUNT in
>  .Xr gcli 1 .
> +.It disable-spinner
> +Disable the progress spinner in the ui, GCLU uses this when making
Will fix this typo.

> diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c
> index d874513..5df9a32 100644
> --- a/src/cmd/cmdconfig.c
> +++ b/src/cmd/cmdconfig.c
> @@ -974,3 +982,24 @@ gcli_config_have_colours(struct gcli_ctx *ctx)
> 
>  	return !cfg->colours_disabled;
>  }
> +
> +int
> +gcli_config_display_progress_spinner(struct gcli_ctx *ctx)
> +{
> +	ensure_config(ctx);
> +
> +	struct gcli_config *cfg;
> +	cfg = ctx_config(ctx);
> +
> +	if (cfg->no_spinner)
> +		return 0;
> +
> +	sn_sv cfg_entry = gcli_config_find_by_key(ctx, "defaults",
> "disable-spinner"); +	if (sn_sv_null(cfg_entry))
> +		return 1;
> +
> +	if (!checkyes(sn_sv_to_cstr(cfg_entry)))
> +		return 0;
This condition is incorrect. When the variable is set to true we do not want 
to show the spinner (and thus return false). I will fix this up.

Nico
Details
Message ID
<D1Z6XSAVG0RH.3CIGWYBKYL1D7@gjnoonan.co.uk>
In-Reply-To
<2328915.mfXeX5GmMH@triton> (view parent)
DKIM signature
pass
Download raw message
On Thu Jun 13, 2024 at 8:43 PM UTC, Nico Sonack wrote:
> This condition is incorrect. When the variable is set to true we do not want 
> to show the spinner (and thus return false). I will fix this up.
Ah yes, I've just looked again and the logic I added in 
src/cmd/gcli.c:main is inverted. I thought I was going crazy for a while 
when the config was set and it worked.

Thanks for fixing up the various mistakes, I would have been happy to 
send v2

-g
Reply to thread Export thread (mbox)