CNDP  22.08.0
cne_tty.h File Reference
#include <termios.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <cne_atomic.h>
#include <cne_common.h>
#include <cne_system.h>

Go to the source code of this file.

Data Structures

struct  cne_tty_t
 

Functions

CNDP_API int tty_setup (int fd_in, int fd_out)
 
CNDP_API void tty_destroy (void)
 
CNDP_API void tty_enable_color (void)
 
CNDP_API void tty_disable_color (void)
 
CNDP_API int tty_is_color_on (void)
 
CNDP_API int tty_is_inited (void)
 
CNDP_API void tty_set_wchanged (void)
 
CNDP_API void tty_clear_wchanged (void)
 
CNDP_API int tty_did_wchange (void)
 
CNDP_API tty_wsize_t * tty_window_size (void)
 
CNDP_API int tty_num_rows (void)
 
CNDP_API int tty_num_columns (void)
 
CNDP_API int tty_poll (char *buf, int len, int timeout)
 
CNDP_API int tty_write (const char *buf, int len)
 
CNDP_API int tty_dwrite (int fd, const char *buf, int len)
 
CNDP_API int tty_fwrite (FILE *f, const char *buf, int len)
 
CNDP_API int tty_read (char *buf, int len)
 
CNDP_API int tty_dread (int fd, char *buf, int len)
 
CNDP_API int tty_fread (FILE *f, char *buf, int len)
 
CNDP_API int tty_printf (const char *fmt,...)
 
CNDP_API int tty_fprintf (FILE *f, const char *fmt,...)
 
CNDP_API int tty_vprintf (const char *fmt, va_list ap)
 
CNDP_API int tty_vfprintf (FILE *f, const char *fmt, va_list ap)
 

Detailed Description

CNE TTY input and output support routines.

Setup the TTY for I/O unless it is a socket instead. These routines are used by cli and all output routines for stdin/stdout as well as socket I/O handling.

Definition in file cne_tty.h.

Function Documentation

◆ tty_setup()

CNDP_API int tty_setup ( int  fd_in,
int  fd_out 
)

setup a tty or socket for user input. Default is stdin/stdout

Parameters
fd_inSet the tty input file descriptor, if -1 use STDIN_FILENO
fd_outSet the tty output file descriptor, if -i use STDOUT_FILENO
Returns
-1 on error or 0 on success
Examples
examples/cli/main.c.

◆ tty_destroy()

CNDP_API void tty_destroy ( void  )

Destroy or cleanup the tty interface and handlers

Examples
examples/cli/main.c.

◆ tty_enable_color()

CNDP_API void tty_enable_color ( void  )

Enable color printing of messages.

◆ tty_disable_color()

CNDP_API void tty_disable_color ( void  )

Disable color printing of messages.

Examples
examples/cndpfwd/parse-args.c, and examples/cnet-graph/parse-args.c.

◆ tty_is_color_on()

CNDP_API int tty_is_color_on ( void  )

Test to see if color output is enabled or disabled.

Returns
false if color has been disabled or true if enabled.

◆ tty_is_inited()

CNDP_API int tty_is_inited ( void  )

Has the TTY been inited?

Returns
true if the tty has been inited or false if not.

◆ tty_set_wchanged()

CNDP_API void tty_set_wchanged ( void  )

Set the window size changed flag.

◆ tty_clear_wchanged()

CNDP_API void tty_clear_wchanged ( void  )

Clear the window size changed flag.

◆ tty_did_wchange()

CNDP_API int tty_did_wchange ( void  )

Test if the window size has changed.

Flag is cleared when read.

Returns
false if the window has not changed or true if it has changed.

◆ tty_window_size()

CNDP_API tty_wsize_t* tty_window_size ( void  )

Get the current window size

Returns
Pointer to structure or NULL if error.

◆ tty_num_rows()

CNDP_API int tty_num_rows ( void  )

Return the number of rows in the screen

◆ tty_num_columns()

CNDP_API int tty_num_columns ( void  )

Return the number of columns in the screen

◆ tty_poll()

CNDP_API int tty_poll ( char *  buf,
int  len,
int  timeout 
)

Poll the TTY input fd and return number of bytes read

Parameters
bufBuffer to put the input characters
lenThe length of the buf array
timeoutThe number of milli-seconds to wait or -1 for no timeout
Returns
0 - on timeout -1 - on Error Number of characters read from input.

◆ tty_write()

CNDP_API int tty_write ( const char *  buf,
int  len 
)

Write the data from buf to the tty file descriptor.

Parameters
bufPointer to data buffer to output the file descriptor.
lenNumber of bytes to write to file descriptor.
Returns
The number of bytes written to the tty file descriptor

◆ tty_dwrite()

CNDP_API int tty_dwrite ( int  fd,
const char *  buf,
int  len 
)

Write the data from buf to the tty file descriptor number, bypass this_tty->fd_out

Parameters
fdThe file descriptor index value
bufPointer to data buffer to output the file descriptor.
lenNumber of bytes to write to file descriptor.
Returns
The number of bytes written to the tty file descriptor

◆ tty_fwrite()

CNDP_API int tty_fwrite ( FILE *  f,
const char *  buf,
int  len 
)

Write the data from buf to the tty file descriptor, bypass this_tty->fd_out

Parameters
fThe file descriptor pointer
bufPointer to data buffer to output the file descriptor.
lenNumber of bytes to write to file descriptor.
Returns
The number of bytes written to the tty file descriptor

◆ tty_read()

CNDP_API int tty_read ( char *  buf,
int  len 
)

Read the data from the tty file descriptor into the buffer.

Parameters
bufPointer to data buffer to place the input from file descriptor.
lenNumber of bytes to read from file descriptor.
Returns
The number of bytes read from the tty file descriptor

◆ tty_dread()

CNDP_API int tty_dread ( int  fd,
char *  buf,
int  len 
)

Read the data from the tty file descriptor into the buffer.

Parameters
fdThe file descriptor index value
bufPointer to data buffer to place the input from file descriptor.
lenNumber of bytes to read from file descriptor.
Returns
The number of bytes read from the tty file descriptor

◆ tty_fread()

CNDP_API int tty_fread ( FILE *  f,
char *  buf,
int  len 
)

Read the data from the tty file descriptor into the buffer.

Parameters
fThe file descriptor pointer
bufPointer to data buffer to place the input from file descriptor.
lenNumber of bytes to read from file descriptor.
Returns
The number of bytes read from the tty file descriptor

◆ tty_printf()

CNDP_API int tty_printf ( const char *  fmt,
  ... 
)

A printf like routine to output to tty file descriptor.

Parameters
fmtThe formatting string for a printf like API

◆ tty_fprintf()

CNDP_API int tty_fprintf ( FILE *  f,
const char *  fmt,
  ... 
)

A fprintf like routine to output to tty file descriptor.

Parameters
fThe file descriptor pointer
fmtThe formatting string for a printf like API

◆ tty_vprintf()

CNDP_API int tty_vprintf ( const char *  fmt,
va_list  ap 
)

A vprintf like routine to output to tty file descriptor

Parameters
fmtThe cne_printf() like format string.
apThe va_list pointer
Returns
The number of bytes written to the file descriptor.

◆ tty_vfprintf()

CNDP_API int tty_vfprintf ( FILE *  f,
const char *  fmt,
va_list  ap 
)

A vfprintf like routine to output to tty file descriptor

Parameters
fThe file descriptor pointer
fmtThe cne_printf() like format string.
apThe va_list pointer
Returns
The number of bytes written to the file descriptor.