Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

13conio Module

The conio module provides following measures to work on a console screen:

To utilize it, import the conio module using import function.

Below is an example to print a frame around a console:

import(conio)

conio.clear()
[w, h] = conio.getwinsize()
conio.moveto(0, 0) {
    print('*' * w)
}
conio.moveto(0, 1 .. (h - 2)) {
    print('*', ' ' * (w - 2), '*')
}
conio.moveto(0, h - 1) {
    print('*' * w)
}
conio.waitkey():raise

13.1Module Function

conio.clear
conio.clear(region?:symbol):void
Clears the screen.

In default, it clears whole the screen. Argument region that takes one of the symbols below would specify the region to be cleared.

conio.getwinsize
conio.getwinsize()
Returns the screen size as a list [width, height].

conio.setcolor
conio.setcolor(fg:symbol:nil, bg?:symbol):map:void {block?}
Sets foreground and background color of text by specifying a color symbol. Available color symbols are listed below:

If fg is set to nil, the foreground color remains unchanged. If bg is omitted or set to nil, the background color remains unchanged.

If block is specified, the color is changed before evaluating the block, and then gets back to what has been set when done.

conio.moveto
conio.moveto(x:number, y:number):map:void {block?}
Moves cursor to the specified position. The most top-left position on the screen is represented as 0, 0.

If block is specified, the cursor is moved before evaluating the block, and then gets back to where it has been when done.

conio.waitkey
conio.waitkey():[raise]
Waits for a keyboard input and returns a character code number associated with the key.

If :raise attribute is specified, hitting Ctrl-C issues a terminating signal that causes the program done.

Character code numbers of some of the special keys are defined as below:


Copyright (C) 2011-2017 ypsitau