2005-09-20 21:26:39 +08:00
/** \file highlight.h
2012-11-18 18:23:22 +08:00
Prototypes for functions for syntax highlighting
2005-09-20 21:26:39 +08:00
*/
2005-10-04 23:11:39 +08:00
# ifndef FISH_HIGHLIGHT_H
# define FISH_HIGHLIGHT_H
# include <wchar.h>
2011-12-27 11:18:46 +08:00
# include "env.h"
2005-10-04 23:11:39 +08:00
# include "util.h"
2012-02-12 09:07:56 +08:00
# include "screen.h"
2012-02-13 10:05:59 +08:00
# include "color.h"
2005-10-04 23:11:39 +08:00
2006-06-20 08:50:10 +08:00
/**
Internal value representing highlighting of normal text
*/
# define HIGHLIGHT_NORMAL 0x1
/**
Internal value representing highlighting of an error
*/
# define HIGHLIGHT_ERROR 0x2
/**
Internal value representing highlighting of a command
*/
# define HIGHLIGHT_COMMAND 0x4
/**
Internal value representing highlighting of a process separator
*/
# define HIGHLIGHT_END 0x8
/**
Internal value representing highlighting of a regular command parameter
*/
# define HIGHLIGHT_PARAM 0x10
/**
Internal value representing highlighting of a comment
*/
# define HIGHLIGHT_COMMENT 0x20
/**
Internal value representing highlighting of a matching parenteses , etc .
*/
# define HIGHLIGHT_MATCH 0x40
/**
Internal value representing highlighting of a search match
*/
# define HIGHLIGHT_SEARCH_MATCH 0x80
/**
Internal value representing highlighting of an operator
*/
# define HIGHLIGHT_OPERATOR 0x100
/**
Internal value representing highlighting of an escape sequence
*/
# define HIGHLIGHT_ESCAPE 0x200
/**
Internal value representing highlighting of a quoted string
*/
# define HIGHLIGHT_QUOTE 0x400
/**
Internal value representing highlighting of an IO redirection
*/
2012-11-18 18:23:22 +08:00
# define HIGHLIGHT_REDIRECTION 0x800
2006-06-20 08:50:10 +08:00
/**
Internal value representing highlighting a potentially valid path
*/
# define HIGHLIGHT_VALID_PATH 0x1000
2012-02-07 12:14:19 +08:00
/**
Internal value representing highlighting an autosuggestion
*/
# define HIGHLIGHT_AUTOSUGGESTION 0x2000
2012-06-29 02:54:37 +08:00
class history_item_t ;
2012-07-02 07:11:14 +08:00
struct file_detection_context_t ;
2012-06-29 02:54:37 +08:00
2005-09-20 21:26:39 +08:00
/**
Perform syntax highlighting for the shell commands in buff . The result is
stored in the color array as a color_code from the HIGHLIGHT_ enum
for each character in buff .
\ param buff The buffer on which to perform syntax highlighting
2012-11-18 18:23:22 +08:00
\ param color The array in wchich to store the color codes . The first 8 bits are used for fg color , the next 8 bits for bg color .
2005-09-20 21:26:39 +08:00
\ param pos the cursor position . Used for quote matching , etc .
\ param error a list in which a description of each error will be inserted . May be 0 , in whcich case no error descriptions will be generated .
*/
2012-11-19 08:30:30 +08:00
void highlight_shell ( const wcstring & buffstr , std : : vector < int > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
2005-09-20 21:26:39 +08:00
/**
Perform syntax highlighting for the text in buff . Matching quotes and paranthesis are highlighted . The result is
stored in the color array as a color_code from the HIGHLIGHT_ enum
for each character in buff .
\ param buff The buffer on which to perform syntax highlighting
2012-11-18 18:23:22 +08:00
\ param color The array in wchich to store the color codes . The first 8 bits are used for fg color , the next 8 bits for bg color .
2005-09-20 21:26:39 +08:00
\ param pos the cursor position . Used for quote matching , etc .
\ param error a list in which a description of each error will be inserted . May be 0 , in whcich case no error descriptions will be generated .
*/
2012-11-19 08:30:30 +08:00
void highlight_universal ( const wcstring & buffstr , std : : vector < int > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
2005-09-20 21:26:39 +08:00
/**
Translate from HIGHLIGHT_ * to FISH_COLOR_ * according to environment
variables . Defaults to FISH_COLOR_NORMAL .
2012-11-18 18:23:22 +08:00
Example :
2005-09-20 21:26:39 +08:00
If the environment variable FISH_FISH_COLOR_ERROR is set to ' red ' , a
call to highlight_get_color ( HIGHLIGHT_ERROR ) will return
FISH_COLOR_RED .
*/
2012-11-19 08:30:30 +08:00
rgb_color_t highlight_get_color ( int highlight , bool is_background ) ;
2005-10-04 23:11:39 +08:00
2012-05-08 08:31:24 +08:00
/** Given a command 'str' from the history, try to determine whether we ought to suggest it by specially recognizing the command.
Returns true if we validated the command . If so , returns by reference whether the suggestion is valid or not .
*/
2012-07-21 11:39:31 +08:00
bool autosuggest_validate_from_history ( const history_item_t & item , file_detection_context_t & detector , const wcstring & working_directory , const env_vars_snapshot_t & vars ) ;
2012-05-08 08:31:24 +08:00
2012-07-07 05:34:53 +08:00
/** Given the command line contents 'str', return via reference a suggestion by specially recognizing the command. The suggestion is escaped. Returns true if we recognized the command (even if we couldn't think of a suggestion for it).
2012-05-08 08:31:24 +08:00
*/
2012-02-20 18:13:31 +08:00
bool autosuggest_suggest_special ( const wcstring & str , const wcstring & working_directory , wcstring & outString ) ;
2012-02-19 10:54:36 +08:00
2012-05-14 11:19:02 +08:00
/* Tests whether the specified string cpath is the prefix of anything we could cd to. directories is a list of possible parent directories (typically either the working directory, or the cdpath). This does I/O!
This is used only internally to this file , and is exposed only for testing .
*/
2012-11-19 08:30:30 +08:00
enum
{
2012-07-07 05:34:53 +08:00
/* The path must be to a directory */
PATH_REQUIRE_DIR = 1 < < 0 ,
2012-11-18 18:23:22 +08:00
2012-07-07 05:34:53 +08:00
/* Expand any leading tilde in the path */
PATH_EXPAND_TILDE = 1 < < 1
} ;
typedef unsigned int path_flags_t ;
bool is_potential_path ( const wcstring & const_path , const wcstring_list_t & directories , path_flags_t flags , wcstring * out_path = NULL ) ;
2012-02-19 13:56:30 +08:00
2005-10-04 23:11:39 +08:00
# endif
2012-02-19 10:54:36 +08:00