Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steamrt
steam-runtime-tools
Commits
a8f96bd5
Commit
a8f96bd5
authored
7 years ago
by
Colin Walters
Browse files
Options
Downloads
Patches
Plain Diff
console: Add an "n items" API
It's often really useful to see the counts, not just the percentage.
parent
31ef1961
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
glnx-console.c
+26
-0
26 additions, 0 deletions
glnx-console.c
glnx-console.h
+5
-1
5 additions, 1 deletion
glnx-console.h
with
31 additions
and
1 deletion
glnx-console.c
+
26
−
0
View file @
a8f96bd5
...
...
@@ -280,6 +280,32 @@ glnx_console_progress_text_percent (const char *text,
text_percent_internal
(
text
,
percentage
);
}
/**
* glnx_console_progress_n_items:
* @text: Show this text before the progress bar
* @current: An integer for how many items have been processed
* @total: An integer for how many items there are total
*
* On a tty, print to the console @text followed by [@current/@total],
* then an ASCII art progress bar, like glnx_console_progress_text_percent().
*
* You must have called glnx_console_lock() before invoking this
* function.
*/
void
glnx_console_progress_n_items
(
const
char
*
text
,
guint
current
,
guint
total
)
{
g_return_if_fail
(
current
<=
total
);
g_return_if_fail
(
total
>
0
);
g_autofree
char
*
newtext
=
g_strdup_printf
(
"%s (%u/%u)"
,
text
,
current
,
total
);
/* Special case current == total to ensure we end at 100% */
int
percentage
=
(
current
==
total
)
?
100
:
(((
double
)
current
)
/
total
*
100
);
glnx_console_progress_text_percent
(
newtext
,
percentage
);
}
void
glnx_console_text
(
const
char
*
text
)
{
...
...
This diff is collapsed.
Click to expand it.
glnx-console.h
+
5
−
1
View file @
a8f96bd5
...
...
@@ -36,7 +36,11 @@ void glnx_console_lock (GLnxConsoleRef *ref);
void
glnx_console_text
(
const
char
*
text
);
void
glnx_console_progress_text_percent
(
const
char
*
text
,
guint
percentage
);
guint
percentage
);
void
glnx_console_progress_n_items
(
const
char
*
text
,
guint
current
,
guint
total
);
void
glnx_console_unlock
(
GLnxConsoleRef
*
ref
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment