Skip to content

Conversation

@jNullj
Copy link
Contributor

@jNullj jNullj commented May 6, 2024

Adds interactive playback controls based of #2999 .

Status:

  • Pausing and resuming playback: space to toggle.
  • Adjusting playback speed: up/down (arrows), +/- 0.1x steps
  • Stepwise navigation: right (arrow) for step forward
  • Add this info and key-bindings to docs/man.

I did not add all suggested in #2999 , These are what i think the most important.
Adding a backward step is non trivial without rewriting lots of how the playback works, and most terminals allow to scroll back the stream anyway.
Speed for holding the key-bind is also self emerging from the inputDelay.

So i think its best to attempt to merge this basic form so it ships the core features with less complex changes.

jNullj added 3 commits May 7, 2024 00:10
Provision for retrival of playback interactive controls using fgetwc without blocking.
delay_for does not change delay.
Hint about that using const.
This allows for usage of const delay and improves readability.
Adds pause to replay_setup.
Adds functions to toggle and get pause state.
Adds stdin keys read - looks for space for pause toggle.
Adds replay pause to replay render loop.
@jNullj
Copy link
Contributor Author

jNullj commented May 6, 2024

I intend on changing that, pause currently ignores the current step.
I will change the loop to check for input every inputDelay to avoid blocking from current step.
This will also provide a more responsive control for all controls.

@jNullj jNullj force-pushed the scriptreplay/add-interactive-playback/2999 branch from 7e8f5e6 to 6f922a3 Compare May 10, 2024 13:34
@jNullj jNullj marked this pull request as ready for review May 10, 2024 13:47
@jNullj jNullj changed the title [WIP] scriptreplay: add interactive playback controls scriptreplay: add interactive playback controls May 10, 2024
{
static const struct timeval mindelay = { .tv_sec = 0, .tv_usec = 100 };
static const struct timeval inputDelay = { .tv_sec = 0, .tv_usec = 100000 };
struct timeval stepDelay = { 0, 0 };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep the variable names consistent. We rarely use C++-like names like "fooBar;" it seems better to use "inputdelat" or "input_delay."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 28d7c58

isterm = setterm(&saved, &saved_flag);

do {
switch (fgetwc(stdin)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is include/fgetwc_or_err.h with fgetwc_or_err(). I guess it can increase the reliability of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO we should not use fgetwc_or_err as we expect fgetwc to have many instances of WEOF with errno !=0 when no user input is added to the stream.

// section from fgetwc_or_err
if (ret == WEOF && errno != 0)
		err(EXIT_FAILURE, _("fgetwc() failed"));

We run at non-blocking mode and this results in this error showing up every time no input is found getwc() failed: Resource temporarily unavailable, which is very common and repeats often during a replay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point, I forgot about the non-blocking mode ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, why do we need widechar (fgetwc() and wchat_t) here? I guess it will work with arbitrary function like fgetc().

Copy link
Contributor Author

@jNullj jNullj May 24, 2024

Choose a reason for hiding this comment

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

At start i hoped it would give me a multi-byte char for the key-press, but i didn't know that they don't count, and so fgetwc only reads one char at a time for this usage.
I fogot to change that after i updated the logic
I will change that to fgetc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed with 7000120

break;

if (replay_get_is_paused(setup))
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please follow the current coding style. It means "if ( ) {" rather than "if ( )\n{".
https://www.kernel.org/doc/html/v4.10/process/coding-style.html#placing-braces-and-spaces

We also do not use "//" for comments :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 0bfd75d

jNullj added 3 commits May 22, 2024 23:25
there is no real reason to use fgetwc here as arrow key press is not read as a multi-byte by fgetwc and the logic implemented here also reads the keypress byte by bytes.
@karelzak
Copy link
Collaborator

https://github.com/util-linux/util-linux/actions/runs/9228958044/job/25445611203?pr=3015

term-utils/scriptreplay.c: In function ‘main’:
term-utils/scriptreplay.c:330:5: error: a label can only be part of a statement and a declaration is not a statement
  330 |     int first_char = fgetc(stdin);
      |     ^~~
make[2]: *** [Makefile:11104: term-utils/scriptreplay.o] Error 1

jNullj added 2 commits May 27, 2024 19:18
This commit fix clang compile issue.
Replace local char veriables with generic ch already used by the in function.
Reduce memory usage.
Linux kernel coding style prefers switch and case at the same indent level.
@jNullj
Copy link
Contributor Author

jNullj commented May 27, 2024

My bad, used gcc at my setup.
I noticed we already have a generic char to use in another loop in main int ch so i used it to save up on memory a bit. I think it fits better and also makes it compatible with clang.
Fixed with c2c16fd and tested both with gcc and clang this time (i have clang-17 tho).

Also noticed the switch-case coding style is not as recommended by the linux kernel and fixed the indent with d616c2f

@karelzak karelzak merged commit c22152e into util-linux:master May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants