Documentation
Term helper
Table of Contents ▼
Presentation
This helper facilitates terminal management (TTY) when writing command-line scripts.
The \Temma\Utils\Term object provides static methods.
input()
This static method retrieves text entered by the user.
Method signature:
input() : string
Example:
use \Temma\Utils\Term as TµTerm;
print("What is your name?\n");
$name = TµTerm::input();
print("Hello '$name'\n");
password()
This static method retrieves text entered by the user, without the text appearing on the screen.
Method signature:
password() : string
Example:
use \Temma\Utils\Term as TµTerm;
print("Please enter your password\n");
$pwd = TµTerm::input();
if (mb_strlen($pwd) < 12)
print("Your password is too short\n");
clear()
Clears the screen.
Method signature:
clear() : void
Example:
\Temma\Utils\Term::clear();
clearFromCursor()
Clears the screen from the current position of the cursor.
Method signature:
clearFromCursor() : void
Example:
\Temma\Utils\Term::clearFromCursor();
reset()
Clears the screen and resets its configuration. Display history is lost.
Method signature:
reset() : void
Example:
\Temma\Utils\Term::reset();
clearLine()
Clears the line on which the cursor is positioned. The cursor is repositioned at the beginning of the line.
Method signature:
clearLine() : void
Example:
\Temma\Utils\Term::clearLine();
clearLineFromCursor()
Clears the current line from the position of the cursor.
Method signature:
clearLineFromCursor() : void
Example:
\Temma\Utils\Term::clearLineFromCursor();
hideCursor()
Hides the cursor.
Method signature:
hideCursor() : void
Example:
\Temma\Utils\Term::hideCursor();
showCursor()
Shows the cursor.
Method signature:
showCursor() : void
Example:
\Temma\Utils\Term::showCursor();
saveCursor()
Saves the current position of the cursor (in order to restore it later with the restoreCursor() method).
Method signature:
saveCursor() : void
Example:
\Temma\Utils\Term::saveCursor();
restoreCursor()
Restore the position of the cursor, which has been saved with the saveCursor() method.
Method signature:
restoreCursor() : void
Example:
\Temma\Utils\Term::restoreCursor();
moveCursorHome()
Moves the cursor to the top-left corner (position 0,0) of the terminal.
Method signature:
moveCursorHome() : void
Example:
\Temma\Utils\Term::moveCursorHome();
moveCursorTo()
Moves the cursor to the given coordinates.
Method signature:
moveCursorTo(int $x, int $y) : void
Example:
\Temma\Utils\Term::moveCursorTo(17, 4);
moveCursorLineStart()
Moves the cursor to the start of the current line.
Method signature:
moveCursorLineStart() : void
Example:
\Temma\Utils\Term::moveCursorLineStart();
moveCursorUp()
Moves the cursor up by the number of lines passed in parameter (1 line by default).
Method signature:
moveCursorUp(int $nbrLines=1) : void
Example:
use \Temma\Utils\Term as TµTerm;
// move one line up
TµTerm::moveCursorUp();
// moves three lines up
TµTerm::moveCursorUp(3);
moveCursorDown()
Moves the cursor down by the number of lines passed in parameter (1 line by default).
Method signature:
moveCursorDown(int $nbrLines=1) : void
Example:
use \Temma\Utils\Term as TµTerm;
// move one line down
TµTerm::moveCursorDown();
// move three lines down
TµTerm::moveCursorDown(3);
moveCursorRight()
Moves the cursor to the right of the number of columns passed in parameter (1 column by default).
Method signature:
moveCursorRight(int $nbrColumns=1) : void
Example:
use \Temma\Utils\Term as TµTerm;
// move one column to the right
TµTerm::moveCursorRight();
// move three columns to the right
TµTerm::moveCursorRight(3);
moveCursorLeft()
Moves the cursor to the left by the number of columns passed in parameter (1 column by default).
Method signature:
moveCursorLeft(int $nbrColumns=1) : void
Example:
use \Temma\Utils\Term as TµTerm;
// move one column to the left
TµTerm::moveCursorLeft();
// move three columns to the left
TµTerm::moveCursorLeft(3);
getCursorPosition()
This method returns the current position of the cursor.
Method signature:
getCursorPosition() : array
Example:
use \Temma\Utils\Term as TµTerm;
[$x, $y] = TµTerm::getCursorPosition();
getScreenSize()
This method returns the screen size (number of columns and rows).
Method signature:
getScreenSize(bool $force=false) : array
Parameter:
- $force: true to force retrieval (without using cache). Unnecessary most of the time, as the object updates cached values when the terminal is resized.
Example:
use \Temma\Utils\Term as TµTerml;
[$with, $height] = TµTerm::getScreenSize();
Previous: | Smarty helper |
Next: | Text helper |
Table of Contents
- Migration : How to upgrade from Temma 1.x to version 2
- Installation : Download Temma and install it to start your web project
- Configuration : All the configuration directives of the etc/temma.json file and the optional environment variables
- External libraries : How to use external function libraries
- Routing : Temma's default routing system, and advanced routing
- Log : Use of the log system, management by criticality levels
- Controllers : Essential parts of your web application
- Views : Smarty templates or JSON/CSV/RSS/iCal/INI exports
- Dependency injection : The backbone of your application developments
- Sessions : Extension of user sessions managed by PHP
- Data sources : Unified data access management
- Model : How to use DAOs to access databases
- Execution flow : How to manage the execution flow, between plugins and the controller
- Plugins : How to use plugins, and create your own plugins to modularize your code
- Attributes : How to filter access to controllers and actions
- Tests : To write automated integration tests.
- Command-line interface : To create executable scripts on the command line, automatically initialized by Temma
-
Helpers :
Items offered by Temma to help you in various circumstances
- Command-line scripts
-
Controller + plugin
- Auth : Controller and plugin to manage user authentication
- Plugins
- Attributes
-
Smarty plugins
- urlize : Modifier to transform a text into an URL
- filenamize : Modifier to transform a text into a file name
- nbsp : Modifier to transform spaces into non-breakable spaces
-
Utility objects
- ANSI : To format texts written to standard output
- BaseConvert : To do digital base conversions
- DataFilter : To filter and validate data
- Email : To send emails
- HTMLCleaner : To clean up an HTML stream coming from a WYSIWYG editor
- IniExport : To export data in INI format
- Json : To read JSON streams that may contain comments
- Lock : To lock access to a file, or the execution of the current PHP script
- Registry : To properly store global variables
- Smarty : To process Smarty templates outside the view
- Term : Terminal management (TTY)
- Text : Different treatments on character strings
- Timer : To manage stopwatches