14.12.2017 14:05
OlegON
 
Иногда необходимо, чтобы значение отображалось каждый раз в той же самой строке, например, при каких-то счетчиках. Сделать это очень просто - управляющими кодами. Чтобы не забывать, приведу их здесь:

Курсор в начало
Код:
<ESC>[{ROW};{COLUMN}H
устанавливает курсор в определенную позицию, если параметры опустить (<ESC>[H), то курсор будет установлен в левый верхний угол.

Курсор вверх
Код:
<ESC>[{COUNT}A
передвигает курсор на COUNT строк вверх, по умолчанию значение 1. Дальше значение COUNT и умолчание описывать не буду, они аналогичны.

Курсор вниз
Код:
<ESC>[{COUNT}B
Курсор вправо
Код:
<ESC>[{COUNT}C
Курсор влево
Код:
<ESC>[{COUNT}D
Принудительная позиция
Код:
<ESC>[{ROW};{COLUMN}f
Сохранить позицию
Код:
<ESC>[s
Восстановить позицию
Код:
<ESC>[u
Сохранить позицию
Код:
<ESC>7
Восстановить позицию
Код:
<ESC>8
Например, для счетчика можно использовать код
Код:
echo "\033[s";
echo $counter."\n";
echo "\033[u";
переменная $counter будет печататься каждый раз в одном и том же месте
Код:
echo "\033[100D";
переместит курсор на 100 позиций влево

Дополнительные коды:
Цитата:
Scrolling

Scroll Screen <ESC>[r

Enable scrolling for entire display.

Scroll Screen <ESC>[{start};{end}r

Enable scrolling from row {start} to row {end}.

Scroll Down <ESC>D

Scroll display down one line.

Scroll Up <ESC>M

Scroll display up one line.

Tab Control

Set Tab <ESC>H

Sets a tab at the current position.

Clear Tab <ESC>[g

Clears tab at the current position.

Clear All Tabs <ESC>[3g

Clears all tabs.

Erasing Text

Erase End of Line <ESC>[K

Erases from the current cursor position to the end of the current line.

Erase Start of Line <ESC>[1K

Erases from the current cursor position to the start of the current line.

Erase Line <ESC>[2K

Erases the entire current line.

Erase Down <ESC>[J

Erases the screen from the current line down to the bottom of the screen.

Erase Up <ESC>[1J

Erases the screen from the current line up to the top of the screen.

Erase Screen <ESC>[2J

Erases the screen with the background colour and moves the cursor to home.

Printing
Some terminals support local printing:

Print Screen <ESC>[i

Print the current screen.

Print Line <ESC>[1i

Print the current line.

Stop Print Log <ESC>[4i

Disable log.

Start Print Log <ESC>[5i

Start log; all received text is echoed to a printer.

Define Key

Set Key Definition <ESC>[{key};"{string}"p

Associates a string of text to a keyboard key. {key} indicates the key by its ASCII value in decimal.

Set Display Attributes

Set Attribute Mode <ESC>[{attr1};...;{attrn}m

Sets multiple display attribute settings. The following lists standard attributes:

0 Reset all attributes
1 Bright
2 Dim
4 Underscore
5 Blink
7 Reverse
8 Hidden

Foreground Colours
30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White

Background Colours
40 Black
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White
например
Код:
echo "\033[31m";
скажет, что весь последующий текст выводится красным цветом.
Часовой пояс GMT +3, время: 15:57.

Форум на базе vBulletin®
Copyright © Jelsoft Enterprises Ltd.
В случае заимствования информации гипертекстовая индексируемая ссылка на Форум обязательна.