Console/ru

From KolibriOS wiki
Jump to navigation Jump to search

console.obj - специализированная библиотека для создания консольного окна. Входит в состав ночных сборок.

Описание функций console.obj

console.obj экспортирует следующие функции:

   typedef unsigned long dword; /* 32-bit unsigned integer */ 
   typedef unsigned short word; /* 16-bit unsigned integer */ 


con_init

Инициализация консоли. Должна быть вызвана только один раз.

   void __stdcall con_init(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); 

Аргументы:

   wnd_width, wnd_height - ширина и высота (в единицах знаков) видимой области; 
   scr_width, scr_height - ширина и высота (в единицах знаков) консольного окна; 

Любой из этих четырёх параметров может быть равен -1 (=0xFFFFFFFF) для использования значений по умолчанию;

   title - заголовок окна консоли. 

con_exit

Функция для завершения консольного приложения. Рекомендуется использовать в конце программы. void __stdcall con_exit(bool bCloseWindow)

Аргументы: если boolean CloseWindow равен нулю, к заголовку окна добавляется строка "[Finished]". Само окно остаётся открытым.

con_set_title

Установить заголовок нового окна.

   void __stdcall con_set_title(const char* title); 

con_write_asciiz

Вывести ASCIIZ-строку на конкретную позицию, со смещением текущей позиции. [[File:

   void __stdcall con_write_asciiz(const char* string)|thumbnail]]

con_write_string

Функция аналогична con_write_asciiz, однако требуется указать длину строки как отдельный параметр.

   void __stdcall con_write_string(const char* string, dword length); 

con_printf

Стандартная функция "printf" из ANSI C.

   int __cdecl con_printf(const char* format, ...) 

con_get_flags

Получить выходные флаги.

   dword __stdcall con_get_flags(void); 

con_set_flags

Установить флаги вывода.

   dword __stdcall con_set_flags(dword new_flags); 

This function returns previous values.Эта функция возваращет предыдущее установленное значение. Флаги (битовая маска):

/* цвет текста */

   define CON_COLOR_BLUE 0x01
   define CON_COLOR_GREEN 0x02
   define CON_COLOR_RED 0x04
   define CON_COLOR_BRIGHT 0x08

/* цвет фона */

   define CON_BGR_BLUE 0x10
   define CON_BGR_GREEN 0x20
   define CON_BGR_RED 0x40
   define CON_BGR_BRIGHT 0x80

/* управление выводом */

   define CON_IGNORE_SPECIALS 0x100

/* if this flag is cleared, function interprets special characters: 10 ('\n') - next line 13 ('\r') - carriage return 8 ('\b') - backspace 9 ('\t') - tab 27 ('\033' = '\x1B') - the beginning of Esc-sequences; otherwise, these characters will be displayed like ordinary characters. */ /* Supported Esc-sequences: Esc[<number1>;<number2>;<number3>m - choice of character attributes: You can specify one, two or three codes in any order; 0 = normal mode (white on black) 1 = bright selection 5 = bright background 7 = inverse mode (black on white) 30 = black characters 31 = red characters 32 = green characters 33 = brown characters 34 = blue characters 35 = purple characters 36 = turqoise characters 37 = white characters 40 = black background 41 = red background 42 = green background 43 = brown background 44 = blue background 45 = purple background 46 = turqoise background 47 = white background The following sequences appeared in version 5 of library: Esc[2J - clear screen, move cursor to upper left corner Esc[<number1>;<number2>H = Esc[<number1>;<number2>f - move cursor to <number1>,<number2> Esc[<number>A - move cursor to <number> lines up Esc[<number>B - move cursor to <number> lines down Esc[<number>C - move cursor to <number> positions right Esc[<number>D - move cursor to <number> positions left

   /

/* сигнал "консоль закрыта"; появился в версии 6; ингорируется функцией con_set_flags */

   define CON_WINDOW_CLOSED 0x200

Значение по умолчанию для флагов = 7. (серый текст на белом фоне)

con_get_font_height

Получить высоту шрифта.

   int __stdcall con_get_font_height(void); 

con_get_cursor_height

Получить высоту курсора.

   int __stdcall con_get_cursor_height(void); 

con_set_cursor_height

Установить высоту курсора.

   int __stdcall con_set_cursor_height(int new_height); 

This function returns the previous value. An attempt to set the value out of the correct interval (from 0 to font_height-1) is ignored. Cursor with zero height isn't displayed. Default value: - 15% from font height.

con_getch

Прочитать символ с клавиатуры.

   int __stdcall con_getch(void); 

For normal characters function returns ASCII-code. For extended characters (eg, Fx, and arrows), first function call returns 0 and second call returns the extended code (similar to the DOS-function input). Starting from version 7, after closing the console window, this function returns 0.

con_getch2

Прочитать символ с клавиатуры.

   word __stdcall con_getch2(void); 

Low byte contains the ASCII-code (0 for extended characters), high byte - advanced code (like in BIOS input functions). Starting from version 7, after closing the console window, this function returns 0.


con_kbhit

Возвращает 1, если клавиша нажата, и 0 в противном случае.

   int __stdcall con_kbhit(void); 

To read pressed keys use con_getch and con_getch2. Starting from version 6, after closing the console window, this function returns 1.

con_gets

Прочитать строку с клавиатуры.

   char* __stdcall con_gets(char* str, int n); 

Reading is interrupted when got "new line" character, or after reading the (n-1) characters (depending on what comes first). In the first case the newline is also recorded in the str. The acquired line is complemented by a null character. Starting from version 6, the function returns a pointer to the entered line if reading was successful, and NULL if the console window was closed.


con_gets2_callback

Con_gets completely analogous, except that when the user press unrecognized key, it calls the specified callback-procedure (which may, for example, handle up / down for history and tab to enter autocompletion).

   typedef int (__stdcall * con_gets2_callback)(int keycode, char** pstr, int* pn, int* ppos); 
   char* __stdcall con_gets2(con_gets2_callback callback, char* str, int n); 

You should pass to the procedure: key code and three pointers - to the string, to the maximum length and to the current position. function may change the contents of string and may change the string itself (for example, to reallocate memory for increase the limit), maximum length, and position of the line - pointers are passed for it. Return value: 0 = line wasn't changed 1 = line changed, you should remove old string and display new, 2 = line changed, it is necessary to display it; 3 = immediately exit the function.

Starting from version 6, this function returns a pointer to the entered line with the successful reading, and NULL if the console window was closed.

con_cls

Clear screen and set cursor at upper left corner.

   void __stdcall con_cls(); 

con_get_cursor

Wrote current (x) coordinate of cursor to *px, and (y) to *py.

   void __stdcall con_get_cursor_pos(int* px, int* py); 

con_set_cursor_pos

Set the cursor position to the specified coordinates. If any of the parameters beyond the relevant range (from 0 to 1 scr_width-for x, from 0 to 1 for scr_height-y, scr_width scr_height and were asked if call con_init), then the corresponding coordinate of the cursor does not change.

   void __stdcall con_set_cursor_pos(int x, int y);



Template:Библиотеки