README.org

#+title: PacmanProgressBar in Elixir

Command line progress bar like the one from Arch Linux's pacman package manager.

I got my inspiration from [[https://dennisbeatty.com/cool-clis-in-elixir-with-io-write-2/][Cool CLIs in Elixir with IO.write/2 by Dennis Beatty]], [[https://github.com/henrik/progress_bar][progress_bar by henrik]], my own old project [[https://gitlab.com/Pistrie/pacmanprogressbar][PacmanProgressBar in Java]], and of course the [[https://wiki.archlinux.org/title/pacman][pacman package manager]].

* Table of contents :toc:
  - [[#usage][Usage]]
  - [[#installation][Installation]]
  - [[#license][License]]

** Usage

You can render the progress bar using PacmanProgressBar.render/2. You specify the total amount of tasks being executed and the amount of tasks completed. This uses IO.write/2 to print the bar, and the bar is preceded by a carriage return character to replace the previous bar like so: IO.write("\r[---C-o..."

#+begin_src elixir
PacmanProgressBar.render(30, 7)

#=> [------c-o--o--o--o--o--o--o--]  23%
#+end_src

Running this function multiple times will overwrite the last result.

#+begin_src elixir
PacmanProgressBar.render(30, 7)
PacmanProgressBar.render(30, 12)

#=> [-----------C--o--o--o--o--o--]  40%
#+end_src

You can also get this progress bar in the form of a string, in case that's something you would need.

#+begin_src elixir
PacmanProgressBar.raw(30, 7)

#=> "[------c-o--o--o--o--o--o--o--]  23%"
#+end_src

When the progress bar is complete it will automatically print a newline character.

** Installation

If [[https://hex.pm/docs/publish][available in Hex]], the package can be installed by adding ~pacman_progress_bar~ to your list of dependencies in ~mix.exs~:

#+begin_src elixir
def deps do
  [
    {:pacman_progress_bar, "~> 0.0.0"}
  ]
end
#+end_src

** License

Released under the [[https://www.gnu.org/licenses/lgpl-3.0.html][LGPL]]. This means that your code can freely use this library. It can even be used in proprietary code. The copyleft license only applies to this library itself. See the LGPL page for more information.