Environment Primitives

Summary
Environment Primitives
Macros
cdChange directory.
create_char_mapCreate a display character-map.
get_term_charactersRetrieve terminal special characters.
get_term_featureGet value of a terminal feature.
get_term_featuresRetrieve terminate features.
get_term_keyboardRetrieve the terminal keyboard definitions.
getenvRetrieve an environment variable.
geteuidRetrieve the effective user identifier.
getpidRetrieve the process identifier.
getuidRetrieve the user identifier.
getwdGet current working directory.
inq_backupGet the backup creation mode.
inq_backup_optionGet backup options.
inq_brief_levelRetrieve the editor nesting level.
inq_char_timeoutGet the escape delay.
inq_environmentRetrieve an environment variable.
inq_featureRetrieve an editor feature.
inq_hostnameRetrieve the local host name.
inq_idle_defaultRetrieve idle interval.
inq_idle_timeRetrieve keyboard idle time.
inq_profileRetrieve profile directory.
inq_usernameRetrieve the user name.
putenvSet an environment variable.
set_backupSet backup creation mode.
set_backup_optionSet backup options.
set_char_timeoutSet the escape delay.
set_idle_defaultSet idle interval.
set_term_charactersSet terminal special characters.
set_term_featureSet a terminal attribute.
set_term_featuresDefine terminal attributes.
set_term_keyboardDefine terminal keyboard definitions.
unameRetrieve system information.

Macros

cd

int cd([string dir])

Change directory.

Description

The cd() primitive changes the current directory on the specified drive to the specified path.  Unlike chdir shell expansion shall occur when the path contains special characters, expanding home references ~, wild cards and environment variables.

cd(newdir);

Under DOS/WIN32, if no drive is specified in path then the current drive is assumed.  The path can be either relative to the current directory on the specified drive or it can be an absolute path name

If dir is omitted, the current directory shall be echoed on the command prompt without effecting any change.

cd();

Returns

The cd() primitive returns 1 if successful otherwise zero on error.  When an error has occurred, the global errno contains a value indicating the type of error that has been detected.

See Also

mkdir, rmdir

create_char_map

int create_char_map([int mapid|string name],
 [int start = 0],
[list chars],
 [list flags],
[string name])

Create a display character-map.

Description

The create_char_map() primitive either creates or updates an existing character-map.  Character-map’s determine the mapping between the buffer encoding, special purpose characters and their display representation.

A map represents each of the 256 possible byte values which may be contained within any given 8-byte encoded buffer.  In addition to the 256 base characters a number of special markers for End-Of-Line, Tabs and End-Of-File may also be defined.

The identifier mapid or the alias name either references an existing map or if omitted a new map shall be generated.  On creation a character-map is derived from the system “normal” map.

Upon the existing or created map the specified chars list is then applied starting at the character start, updating each character in sequence until the end of the list is encountered.  Optionally the pairs of integer values contained within the flags list are then applied in the same manor.  If specified, the character-maps alias is changed to name.

Character-map Names

By default two system predefined character-map’s are available known by the names “normal” and “binary”, these are in addition to the number managed by the view’s package; care should be taken not to overwrite these resources prior to understanding the impact.

Special Characters

The follow special character indexes have importance when displaying buffer content and can be controlled using create_char_map for example.

create_char_map("literal", CMAP_EOF, quote_list("[EOF]"));
Constant
Value
Description
CMAP_TABSTART
-
Beginning of a Tab
CMAP_TABVIRTUAL
-
Tab body
CMAP_TABEND
-
Tab end
CMAP_EOL
-
End-of-line marker
CMAP_EOF
-
End-of-file marker

By default, all specials are simple spaces as such invisible.

Note, for CRiSP ™ compatibility the char list may reference 257 characters with the 257th entry being equivalent to CMAP_EOL.

Character Flags

The flags argument should be given as a set of one or more integer pairs:

{ <character>, <flag> }

The character flags available include, with one

Constant
Value
Description
CMAP_DEFAULT
0
Default
CMAP_TAB
1
Horizontal tab
CMAP_BACKSPACE
2
Backspace
CMAP_ESCAPE
3
ESCAPE character

Normal Character Map

The “normal” or default character-map is built using the rules below.

  • control-characters - ^[A-Z] in ASCII, otherwise use of UNICODE 0x2400-0x241F C0 character range.
  • DEL - ^? otherwise UNICODE 0x2421.
  • printable - all characters below 0x80 are themselves, otherwise characters above if 8bit and not 0xff or UNICODE.
  • non-printable - hexadecimal representation of the form 0x##.

Parameters

mapid, nameCharacter-map reference, being either an integer map identifier or the associated map name as a string.  If omitted a unique identifier shall be allocated.
startOptional integer, stating the first character index.
charsCharacter definition list, being a list of integer and/or string values for each character in the sequence starting at the offset start.
flagsCharacter flag list, being one or more pairs of integer values.  Within each pair, The first element is the integer character position, and the second is the integer flag value from the set “Character Flags”.
nameOptional string, being the unique name by which the character-map may be referenced.

Returns

The create_char_map() primitive returns the identifier of the resolved or created character-map otherwise -1 if the specified character map does not exist.

Example

The following enables an ASCII representation for control characters 0 to 31.

int map =
create_char_map(0, NULL,
quote_list(
"<NUL>", "<SOH>", "<STX>", "<ETX>",
"<EOT>", "<ENQ>", "<ACK>", "<BEL>",
"<BS>", "<HT>", "<NL>", "<VT>",
"<FF>", "<CR>", "<SO>", "<SI>",
"<DLE>", "<DC1>", "<DC2>", "<DC3>",
"<DC4>", "<NAK>", "<SYN>", "<ETB>",
"<CAN>", "<EM>", "<SUB>", "<ESC>",
"<FS>", "<GS>", "<RS>", "<US>"),
quote_list('\t', CMAP_TAB));
set_buffer_cmap(map);

Portability

n/a

See Also

inq_char_map

get_term_characters

list get_term_characters([top_left],
[top_right],
 [bottom_left],
[bottom_right],
[vertical],
[horizontal],
 [top_join],
[bottom_join],
[cross],
 [left_join],
[right_join],
[scrol],
[thumb])

Retrieve terminal special characters.

Description

The set_term_characters() primitive retrieves the set of characters which are utilised by the tty console driver to represent window borders.

set_term_characters() operators in one of two modes.  Without arguments a list of strings, one for each character is retrieved.  Alternatively each parameter is either an integer or string variable to be populated with the associated character value.  Values can be omitted by supplying a NULL parameter against the associated character index.

Refer to set_term_characters for the order and meaning of each of these characters.

Parameters

...Integer character value or string escape sequence, one for each character within the set.

Returns

Without any arguments the get_term_characters primitive returns a list of strings, one for each terminal character, in the form name=value.  Otherwise a NULL list is returned.

Portability

n/a

See Also

set_term_characters, set_term_feature

get_term_feature

int get_term_feature( string | int ident,
declare value)

Get value of a terminal feature.

Description

The get_term_feature() primitive retrieves the value associated with the specified attribute ident.

Parameters

identEither the integer identifier or the a string containing the name of the terminal attribute to be retrieved.
valueVariable to populated with the referenced attribute.

Returns

The set_term_feature() primitive returns 0 on success, otherwise 1 on error.

Portability

A GriefEdit extension.

See Also

set_term_feature

get_term_features

list get_term_features(...)

Retrieve terminate features.

Description

The get_term_features() primitive retrieves a list of string pairs one for each terminal attribute.

Parameters

none

Returns

Without any arguments the get_term_features() primitive returns a list of strings, one for each terminal attribute, in the form name=value.  Otherwise a NULL list is returned.

Portability

Many of the return values are only meaningful on systems that use a tty based console interface.

The CRiSPEdit™ version is similar to get_term_feature.

See Also

get_term_keyboard, get_term_feature

get_term_keyboard

list get_term_keyboard()

Retrieve the terminal keyboard definitions.

Description

The get_term_keyboard() primitive retrieves the current terminal keyboard definition.

Under Unix™ console attributes are derived from the system termcap or terminfo databases or similar interfaces under non-unix systems.

See get_term_keyboard for further details.

Parameters

none

Returns

The get_term_keyboard() primitive returns a list of key binding pairs, each pair consisting of an integer key-code plus a string containing the associated escape sequence.

Portability

On systems not utilising a tty based console interface, the list shall be empty.

See Also

set_term_features

getenv

string getenv(string name)

Retrieve an environment variable.

Description

The getenv() primitive searches the environment of the calling process for the environment variable name if it exists and returns the value of that environment variable.  If the specified environment variable cannot be found, an empty string shall be returned.

Parameters

nameString containing the name of the environment variable.

Returns

The getenv() primitive returns the value of the corresponding environment variable, otherwise an empty string.

Portability

n/a

See Also

putenv, inq_environment

geteuid

int geteuid()

Retrieve the effective user identifier.

Description

The geteuid() primitive shall return the effective user ID of the calling process.

Parameters

none

Returns

The geteuid() primitive shall always be successful returning the current effective user identifier.

Portability

n/a

See Also

getpid, getuid

getpid

int getpid()

Retrieve the process identifier.

Description

The getpid() primitive shall return the process ID of the calling process.

Parameters

none

Returns

The getpid() primitive shall always be successful returning the current process identifier.

Portability

n/a

See Also

getuid

getuid

int getuid()

Retrieve the user identifier.

Description

The getuid() primitive shall return the real user ID of the calling process.

Parameters

none

Returns

The getuid() primitive shall always be successful returning the current user identifier.

Portability

n/a

See Also

getpid, geteuid

getwd

int getwd(int ignored,
string dir)

Get current working directory.

Description

The getwd() primitive primitive retrieves the name of the current working directory.

The ignored parameter exists for compatibility with BRIEF.

Returns

The getwd() primitive returns 1 if successful otherwise zero on error.  When an error has occurred, the global errno contains a value indicating the type of error that has been detected.

See Also

cd, mkdir, rmdir

inq_backup

int inq_backup([int bufnum])

Get the backup creation mode.

Description

The inq_backup() primitive retrieves the value of the associated objects backup mode.  If bufnum is specified, then the value of the stated buffer is returned, otherwise upon being omitted the global (default) backup mode shall be returned.

Returns

The inq_backup() primitive returns the current value of the backup flag.

Portability

A GriefEdit extension.

See Also

set_backup, set_backup_option, inq_backup_option

inq_backup_option

declare inq_backup_option(int what,
 [int bufnum])

Get backup options.

Description

The inq_backup_option() primitive retrieves the value of the backup option what for the associated object.  If bufnum is specified, then the value of the stated buffer is returned, otherwise upon being omitted the global (default) backup option shall be modified.

Returns

The inq_backup_option() primitive returns the current value associated with the attribute what, as follows

  • BK_MODE - Backup creation mode, as an integer.
  • BK_AUTOSAVE - Buffer autosave flag, as an integer.
  • BK_DIR - Backup directory, as a string.
  • BK_DIRMODE - Directory creation mode, as an integer.
  • BK_VERSIONS - Number of versions to be maintained, as an integer.
  • BK_PREFIX - Backup filename prefix, as a string.
  • BK_SUFFIX - Backup filename suffix, as a string.
  • BK_ONESUFFIX - Whether only a single suffix to used replacing any existing, as an integer.
  • BK_ASK - Filesize watermark at which point backups shall be prompted before created a backup image, as an integer.
  • BK_DONT - Filesize watermark at which point backups shall not be created regardless of the current backup mode, as an integer.

Portability

A GriefEdit extension.

See Also

set_backup, inq_backup

inq_brief_level

int inq_brief_level()

Retrieve the editor nesting level.

Description

The inq_brief_level() primitive retrieves the number of copies of GRIEF running within the current session.

The original implementation returned the total number of instances in memory, whereas this emulation only reports the number of instances visible with the associated terminal.

This function is provided for compatibility using the getenv interface; see the getenv primitive and the brief macro module for details.

Parameters

none

Returns

The current number of active editor sessions.

Portability

Provided for BRIEF compatibility, retrieving the current GRLEVEL environment variable level.

See Also

inq_environment

inq_char_timeout

int inq_char_timeout()

Get the escape delay.

Description

The inq_char_timeout() primitive retrieves the current value of the terminal escape delay.

Parameters

none

Returns

The inq_char_timeout() primitive returns the current character timeout.

Portability

A GriefEdit extension

See Also

inq_kbd_char, read_char

inq_environment

string inq_environment(string name)

Retrieve an environment variable.

Description

The inq_environment() primitive shall search the environment of the calling process for the environment variable name if it exists and return the value of the environment variable.  If the specified environment variable cannot be found, an empty string shall be returned.

This function is provided for compatibility using the getenv interface; see the getenv primitive and the brief macro module for details.

Parameters

nameString containing the name of the environment variable.

Returns

The inq_environment() primitive returns the value of the corresponding environment variable, otherwise an empty string.

Portability

n/a

See Also

getenv

inq_feature

int|list inq_feature([int|string feature],
[string value])

Retrieve an editor feature.

Description

The inq_feature() primitive tsets the status of the specific feature feature, returning its current configuration value.

Warning:

The inq_feature() primitive is an experimental interface and may change without notice.

Parameters

featureName of the feature.
valueConfiguration value.

Return

The inq_feature() primitive returns non-zero on success, otherwise zero on error.

Macro Portability; A GriefEdit extension.

See Also

set_feature, inq_display_mode, <set>

inq_hostname

string inq_hostname()

Retrieve the local host name.

Description

The inq_hostname() primitive retrieves the name of the local host.

Parameters

none

Returns

The inq_hostname() primitive returns a string containing the local host name.

Portability

A GriefEdit extension.

See Also

inq_username, getenv

inq_idle_default

int inq_idle_default()

Retrieve idle interval.

Description

The inq_idle_default() primitives retrieves the current keyboard idle interval, see set_idle_default.

Parameters

none

Returns

The inq_idle_default() primitives returns the current value of the interval timer.

Portability

n/a

See Also

set_idle_default

inq_idle_time

int inq_idle_time()

Retrieve keyboard idle time.

Description

The inq_idle_time() primitives retrieves the number of seconds since the user last pressed a key, representing the time keyboard input has been idle.

Parameters

none

Returns

The inq_idle_time() primitive returns the idle timer in seconds.

Portability

n/a

See Also

inq_idle_default, set_idle_default

inq_profile

string inq_profile()

Retrieve profile directory.

Description

The inq_profile() primitive retrieves the directory within which user specific profile information can be stored, examples include the restore state and personal dictionary.

This directory shall be system specific.

  • On Unix style systems, the profile is normally a sub-directory within the home directory of the current user is specified by the $HOME environment variable; this is also represented by the ~ directory.
~/.grief
  • On Windows systems, the profile is normally a sub-directory within the directory that serves as a common repository for application-specific data.  A typical path is
C:\Documents and Settings\<user>\Application Data\.grief.

Parameters

none

Returns

The inq_profile() primitive returns a string containing system dependent profile directory.

Portability

A GriefEdit extension.

See Also

inq_environment

inq_username

string inq_username()

Retrieve the user name.

Description

The inq_username() primitive retrieves the current user name.

Parameters

none

Returns

The inq_username() primitive returns a string containing the current user name.

Portability

A GriefEdit extension.

See Also

inq_hostname, getenv

putenv

void putenv(string name,
 [string value])

Set an environment variable.

Description

The putenv() primitive shall use the string arguments to set the value of an environment variable.

The arguments must construct a string of the form

"name=value"

This construction may be stated by one or two means.  Firstly by the explicit string arguments name and value, or alternatively a single argument name already correctly formed containing both components separated by an embedded = within the string.

Parameters

nameString containing the name of the environment variable and if value is omitted should also contain the associated value separated by an equals =.
valueOptional value to be assigned.

Returns

Upon successful completion, putenv shall return one on success, otherwise zero and set errno to indicate the error.

Portability

A GriefEdit extension.

See Also

getenv

set_backup

int set_backup(int mode,
 [int bufnum])

Set backup creation mode.

Description

The set_backup() primitive either toggles, set or retrieves the current backup flag of the associated object.  If bufnum is specified, then the stated buffer is effected, otherwise upon being omitted the global (default) backup mode shall be effected.

The backup flag is tested each time a buffer is written to its underlying storage (See: write_buffer).  The flag maybe one of two states, either off or on; when on, then a backup files shall be created.

If mode is not specified, then the value of the associated backup flag is toggled from on to off or off to no.  If given as zero backups shall be disabled, with a positive non-zero value enabling backups.

The set_backup() primitive may also be used to inquire the value of the associated backup flag.  If the specified mode is -1 then the current flag value of the associated object shall be returned without any other effects.

When invoked from the command, one of the following messages shall be echoed

   "Backups will be created".
or "Backups will not be created."
   "Backups will be created for the buffer".
or "Backups will not be created for the buffer."

Returns

The set_backup() primitive returns the previous value of the backup flag.

Portability

n/a

See Also

inq_backup, set_backup_option, inq_backup_option

set_backup_option

int set_backup_option(int what,
 [int bufnum],
 parameter)

Set backup options.

Description

The set_backup_option() primitive sets the value of the backup option what for the associated object. backup mode.  If bufnum is specified, then the value of the stated buffer is modified, otherwise upon being omitted the global (default) backup mode shall be modified.

parameter shall be what specific, with the following options available;

  • BK_MODE - Backup creation mode, see set_backup and inq_backup.  A zero integer parameter shall disable backups, with a non-zero value enabling backups.
  • BK_AUTOSAVE - Buffer auto-save flag.  A zero integer parameter shall disable auto-backups, with a non-zero value enabling auto-backups.
  • BK_DIR - Backup directory.  parameter should a string containing the backup directory path.
  • BK_DIRMODE - Directory creation mode.  parameter should be a integer value specifying the file creation umask.
  • BK_VERSIONS - Number of versions to be maintained.  parameter should be an integer value specifying the number of backup versions to be kept in the range [1 ..  99]; values outside shall set the versions to the lower/upper bounds.
  • BK_PREFIX - Backup filename prefix.  parameter should be a string containing the prefix, an empty string shall clear the current suffix.
  • BK_SUFFIX - Backup filename suffix/extension.  parameter should be a string containing the suffix, an empty string shall clear the current prefix.
  • BK_ONESUFFIX - Whether only a single suffix to used replacing any existing, otherwise append the suffix shall be appended.  parameter should be integer, with a non-zero enabling or zero disabling one-suffix filtering on backup filenames.
  • BK_ASK - File-size watermark at which point backups shall be prompted before created a backup image.  parameter should be a positive integer value being the watermark file-size in bytes, with a value of zero disabling any prompts.
  • BK_DONT - Filesize watermark at which point backups shall not be created regardless of the current backup mode.  parameter should be a positive integer value being the watermark filesize in bytes, with a value of zero disabling any affected.

Returns

The set_backup_option() on success returns zero, otherwise -1 on error.

Portability

A GriefEdit extension.

See Also

inq_backup_option, set_backup, inq_backup

set_char_timeout

void set_char_timeout([int timeout])

Set the escape delay.

Description

The set_char_timeout() primitive sets the length of time to wait before timing out and treating the ESC keystroke as the ESC character rather than combining it with other characters in the buffer to create a key sequence.

The most common instance where you may wish to change this value is to work with slow hosts, e.g., running on a network.  If the host cannot read characters rapidly enough, it will have the same effect as if the terminal did not send characters rapidly enough.  The library will still see a timeout.

The escape-delay value defaults to 750 milliseconds, but this shall be overridden by the ESCDELAY environment variable or the --escdelay command line option.

The ESCDELAY environment is defined specifies the default timeout interval, which is generally measured in millisecond.  If ESCDELAY is 0, the system immediately composes the ESCAPE response without waiting for more information from the buffer.  The user may choose any value between 0 and 9999, inclusive.

Note:

The ESCDELAY value is generally measured in milliseconds under most unix environments, but under AIX this value is measured in fifths of a milliseconds (200 microseconds) to be compatible with libcursor implementations; the default value is 500, or 0.1 second

Parameters

timeoutOptional character timeout is milliseconds, otherwise the current ESCDELAY shall be reapplied.

Returns

The set_char_timeout() primitive returns the previous character timeout.

Portability

n/a

See Also

inq_char_timeout

set_idle_default

int set_idle_default(int internal =  0)

Set idle interval.

Description

The set_idle_default() primitives set the keyboard idle interval as a measure of seconds betwen the last keystroke and when the REG_IDLE event is generated, see register_macro for details.

Parameters

intervalInteger idle interval in seconds, if omitted the system default shall be utilised.

Returns

The set_idle_default() primitives returns the previous value of the interval timer.

Portability

n/a

See Also

inq_idle_default

set_term_characters

int set_term_characters(int value0,
 ....)

Set terminal special characters.

Description

The set_term_characters() primitive is one of a set of functions which value add to the console interface specification.  Under Unix™ console attributes are derived from the system termcap or terminfo databases or similar interfaces under non-console and non-unix systems.

The set_term_characters() primitive configures the set of characters which are utilised by the tty console driver to represent window borders.

Each of the character parameters listed below may be either an integer or string expression representing the character value.  An integer value (including character constants) are treated as a single character whilst running within graphics-mode, whereas a string shall be interpreted as an escape sequence.  Values can be omitted by supplying a NULL parameter against the associated character index.

This function should generally be invoked prior to the display being enabled (See: display_windows), otherwise a redraw is required.

Index
Name
Description
0
top_left
Top left of a window.
1
top_right
Right right of a window.
2
bottom_left
Bottom left of a window.
3
bottom_right
Bottom right of a window.
4
vertical
Vertical window sides.
5
horizontal
Horizontal window sides.
5
top_join
Top intersection of window corners.
6
bottom_join
Bottom intersection of window corners.
7
cross
Intersection of window corners.
8
left_join
Left Window intersection.
9
right_join
Right window intersection.
10
scroll
Scroll bar arena.
11
thumb
Scroll bar thumb.

Parameters

...Integer character value or string escape sequence, one for each character within the set.

Example

The following configures a terminal to use simple non-graphical characters to represent window borders.

set_term_characters(
'+', // 0. Top left of window.
'+', // 1. Top right of window.
'+', // 2. Bottom left of window.
'+', // 3. Bottom right of window.
'|', // 4. Vertical bar for window sides.
'-', // 5. Top and bottom horizontal bar for window.
'+', // 6. Top join.
'+', // 7. Bottom join.
'+', // 8. Window 4-way intersection.
'+', // 9. Left hand join.
'+', // 10. Right hand join.
'*' // 11. Thumb wheel.
);

Note:

For further examples refer to the tty macros, which setup the terminal interface for many well known environments.

Returns

nothing

Portability

n/a

See Also

set_term_features, set_term_keyboard

set_term_feature

int set_term_feature(  int|string ident,
 [string|int value])

Set a terminal attribute.

Description

The set_term_feature() primitive is one of a set of functions which value add to the console interface specification.  Under Unix™ console attributes are derived from the system termcap or terminfo databases or similar interfaces under non-console and non-unix systems.

The set_term_feature() primitive allows certain attributes about the current display to be modified; for example features which are not adequately handled by termcap or terminfo.  The attribute identified by ident shall be set to value.

Parameters

identEither the integer identifier or a string containing the name of the terminal attribute to be modified.
valueValue to be applied against the attribute, if omitted or NULL the current value is cleared.  The type of the value is specific to the attribute being modified, either in string or integer form.

Types

Each of the attributes are defined using one of four data types.

EscapeTerminal specific escape sequence being a series of characters that shall be written to the attached terminal.
Controls supporting parameters should use printf style %d as the place holders for parameters; allowing terminfo/termcap independent macro development.
Most of the sequence attributes are no longer required since the current generation of curses/ncurses terminfo or terminfo databases are complete.  Supplied values shall only be utilised in the event these are missing from the current terminal description.
BooleanBoolean flag, which can be stated as either a numeric zero/non-zero value or a string value yes/no.
IntegerNumeric value, either stated as an integer value or string containing a decimal value.
StringString value.

Attributes

The following terminal attributes are exposed

Constant
Name
Type
Description
TF_PRINT_SPACE
repeat_space
Escape
Control sequence to print a space n times.
TF_PRINT_BITEIGHT
print_character
Escape
Control sequence to print eight bit characters.
TF_INSERT_CURSOR
insert_cursor
Escape
Control sequence which modifies the cursor looks, utilised when GriefEdit has insert-mode enabled.
TF_OVERWRITE_CURSOR
overwrite_cursor
Escape
Control sequence which modifies the cursor looks, utilised when GriefEdit has overwrite-mode enabled.
TF_VINSERT_CURSOR
virt_insert_cursor
Escape
Control sequence which modifies the cursor looks, utilised when GriefEdit has insert-mode enabled and is positioned over a virtual-space.
TF_VOVERWRITE_CURSOR
virt_overwrite_cursor
Escape
Control sequence which modifies the cursor looks, utilised when GriefEdit has overwrite-mode enabled an is positioned over a virtual-space.
TF_PRINT_ESCAPE
print_escape
Escape
Control sequence which prints an ESC character graphically.
TF_REPEAT_LAST
repeat_last
Escape
Control sequence for repeating the previous character printed n times.
TF_0M_RESETS_COLOR
0m_resets_color
Boolean
When non-zero, then whenever an ESC[0m is printed, it is assumed that the background and foreground colours are reset (defunct).
TF_COLOR
color
Boolean
When non-zero, the terminal is assumed to support color.
TF_CURSOR_RIGHT
parm_cursor_right
Escape
Control sequence for move the cursor n characters within on the same line.
TF_CLEAR_IS_BLACK
clear_is_black
Boolean
When true states that area erase commands set the background of the erased line to black, otherwise the current background is assumed.
TF_DISABLE_INSDEL
noinsdel
Boolean
When true disables the use of window scrolling when attempting to optimise output; on several displays its faster to rewrite the window.
TF_GRAPHIC_MODE
graphics_mode
Escape
Control sequence to send when sending graphics (line drawing) characters.
TF_TEXT_MODE
text_mode
Escape
Control sequence to send when exiting graphics mode and going back to normal character set.
TF_RESET
reset
Escape
Control sequence to be executed during terminal initialisation operations.
TF_INIT
init
Escape
Control sequence to be executed during terminal reset operations.
TF_COLORSETFGBG
colorset_fgbg
Escape
Control sequence when executed sets both the foreground and backgrounds colours.
TF_COLORSET_FG
colorset_fg
Escape
Control sequence when executed sets the foreground colour.
TF_COLORSET_BG
colorset_bg
Escape
Control sequence when executed sets the background colour.
TF_COLORDEPTH
color_depth
Integer
Colour depth.
TF_DEFAULT_FG
default_fg_color
Integer
Terminals default foreground color.
TF_DEFAULT_BG
default_bg_color
Integer
Terminals default background color.
TF_SCHEMEDARK
scheme_dark
Boolean
When true the dark colour scheme variant shall be select over the light; if available.
TF_COLORMAP
color_map
String
Xterm colour map specification; a comma separated list of colours defining the colour palette.
TF_COLORPALETTE
color_palette
String
User defined palette.
TF_EIGHT_BIT
eight_bit
Boolean
When true the console supports the display of eight bit characters.
TF_MOUSE
mouse
String
Mouse device.
TF_MOUSECLKMS
mouse_clickms
Integer
Mouse click time in milliseconds.
TF_WINDOW_SETSIZE
winsetsize
Escape
Control sequence to set the window size to x by y.
TF_WINDOW_SETPOS
winsetpost
Escape
Control sequence to set the window position at x by y.
TF_CODEPAGE
codepage
Integer
Character code page.
TF_DISABLE_SCROLL
scroll_disable
Boolean
When true disables use of scroll region commands.
TF_SCROLL_MAX
scroll_max
Integer
Upper size of window to be scrolled permitting use of scroll region commands.
TF_NOALTSCREEN
noaltscreen
Boolean
When true denotes no alternative screen selection is available.
TF_LAZYUPDATE
lazy_update
Integer
When set to a positive value, indicates lazy screen updates are enabled.  Screen updates are delayed until the keyboard becomes idle upto the stated number of lines.
TF_ATTRIBUTES
attributes
Integer
Terminal attribute bitmap; see the table below.
TF_NAME
name
String
Name of the terminal.
TF_TTY_FAST
tty_fast
Integer
When true disables use of pad characters.
TF_TTY_GRAPHICSBOX
tty_graphicsbox
Integer
When true enables use of graphic box characters.
TF_KBPROTOCOL
kbprotocol
String
Active kb-protocol.
TF_SCREEN_ROWS
screen_rows
Integer
Number of screen rows.
TF_SCREEN_COLS
screen_cols
Integer
Number of screen columns.
TF_LINENO_COLUMNS
lineno_columns
Integer
Terminal specific number of columns allocated for the display of buffer number lines.
TF_WINDOW_MINROWS
window_minrows
Integer
Minimum vertical size of a window.
TF_WINDOW_MINCOLS
window_mincols
Integer
Minimum horizontal size of a window.
TF_XTERM_COMPAT
xterm_compat
Integer
When true terminal to treated like an xterm.
TF_XTERM_CURSOR
xterm_cursor
Integer
When true terminal supports xterm cursor control commands.
TF_XTERM_TITLE
xterm_title
Integer
Control sequence when executed set the console title.
TF_XTERM_PALETTE
xterm_palette
Integer
Xterm palette selector.
TF_VT_DATYPE
vt_datype
Integer
Terminal type; xterm device attribute, known values are.
0xterm.
77mintty.
83screen.
82rxvt.
85rxvt unicode.
TF_VT_DAVERSION
vt_daversion
Integer
Terminal version.
TF_VT_DAOPTIONS
vt_daoptions
Integer
Terminal options.
TF_ENCODING
encoding
String
Terminal character encoding.
TF_UNICODE_VERSION
unicode_version
String
UNICODE interface version, for example “6.0.1”.

TF_ATTRIBUTE

The reported TF_ATTRIBUTE attribute represents special terminal features mined during terminal initialisation.  The flag argument can contain none or more of the following symbols bitwise OR’ed together.

Constant
Description
TF_AGRAPHICCHARACTERS
Graphic characters (ACS defined)
TF_AFUNCTIONKEYS
F1-F10 function keys.
TF_ACYGWIN
Cygwin native console.
TF_AUTF8ENCODING
UTF8 character encoding, Unicode implied.
TF_AUNICODEENCODING
Unicode character encoding.
TF_AMETAKEY
Meta keys.
TF_AXTERMKEYS
XTerm modifyOtherKeys available.
TF_AKITTYKEYS
Kitty extended keycodes available.

Note:

Many of the exposed attributes are specific to the underlying terminal, a well known is the Xterm Control Sequences available on http://invisible-island.net.

Returns

The set_term_feature() primitive returns 0 on success, otherwise 1 on error.

Portability

A GriefEdit extension.

See Also

set_term_features, set_term_characters, set_term_keyboard

set_term_features

int set_term_features(list features)

Define terminal attributes.

Description

The set_term_features() primitive is one of a set of functions which value add to the console interface specification.  Under Unix™ console attributes are derived from the system termcap or terminfo databases or similar interfaces under non-console and non-unix systems.

Similar to the set_term_feature, set_term_features allows attributes about the current display to be modifed; for example features which are not adequately handled by termcap or terminfo.

set_term_features utilises a list interface with elements within the list implied by the TF_XXXX enumeration.  This permits bulk attribute initialisation at the expense of visibility.  See set_term_feature for further details on the exposed attributes.

Parameters

listTerminal attributes one or each attribute in the order implied by the TF_XXXX enumeration.
Each parameter may be either an integer or string expression representing the character value.  An integer value (including character constants) are treated as a single character whilst within graphics-mode, whereas a string shall be interpreted as an escape sequence.  Values can be omitted by supplying a NULL parameter against the associated character index.

Returns

nothing

Example

set_term_features(
NULL, // TF_PRINT_SPACE
NULL, // TF_PRINT_BITEIGHT
NULL, // TF_INSERT_CURSOR
NULL, // TF_OVERWRITE_CURSOR
NULL, // TF_VINSERT_CURSOR
NULL, // TF_VOVERWRITE_CURSOR
NULL, // TF_PRINT_ESCAPE
NULL, // TF_REPEAT_LAST
FALSE, // TF_0M_RESETS_COLOR
FALSE, // TF_COLOR
"\x1B[%dC", // TF_CURSOR_RIGHT
TRUE, // TF_CLEAR_IS_BLACK
FALSE, // TF_DISABLE_INSDEL
"\x1B(0", // TF_GRAPHIC_MODE
"\x1B(B" // TF_TEXT_MODE
);

Portability

Many of the return values are only meaningful on systems that use a tty based console interface.

See Also

set_term_feature, set_term_characters, set_term_keyboard

set_term_keyboard

int set_term_keyboard(list kbd)

Define terminal keyboard definitions.

Description

The set_term_keyboard() primitive is one of a set of functions which value add to the console interface specification.  Under Unix™ console attributes are derived from the system termcap or terminfo databases or similar interfaces under non-unix systems.

The set_term_keyboard function manages the keyboard scan-code (terminal escape sequence) to key-code mapping table.  For each key definition set_term_keyboard expects a pair of arguments, the first being Griefs internal key-code (See: key_to_int) with the second stating the associated escape sequence.

The mapped escape sequence shall be treated as unique; in what only the last instance shall be retained.  Whereas key-codes can be associated with multiple escape sequences.  For example, a generic Xterm mapping could support alternative function key reports.

The second argument may takes one of two forms.  The first being a single string containing the escape sequence, the second being a key-list permitting a range of keys to be bound.

Example simple key associates including non-unique key codes.

set_term_keyboard(
:

KEY_PAGEUP, "\x1b[5~", // vt220 mode
KEY_PAGEDOWN, "\x1b[6~",
KEY_INS, "\x1b[2~",
KEY_DEL, "\x7f",

KEY_PAGEUP, "\x1b[5z", // sunFunctionKeys mode
KEY_PAGEDOWN, "\x1b[6z",
KEY_INS, "\x1b[2z",

:
);

Character Ranges

The key-lists are simply a list of strings describing each consecutive key within a set or range of keys.  A constant set of keys can be simply quoted using the quote_list function, alternatively the list can be constructed with the other list primitives.

The following character definitions are generally defined using a consecutive set of keys.

  • F1_F12
  • SHIFT_F1_F12
  • CTRL_A_Z
  • CTRL_F1_F12
  • CTRLSHIFT_F1_F12
  • ALT_F1_F12
  • ALT_A_Z
  • ALT_0_9
  • KEYPAD_0_9
  • CTRL_KEYPAD_0_9
  • SHIFT_KEYPAD_0_9
  • ALT_KEYPAD_0_9

Example of a consecutive definition against a constant set of sequences.

set_term_keyboard(
F1_F12, quote_list(
"\x1bOP", "\x1bOQ", "\x1bOR", "\x1bOS",
"\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~",
"\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~" )
);

Ambiguous

Due to the complex nature of terminal escape sequences, many key definitions result in ambiguous mappings; for example two or more mappings starting with the same sequence of characters.  The mapping of ambiguous sequences to their associated key-code utilise a scan delay mechanism.  When an ambiguous sequence is detected the driver waits several milliseconds before selecting the longest matching sequence, see set_char_timeout for details.

Note:

Many of the reported escapes are specific to the underlying terminal, a well known is the Xterm Control Sequences available on http ://invisible-island.net.

Parameters

none

Returns

nothing

Example

The following is an example from the Linux terminal definition.

set_term_keyboard(

:

F1_F12, quote_list(
"\x1bOP", "\x1bOQ", "\x1bOR", "\x1bOS",
"\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~",
"\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~" ),

SHIFT_F1_F12, quote_list(
NULL, NULL, "\x1b[25~", "\x1b[26~",
"\x1b[28~", "\x1b[29~", "\x1b[31~", "\x1b[32~",
"\x1b[33~", "\x1b[34~", "\x1b[23;2~", "\x1b[24;2~" ),

CTRL_F1_F12, quote_list(
"\x1bO5P", "\x1bO5Q", "\x1bO5R", "\x1bO5S",
"\x1b[15;5~", "\x1b[17;5~", "\x1b[18;5~", "\x1b[19;5~",
"\x1b[20;5~", "\x1b[21;5~", "\x1b[23;5~", "\x1b[24;5~" ),

:
);

Note:

For further examples refer to the tty macros, which setup the terminal interface for many well known environments.

Portability

n/a

See Also

set_term_characters, set_term_features

uname

int uname([string &sysname],
[string &nodename],
 [string &version],
[string &release],
 [string &machine])

Retrieve system information.

Description

The uname() primitive retrieves the strings corresponding to the result of a uname system call.  On non-POSIX systems, these strings maybe blank unless there is an equilvent value available.

Parameters

sysnameSystem name.
nodenameNetwork node name.
versionKernel version
releaseKernel release.
machineMachine type.

Returns

The uname() primitive returns on 0 otherwise, -1 on error.

Portability

A GriefEdit extension.

See Also

version

$Id: $

To send feedback on this topic email: grie.nosp@m.fedit@gmai.nosp@m.l.com

Copyright © Adam Young All Rights Reserved.

int cd([string dir])
Change directory.
int create_char_map([int mapid|string name],
 [int start = 0],
[list chars],
 [list flags],
[string name])
Create a display character-map.
list get_term_characters([top_left],
[top_right],
 [bottom_left],
[bottom_right],
[vertical],
[horizontal],
 [top_join],
[bottom_join],
[cross],
 [left_join],
[right_join],
[scrol],
[thumb])
Retrieve terminal special characters.
int get_term_feature( string | int ident,
declare value)
Get value of a terminal feature.
list get_term_features(...)
Retrieve terminate features.
list get_term_keyboard()
Retrieve the terminal keyboard definitions.
string getenv(string name)
Retrieve an environment variable.
int geteuid()
Retrieve the effective user identifier.
int getpid()
Retrieve the process identifier.
int getuid()
Retrieve the user identifier.
int getwd(int ignored,
string dir)
Get current working directory.
int inq_backup([int bufnum])
Get the backup creation mode.
declare inq_backup_option(int what,
 [int bufnum])
Get backup options.
int inq_brief_level()
Retrieve the editor nesting level.
int inq_char_timeout()
Get the escape delay.
string inq_environment(string name)
Retrieve an environment variable.
int|list inq_feature([int|string feature],
[string value])
Retrieve an editor feature.
string inq_hostname()
Retrieve the local host name.
int inq_idle_default()
Retrieve idle interval.
int inq_idle_time()
Retrieve keyboard idle time.
string inq_profile()
Retrieve profile directory.
string inq_username()
Retrieve the user name.
void putenv(string name,
 [string value])
Set an environment variable.
int set_backup(int mode,
 [int bufnum])
Set backup creation mode.
int set_backup_option(int what,
 [int bufnum],
 parameter)
Set backup options.
void set_char_timeout([int timeout])
Set the escape delay.
int set_idle_default(int internal =  0)
Set idle interval.
int set_term_characters(int value0,
 ....)
Set terminal special characters.
int set_term_feature(  int|string ident,
 [string|int value])
Set a terminal attribute.
int set_term_features(list features)
Define terminal attributes.
int set_term_keyboard(list kbd)
Define terminal keyboard definitions.
int uname([string &sysname],
[string &nodename],
 [string &version],
[string &release],
 [string &machine])
Retrieve system information.
int chdir(string path)
Change directory.
extern int errno;
Last system errno number.
int mkdir(string pathname,  
int mode =  0755)
Create a directory.
int rmdir(string path)
Remove directory.
int inq_char_map([int winnum],
[string &name])
Retrieve the character-map.
int inq_kbd_char()
Peek at the keyboard.
void read_char([int timeout = 0],
[int mode = 0])
Read next key from the keyboard.
int set_feature([int|string feature],
[string value])
Config an editor feature.
int inq_display_mode([string flagname],
[string ~flags])
Inquire display control flags.
int write_buffer(  [string filename],
[int flags],
[string encoding])
Write to buffer content.
int umask(int cmask =  NULL)
Set and get the file mode creation mask.
int register_macro(int type,
 string macro,
 [int local = FALSE])
Register a callback procedure.
int display_windows([int mode])
Control window display.
void redraw([int winch])
Redraw screen.
int key_to_int(string key,
int raw)
Convert key name to a code.
list quote_list(...)
Build an unevaluated list.
int version([int major | string machtype],
 [int min],
[int edit],
[int release],
[string machtype],
 [string compile],
[int cmversion],
 [string features],
[string build])
Version information.