Private
Server IP : 195.201.23.43  /  Your IP : 18.218.25.144
Web Server : Apache
System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64
User : kdecoratie ( 1041)
PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /bin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /bin/spinner
#!/usr/bin/env perl
package spinner;
use strict;
use warnings;
use 5.010;
use Term::Spinner::Color;
use Getopt::Long qw( GetOptionsFromArray );
use Pod::Usage;
use Time::HiRes qw(sleep);
use utf8;
use open ':std', ':encoding(UTF-8)';
use sigtrap qw/handler finished normal-signals/;

# I have no idea if this works.
if ($^O eq 'MSWin32') {
  require Win32::Console::ANSI;
  Win32::Console::ANSI->import();
}
use Term::ANSIScreen qw(:cursor);

my $done;    # Set this in signal handleer to stop spinning.
my $last_size;

sub main {
  my ($argv) = @_;
  my %opt;
  GetOptionsFromArray($argv, \%opt, 'help|h', 'color|c', 'colorcycle|r',
    'seq|s',);
  pod2usage(0) if $opt{help};

  # setup the arguments for constructing the spinner
  my %args;
  if     ($opt{seq})        { $args{seq}        = $opt{seq} }
  if     ($opt{color})      { $args{color}      = $opt{color} }
  if     ($opt{colorcycle}) { $args{colorcycle} = $opt{colorcycle} || 0 }
  if     ($opt{delay})      { $args{delay}      = $opt{delay} }
  unless ($args{delay})     { $args{delay}      = 0.2 }

  my $s = Term::Spinner::Color->new(%args);

  # XXX Maybe hacky. Store current cursor position.
  savepos();
  $s->start();
  while (1) {
    $last_size = $s->{last_size};
    sleep $args{delay};
    $s->next();
  }
  return 0;
}

sub finished {
  my $done = 1;
  my $bksp = chr(0x08);

  # try two ways to get back to original position
  my $back = $bksp x $last_size;
  print $back;
  loadpos();
  print "\x1b[?25h";    # Show cursor
  exit 0;
}

exit main(\@ARGV);

__END__

=head1 NAME

spinner - A command to print a spinner and wait for a signal to stop.

=head1 SYNOPSIS

One-liner from a POSIX-y shell:

    # spinner & PID=$!; sleep 5; kill $PID

In a POSIX-y script:

    spinner &
    PID=$!
    # Do some stuff
    sleep 5
    kill $PID

In the above examples, "sleep 5" would be replaced with whatever long-running
work you need to do. It can be one command or many.

=head1 DESCRIPTION

This command can be used in shell scripts to print a spinner while you do
stuff in the background. Once you've completed your work, you stop the spinner
by sending a signal to the PID of the spinner process.

If you're working with Perl, you should use the Term::Spinner::Color module
directly instead. If you prefer a pure-shell implementation, I've also built
https://github.com/swelljoe/spinner which has nearly identical behavior, but
only requires a POSIX-y shell.
Private