2005-09-20 13:26:39 +00:00
/** \file highlight.h
2012-11-18 10:23:22 +00:00
Prototypes for functions for syntax highlighting
2005-09-20 13:26:39 +00:00
*/
2005-10-04 15:11:39 +00:00
# ifndef FISH_HIGHLIGHT_H
# define FISH_HIGHLIGHT_H
# include <wchar.h>
2011-12-27 03:18:46 +00:00
# include "env.h"
2005-10-04 15:11:39 +00:00
# include "util.h"
2012-02-13 02:05:59 +00:00
# include "color.h"
2005-10-04 15:11:39 +00:00
2014-01-15 09:01:25 +00:00
/* Internally, we specify highlight colors using a set of bits. Each highlight_spec is a 32 bit uint. We divide this into low 16 (foreground) and high 16 (background). Each half we further subdivide into low 8 (primary) and high 8 (modifiers). The primary is not a bitmask; specify exactly one. The modifiers are a bitmask; specify any number */
enum
{
/* The following values are mutually exclusive; specify at most one */
highlight_spec_normal = 0 , // normal text
highlight_spec_error , // error
highlight_spec_command , //command
highlight_spec_statement_terminator , //process separator
highlight_spec_param , //command parameter (argument)
highlight_spec_comment , //comment
highlight_spec_match , //matching parenthesis, etc.
highlight_spec_search_match , //search match
highlight_spec_operator , //operator
highlight_spec_escape , //escape sequences
highlight_spec_quote , //quoted string
highlight_spec_redirection , //redirection
highlight_spec_autosuggestion , //autosuggestion
2014-01-15 09:40:40 +00:00
2014-01-15 09:36:09 +00:00
// Pager support
highlight_spec_pager_prefix ,
highlight_spec_pager_completion ,
highlight_spec_pager_description ,
highlight_spec_pager_progress ,
highlight_spec_pager_secondary ,
2014-01-15 10:05:46 +00:00
2014-01-15 09:01:25 +00:00
HIGHLIGHT_SPEC_PRIMARY_MASK = 0xFF ,
2014-01-15 09:40:40 +00:00
2014-01-15 09:01:25 +00:00
/* The following values are modifiers */
highlight_modifier_valid_path = 0x100 ,
2014-01-26 08:41:30 +00:00
highlight_modifier_force_underline = 0x200 ,
highlight_modifier_sloppy_background = 0x300 , //hackish, indicates that we should treat a foreground color as background, per certain historical behavior
2014-01-15 09:40:40 +00:00
2014-01-15 09:01:25 +00:00
/* Very special value */
highlight_spec_invalid = 0xFFFF
2014-01-15 09:40:40 +00:00
2014-01-15 09:01:25 +00:00
} ;
typedef uint32_t highlight_spec_t ;
inline highlight_spec_t highlight_get_primary ( highlight_spec_t val )
{
return val & HIGHLIGHT_SPEC_PRIMARY_MASK ;
}
inline highlight_spec_t highlight_make_background ( highlight_spec_t val )
{
2014-01-23 01:45:27 +00:00
assert ( val > > 16 = = 0 ) ; //should have nothing in upper bits, otherwise this is already a background
2014-01-15 09:01:25 +00:00
return val < < 16 ;
}
2006-06-20 00:50:10 +00:00
2012-02-07 04:14:19 +00:00
2012-06-28 18:54:37 +00:00
class history_item_t ;
2012-07-01 23:11:14 +00:00
struct file_detection_context_t ;
2012-06-28 18:54:37 +00:00
2005-09-20 13:26:39 +00: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 10:23:22 +00: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 13:26:39 +00: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 .
*/
2014-01-15 09:01:25 +00:00
void highlight_shell ( const wcstring & buffstr , std : : vector < highlight_spec_t > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
void highlight_shell_new_parser ( const wcstring & buffstr , std : : vector < highlight_spec_t > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
2005-09-20 13:26:39 +00: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 10:23:22 +00: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 13:26:39 +00: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 .
*/
2014-01-15 09:01:25 +00:00
void highlight_universal ( const wcstring & buffstr , std : : vector < highlight_spec_t > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
2005-09-20 13:26:39 +00:00
/**
Translate from HIGHLIGHT_ * to FISH_COLOR_ * according to environment
variables . Defaults to FISH_COLOR_NORMAL .
2012-11-18 10:23:22 +00:00
Example :
2005-09-20 13:26:39 +00:00
If the environment variable FISH_FISH_COLOR_ERROR is set to ' red ' , a
2014-01-15 09:01:25 +00:00
call to highlight_get_color ( highlight_error ) will return
2005-09-20 13:26:39 +00:00
FISH_COLOR_RED .
*/
2014-01-15 09:01:25 +00:00
rgb_color_t highlight_get_color ( highlight_spec_t highlight , bool is_background ) ;
2005-10-04 15:11:39 +00:00
2012-05-08 00:31:24 +00: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 03:39:31 +00: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 00:31:24 +00:00
2012-07-06 21:34:53 +00: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 00:31:24 +00:00
*/
2012-02-20 10:13:31 +00:00
bool autosuggest_suggest_special ( const wcstring & str , const wcstring & working_directory , wcstring & outString ) ;
2012-02-19 02:54:36 +00:00
2012-05-14 03:19:02 +00: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 00:30:30 +00:00
enum
{
2012-07-06 21:34:53 +00:00
/* The path must be to a directory */
PATH_REQUIRE_DIR = 1 < < 0 ,
2012-11-18 10:23:22 +00:00
2012-07-06 21:34:53 +00: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 05:56:30 +00:00
2013-10-06 23:23:45 +00:00
/* For testing */
2014-01-15 09:01:25 +00:00
void highlight_shell_classic ( const wcstring & buff , std : : vector < highlight_spec_t > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
void highlight_shell_new_parser ( const wcstring & buff , std : : vector < highlight_spec_t > & color , size_t pos , wcstring_list_t * error , const env_vars_snapshot_t & vars ) ;
2013-10-06 23:23:45 +00:00
2005-10-04 15:11:39 +00:00
# endif
2012-02-19 02:54:36 +00:00