2011-12-27 03:18:46 +00:00
|
|
|
/** \file reader.h
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
Prototypes for functions for reading data from stdin and passing
|
|
|
|
to the parser. If stdin is a keyboard, it supplies a killring,
|
|
|
|
history, syntax highlighting, tab-completion and various other
|
|
|
|
features.
|
|
|
|
*/
|
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_READER_H
|
|
|
|
#define FISH_READER_H
|
|
|
|
|
2012-01-16 16:56:47 +00:00
|
|
|
#include <vector>
|
2005-10-04 15:11:39 +00:00
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
2007-04-25 18:30:02 +00:00
|
|
|
#include "io.h"
|
2012-02-11 01:54:21 +00:00
|
|
|
#include "common.h"
|
2012-02-24 20:13:35 +00:00
|
|
|
#include "complete.h"
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2012-01-23 05:40:08 +00:00
|
|
|
class parser_t;
|
2012-02-02 00:27:14 +00:00
|
|
|
class completion_t;
|
2012-02-06 00:42:24 +00:00
|
|
|
class history_t;
|
2012-01-23 05:40:08 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
2005-10-19 12:07:44 +00:00
|
|
|
Read commands from \c fd until encountering EOF
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2007-04-25 18:30:02 +00:00
|
|
|
int reader_read( int fd, io_data_t *io);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Tell the shell that it should exit after the currently running command finishes.
|
|
|
|
*/
|
2006-05-14 10:16:23 +00:00
|
|
|
void reader_exit( int do_exit, int force );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Check that the reader is in a sane state
|
|
|
|
*/
|
|
|
|
void reader_sanity_check();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the reader
|
|
|
|
*/
|
|
|
|
void reader_init();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destroy and free resources used by the reader
|
|
|
|
*/
|
|
|
|
void reader_destroy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the filename of the file currently read
|
|
|
|
*/
|
2012-02-02 23:05:08 +00:00
|
|
|
const wchar_t *reader_current_filename();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Push a new filename on the stack of read files
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
\param fn The fileanme to push
|
|
|
|
*/
|
2006-02-02 15:23:56 +00:00
|
|
|
void reader_push_current_filename( const wchar_t *fn );
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Pop the current filename from the stack of read files
|
|
|
|
*/
|
2012-02-02 23:05:08 +00:00
|
|
|
void reader_pop_current_filename();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Write the title to the titlebar. This function is called just
|
|
|
|
before a new application starts executing and just after it
|
|
|
|
finishes.
|
|
|
|
*/
|
|
|
|
void reader_write_title();
|
|
|
|
|
|
|
|
/**
|
2007-10-05 14:59:19 +00:00
|
|
|
Call this function to tell the reader that a repaint is needed, and
|
|
|
|
should be performed when possible.
|
|
|
|
*/
|
|
|
|
void reader_repaint_needed();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-03-25 10:00:38 +00:00
|
|
|
/** Call this function to tell the reader that some color has changed. */
|
|
|
|
void reader_react_to_color_change();
|
|
|
|
|
|
|
|
/* Repaint immediately if needed. */
|
|
|
|
void reader_repaint_if_needed();
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Run the specified command with the correct terminal modes, and
|
|
|
|
while taking care to perform job notification, set the title, etc.
|
|
|
|
*/
|
2006-06-21 14:03:44 +00:00
|
|
|
void reader_run_command( const wchar_t *buff );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the string of character currently entered into the command
|
|
|
|
buffer, or 0 if interactive mode is uninitialized.
|
|
|
|
*/
|
2012-02-06 09:45:16 +00:00
|
|
|
const wchar_t *reader_get_buffer();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-02-06 00:42:24 +00:00
|
|
|
/** Returns the current reader's history */
|
|
|
|
history_t *reader_get_history(void);
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Set the string of characters in the command buffer, as well as the cursor position.
|
|
|
|
|
|
|
|
\param b the new buffer value
|
|
|
|
\param p the cursor position. If \c p is less than zero, the cursor is placed on the last character.
|
|
|
|
*/
|
2012-02-22 19:07:34 +00:00
|
|
|
void reader_set_buffer( const wcstring &b, int p );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the current cursor position in the command line. If interactive
|
|
|
|
mode is uninitialized, return -1.
|
|
|
|
*/
|
|
|
|
int reader_get_cursor_pos();
|
|
|
|
|
|
|
|
/**
|
2006-10-04 21:42:04 +00:00
|
|
|
Return the value of the interrupted flag, which is set by the sigint
|
2005-09-20 13:26:39 +00:00
|
|
|
handler, and clear it if it was set.
|
|
|
|
*/
|
2006-10-04 21:42:04 +00:00
|
|
|
int reader_interrupted();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Read one line of input. Before calling this function, reader_push()
|
|
|
|
must have been called in order to set up a valid reader
|
|
|
|
environment.
|
|
|
|
*/
|
2012-02-06 09:45:16 +00:00
|
|
|
const wchar_t *reader_readline();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-27 03:18:46 +00:00
|
|
|
Push a new reader environment.
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
void reader_push( const wchar_t *name );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return to previous reader environment
|
|
|
|
*/
|
|
|
|
void reader_pop();
|
|
|
|
|
|
|
|
/**
|
2011-12-27 03:18:46 +00:00
|
|
|
Specify function to use for finding possible tab completions. The function must take these arguments:
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
- The command to be completed as a null terminated array of wchar_t
|
|
|
|
- An array_list_t in which completions will be inserted.
|
|
|
|
*/
|
2012-02-27 04:11:34 +00:00
|
|
|
typedef void (*complete_function_t)( const wcstring &, std::vector<completion_t> &, complete_type_t, wcstring_list_t * lst );
|
2012-02-24 20:13:35 +00:00
|
|
|
void reader_set_complete_function( complete_function_t );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-27 03:18:46 +00:00
|
|
|
The type of a highlight function.
|
|
|
|
*/
|
2012-07-21 03:39:31 +00:00
|
|
|
class env_vars_snapshot_t;
|
|
|
|
typedef void (*highlight_function_t)( const wcstring &, std::vector<int> &, int, wcstring_list_t *, const env_vars_snapshot_t &vars );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2011-12-27 03:18:46 +00:00
|
|
|
/**
|
|
|
|
Specify function for syntax highlighting. The function must take these arguments:
|
|
|
|
|
|
|
|
- The command to be highlighted as a null terminated array of wchar_t
|
|
|
|
- The color code of each character as an array of ints
|
|
|
|
- The cursor position
|
|
|
|
- An array_list_t used for storing error messages
|
|
|
|
*/
|
|
|
|
void reader_set_highlight_function( highlight_function_t );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Specify function for testing if the command buffer contains syntax
|
|
|
|
errors that must be corrected before returning.
|
|
|
|
*/
|
2012-02-06 09:45:16 +00:00
|
|
|
void reader_set_test_function( int (*f)( const wchar_t * ) );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Specify string of shell commands to be run in order to generate the
|
|
|
|
prompt.
|
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
void reader_set_prompt( const wchar_t *prompt );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-27 03:18:46 +00:00
|
|
|
Returns true if the shell is exiting, 0 otherwise.
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
|
|
|
int exit_status();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Replace the current token with the specified string
|
|
|
|
*/
|
2012-02-02 22:27:13 +00:00
|
|
|
void reader_replace_current_token( const wchar_t *new_token );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-14 11:40:33 +00:00
|
|
|
/**
|
2006-10-04 21:42:04 +00:00
|
|
|
The readers interrupt signal handler. Cancels all currently running blocks.
|
2005-10-14 11:40:33 +00:00
|
|
|
*/
|
2005-10-05 22:37:08 +00:00
|
|
|
void reader_handle_int( int signal );
|
|
|
|
|
2006-05-14 10:16:23 +00:00
|
|
|
/**
|
|
|
|
This function returns true if fish is exiting by force, i.e. because stdin died
|
|
|
|
*/
|
|
|
|
int reader_exit_forced();
|
|
|
|
|
2007-01-29 16:26:24 +00:00
|
|
|
/**
|
|
|
|
Test if the given shell command contains errors. Uses parser_test
|
|
|
|
for testing. Suitable for reader_set_test_function().
|
|
|
|
*/
|
2012-02-06 09:45:16 +00:00
|
|
|
int reader_shell_test( const wchar_t *b );
|
2007-01-29 16:26:24 +00:00
|
|
|
|
2007-09-21 14:05:49 +00:00
|
|
|
/**
|
|
|
|
Test whether the interactive reader is in search mode.
|
|
|
|
|
|
|
|
\return o if not in search mode, 1 if in search mode and -1 if not in interactive mode
|
|
|
|
*/
|
|
|
|
int reader_search_mode();
|
|
|
|
|
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|