DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Enumerations | Functions | Variables
linenoise.c File Reference
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include "linenoise.h"
#include "utf8.h"

Classes

struct  current
struct  ctx

Macros

#define USE_TERMIOS
#define HAVE_UNISTD_H
#define LINENOISE_DEFAULT_HISTORY_MAX_LEN   100
#define LINENOISE_MAX_LINE   4096
#define ctrl(C)   ((C) - '@')
#define IGNORE_RC(EXPR)   if (EXPR) {}

Enumerations

enum  {
  SPECIAL_NONE, SPECIAL_UP = -20, SPECIAL_DOWN = -21, SPECIAL_LEFT = -22,
  SPECIAL_RIGHT = -23, SPECIAL_DELETE = -24, SPECIAL_HOME = -25, SPECIAL_END = -26
}

Functions

static int fd_read (struct current *current)
 Reads a complete utf-8 character and returns the unicode value, or -1 on error.
static int getWindowSize (struct current *current)
void linenoiseHistoryFree (void)
static void linenoiseAtExit (void)
static int isUnsupportedTerm (void)
static int enableRawMode (struct current *current)
static void disableRawMode (struct current *current)
static void fd_printf (int fd, const char *format,...)
static void clearScreen (struct current *current)
static void cursorToLeft (struct current *current)
static int outputChars (struct current *current, const char *buf, int len)
static void outputControlChar (struct current *current, char ch)
static void eraseEol (struct current *current)
static void setCursorPos (struct current *current, int x)
static int fd_read_char (int fd, int timeout)
 Reads a char from 'fd', waiting at most 'timeout' milliseconds.
static int check_special (int fd)
 If escape (27) was received, reads subsequent chars to determine if this is a known special key.
static int utf8_getchars (char *buf, int c)
static int get_char (struct current *current, int pos)
 Returns the unicode character at the given offset, or -1 if none.
static void refreshLine (const char *prompt, struct current *current)
static void set_current (struct current *current, const char *str)
static int has_room (struct current *current, int bytes)
static int remove_char (struct current *current, int pos)
 Removes the char at 'pos'.
static int insert_char (struct current *current, int pos, int ch)
 Insert 'ch' at position 'pos'.
static int remove_chars (struct current *current, int pos, int n)
 Returns 0 if no chars were removed or non-zero otherwise.
static void beep ()
static void freeCompletions (linenoiseCompletions *lc)
static int completeLine (struct current *current, int c)
void linenoiseSetCompletionCallback (linenoiseCompletionCallback *fn)
void linenoiseAddCompletion (linenoiseCompletions *lc, const char *str)
static int linenoisePrompt (struct current *current)
static void current_nonblock (struct current *current, int nonblock)
char * linenoise_nb (const char *prompt)
void linenoise_nb_clean (void)
int linenoise_nb_eol (void)
char * linenoise (const char *prompt)
int linenoiseHistoryAdd (const char *line)
int linenoiseHistorySetMaxLen (int len)
int linenoiseHistorySave (const char *filename)
int linenoiseHistoryLoad (const char *filename)
char ** linenoiseHistory (int *len)

Variables

static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN
static int history_len = 0
static char ** history = NULL
static int rawmode = 0
static struct termios orig_termios
static int atexit_registered = 0
static const char * unsupported_term [] = {"dumb","cons25",NULL}
static
linenoiseCompletionCallback
completionCallback = NULL
static struct ctx nb_ctx

Macro Definition Documentation

#define ctrl (   C)    ((C) - '@')
#define HAVE_UNISTD_H
#define IGNORE_RC (   EXPR)    if (EXPR) {}
#define LINENOISE_DEFAULT_HISTORY_MAX_LEN   100
#define LINENOISE_MAX_LINE   4096
#define USE_TERMIOS

Enumeration Type Documentation

anonymous enum
Enumerator:
SPECIAL_NONE 
SPECIAL_UP 
SPECIAL_DOWN 
SPECIAL_LEFT 
SPECIAL_RIGHT 
SPECIAL_DELETE 
SPECIAL_HOME 
SPECIAL_END 

Function Documentation

static void beep ( )
static
static int check_special ( int  fd)
static

If escape (27) was received, reads subsequent chars to determine if this is a known special key.

Returns SPECIAL_NONE if unrecognised, or -1 if EOF.

If no additional char is received within a short time, 27 is returned.

static void clearScreen ( struct current current)
static
static int completeLine ( struct current current,
int  c 
)
static
static void current_nonblock ( struct current current,
int  nonblock 
)
static
static void cursorToLeft ( struct current current)
static
static void disableRawMode ( struct current current)
static
static int enableRawMode ( struct current current)
static
static void eraseEol ( struct current current)
static
static void fd_printf ( int  fd,
const char *  format,
  ... 
)
static
static int fd_read ( struct current current)
static

Reads a complete utf-8 character and returns the unicode value, or -1 on error.

static int fd_read_char ( int  fd,
int  timeout 
)
static

Reads a char from 'fd', waiting at most 'timeout' milliseconds.

A timeout of -1 means to wait forever.

Returns -1 if no char is received within the time or an error occurs.

static void freeCompletions ( linenoiseCompletions lc)
static
static int get_char ( struct current current,
int  pos 
)
static

Returns the unicode character at the given offset, or -1 if none.

static int getWindowSize ( struct current current)
static
static int has_room ( struct current current,
int  bytes 
)
static
static int insert_char ( struct current current,
int  pos,
int  ch 
)
static

Insert 'ch' at position 'pos'.

Returns 1 if the line needs to be refreshed, 2 if not and 0 if nothing was inserted (no room)

static int isUnsupportedTerm ( void  )
static
char* linenoise ( const char *  prompt)
char* linenoise_nb ( const char *  prompt)
void linenoise_nb_clean ( void  )
int linenoise_nb_eol ( void  )
void linenoiseAddCompletion ( linenoiseCompletions lc,
const char *  str 
)
static void linenoiseAtExit ( void  )
static
char** linenoiseHistory ( int *  len)
int linenoiseHistoryAdd ( const char *  line)
void linenoiseHistoryFree ( void  )
int linenoiseHistoryLoad ( const char *  filename)
int linenoiseHistorySave ( const char *  filename)
int linenoiseHistorySetMaxLen ( int  len)
static int linenoisePrompt ( struct current current)
static
void linenoiseSetCompletionCallback ( linenoiseCompletionCallback fn)
static int outputChars ( struct current current,
const char *  buf,
int  len 
)
static
static void outputControlChar ( struct current current,
char  ch 
)
static
static void refreshLine ( const char *  prompt,
struct current current 
)
static
static int remove_char ( struct current current,
int  pos 
)
static

Removes the char at 'pos'.

Returns 1 if the line needs to be refreshed, 2 if not and 0 if nothing was removed

static int remove_chars ( struct current current,
int  pos,
int  n 
)
static

Returns 0 if no chars were removed or non-zero otherwise.

static void set_current ( struct current current,
const char *  str 
)
static
static void setCursorPos ( struct current current,
int  x 
)
static
static int utf8_getchars ( char *  buf,
int  c 
)
static

Variable Documentation

int atexit_registered = 0
static
linenoiseCompletionCallback* completionCallback = NULL
static
char** history = NULL
static
int history_len = 0
static
int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN
static
struct ctx nb_ctx
static
struct termios orig_termios
static
int rawmode = 0
static
const char* unsupported_term[] = {"dumb","cons25",NULL}
static