Skip to content

UI script

Derisis13 edited this page Jun 30, 2022 · 1 revision

ani-cli UI script

ani-cli v3 is modularized, so there's an option to re-implement modules and switch them to achieve different behaviour. One of such modules is the UI module which contains all functions that define an user interface for the script.

loading the UI

To install an UI for ani-cli replace the UI file in $project_root/lib/ani-cli where project root is the installation root (usually /usr/local). When the script starts up, it always sources whichever file is called UI in this directory. The file will be read, and code will be executed. This is when function definitions are loaded and if there's any code that doesn't belong to any function is run. The sourcing of the UI happens after the innitialization of global constants but before the processing the program arguments.

Functions of the UI

For ani-cli to work properly the following functions need to be implemented with the interfaces as described:

inf ()

  • Purpose: display an informational message (such as "now playing")
  • Input: $*: the message that should be displayed
  • Output: nothing
  • Side effect: display message in $*

err ()

  • Purpose: display an error message (such as "dependency not found")
  • Input: $*: the error message
  • Output: nothing
  • Side effect: display message in $*

progress ()

  • Purpose: display a temporary message (such as "searching episodes...")
  • Input: $*: the temporary message
  • Output: nothing
  • Side effect: displays a message that is overwritten by the next

prompt ()

  • Purpose: get an user input (such as query) and display associated message (such as "Search anime")
  • Input: $*: the message associated with the input
  • Output: sets REPLY and REPLY2: REPLY is the input to the first whitespace, REPLY2 is the rest of the input
  • Side effect: display the message in $*

retry ()

  • Purpose: get an user input (such as ep_choice) and display associated error message (such as "Episode out of range")
  • Input: $*: the error message
  • Output: sets REPLY and REPLY2: REPLY is the input to the first whitespace, REPLY2 is the rest of the input
  • Side effect: display the message in $*

debug ()

  • Purpose: display a debug message of a referrer and associated video links
  • Input: $1: the referrer, $2: associated links (in a single string, newline separated)
  • Output: nothing
  • Side effect: clearly show the referrer and the associated links. This is only used for debugging the scraping

selection_menu ()

  • Purpose: provide the user with a selection menu and captures the user input
  • Input: $*: the menu lines separated by newlines. In each line until the first whitespace is the line's associated option that the user is expected to input to select the line (processing done by the main script)
  • Output: sets REPLY to the input until the first whitespace
  • Side effect: displays menu lines with associated options if needed

ui_version_text ()

  • Purpose: Display version info about the UI. It's recommended to include the version as well as the UI name (such as "Classic"). This function is called with version_text () which uses prompt.
  • Input: nothing
  • Output: nothing
  • Side effect: displays UI version and name.

Limitations

  • Many functions achieve similar functionality with small differences. Feel free to reuse functions, but remember to implement all.
  • There's no dependency check for UIs from the main script. You can however always use dep_ch in the body of the UI file, and it'll be executed on sourcing.
  • Currently when using ani-cli -U the default (classic) UI is downloaded instead of what UI is currently installed. We're aware of this issue and working on a solution.