2016-05-01 11:47:05 +08:00
|
|
|
// Prototypes for functions for syntax highlighting.
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_HIGHLIGHT_H
|
|
|
|
#define FISH_HIGHLIGHT_H
|
|
|
|
|
2017-02-13 12:24:22 +08:00
|
|
|
#include <stddef.h>
|
2016-04-21 14:00:54 +08:00
|
|
|
#include <stdint.h>
|
2017-02-14 12:37:27 +08:00
|
|
|
|
2016-04-21 14:00:54 +08:00
|
|
|
#include <vector>
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2016-05-01 11:47:05 +08:00
|
|
|
#include "color.h"
|
2016-04-21 14:00:54 +08:00
|
|
|
#include "common.h"
|
2011-12-27 11:18:46 +08:00
|
|
|
#include "env.h"
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2016-05-01 11:47:05 +08: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 22:44:27 +08:00
|
|
|
highlight_spec_selection,
|
2014-01-15 17:40:40 +08:00
|
|
|
|
2016-05-01 11:47:05 +08:00
|
|
|
// Pager support.
|
2019-01-13 15:16:30 +08:00
|
|
|
// NOTE: pager.cpp relies on these being in this order.
|
|
|
|
highlight_spec_pager_progress,
|
|
|
|
highlight_spec_pager_background,
|
2014-01-15 17:36:09 +08:00
|
|
|
highlight_spec_pager_prefix,
|
|
|
|
highlight_spec_pager_completion,
|
|
|
|
highlight_spec_pager_description,
|
2019-01-13 15:16:30 +08:00
|
|
|
highlight_spec_pager_secondary_background,
|
|
|
|
highlight_spec_pager_secondary_prefix,
|
|
|
|
highlight_spec_pager_secondary_completion,
|
|
|
|
highlight_spec_pager_secondary_description,
|
|
|
|
highlight_spec_pager_selected_background,
|
|
|
|
highlight_spec_pager_selected_prefix,
|
|
|
|
highlight_spec_pager_selected_completion,
|
|
|
|
highlight_spec_pager_selected_description,
|
2014-01-15 18:05:46 +08:00
|
|
|
|
2019-01-13 13:35:12 +08:00
|
|
|
// Used to double check a data structure in highlight.cpp
|
|
|
|
HIGHLIGHT_SPEC_MAX,
|
|
|
|
|
2014-01-15 17:01:25 +08:00
|
|
|
HIGHLIGHT_SPEC_PRIMARY_MASK = 0xFF,
|
2014-01-15 17:40:40 +08:00
|
|
|
|
2016-05-01 11:47:05 +08:00
|
|
|
// The following values are modifiers.
|
2014-01-15 17:01:25 +08:00
|
|
|
highlight_modifier_valid_path = 0x100,
|
2014-01-26 16:41:30 +08:00
|
|
|
highlight_modifier_force_underline = 0x200,
|
2014-01-15 17:01:25 +08:00
|
|
|
/* Very special value */
|
|
|
|
highlight_spec_invalid = 0xFFFF
|
2014-01-15 17:40:40 +08:00
|
|
|
|
2014-01-15 17:01:25 +08:00
|
|
|
};
|
|
|
|
typedef uint32_t highlight_spec_t;
|
|
|
|
|
2016-05-01 11:47:05 +08:00
|
|
|
inline highlight_spec_t highlight_get_primary(highlight_spec_t val) {
|
2014-01-15 17:01:25 +08:00
|
|
|
return val & HIGHLIGHT_SPEC_PRIMARY_MASK;
|
|
|
|
}
|
|
|
|
|
2016-05-01 11:47:05 +08:00
|
|
|
inline highlight_spec_t highlight_make_background(highlight_spec_t val) {
|
|
|
|
assert(val >> 16 ==
|
|
|
|
0); // should have nothing in upper bits, otherwise this is already a background
|
2014-01-15 17:01:25 +08:00
|
|
|
return val << 16;
|
|
|
|
}
|
2006-06-20 08:50:10 +08:00
|
|
|
|
2012-06-29 02:54:37 +08:00
|
|
|
class history_item_t;
|
|
|
|
|
2016-05-01 11:47:05 +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.
|
|
|
|
///
|
2016-06-06 09:46:04 +08:00
|
|
|
/// \param buffstr The buffer on which to perform syntax highlighting
|
2016-05-01 11:47:05 +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.
|
|
|
|
/// \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.
|
|
|
|
void highlight_shell(const wcstring &buffstr, std::vector<highlight_spec_t> &color, size_t pos,
|
2018-09-09 17:25:51 +08:00
|
|
|
wcstring_list_t *error, const environment_t &vars);
|
2016-05-01 11:47:05 +08:00
|
|
|
|
|
|
|
/// Perform a non-blocking shell highlighting. The function will not do any I/O that may block. As a
|
|
|
|
/// result, invalid commands may not be detected, etc.
|
|
|
|
void highlight_shell_no_io(const wcstring &buffstr, std::vector<highlight_spec_t> &color,
|
2018-09-09 17:25:51 +08:00
|
|
|
size_t pos, wcstring_list_t *error, const environment_t &vars);
|
2016-05-01 11:47:05 +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.
|
|
|
|
///
|
2016-06-06 09:46:04 +08:00
|
|
|
/// \param buffstr The buffer on which to perform syntax highlighting
|
2016-05-01 11:47:05 +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.
|
|
|
|
/// \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.
|
|
|
|
void highlight_universal(const wcstring &buffstr, std::vector<highlight_spec_t> &color, size_t pos,
|
2018-09-09 17:25:51 +08:00
|
|
|
wcstring_list_t *error, const environment_t &vars);
|
2016-05-01 11:47:05 +08:00
|
|
|
|
|
|
|
/// Translate from HIGHLIGHT_* to FISH_COLOR_* according to environment variables. Defaults to
|
|
|
|
/// FISH_COLOR_NORMAL.
|
|
|
|
///
|
|
|
|
/// Example:
|
|
|
|
///
|
|
|
|
/// 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.
|
2014-01-15 17:01:25 +08:00
|
|
|
rgb_color_t highlight_get_color(highlight_spec_t highlight, bool is_background);
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2016-05-01 11:47:05 +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.
|
|
|
|
bool autosuggest_validate_from_history(const history_item_t &item,
|
|
|
|
const wcstring &working_directory,
|
2018-09-09 17:25:51 +08:00
|
|
|
const environment_t &vars);
|
2016-05-01 11:47:05 +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.
|
|
|
|
enum {
|
|
|
|
// The path must be to a directory.
|
2012-07-07 05:34:53 +08:00
|
|
|
PATH_REQUIRE_DIR = 1 << 0,
|
2016-05-01 11:47:05 +08:00
|
|
|
// Expand any leading tilde in the path.
|
2012-07-07 05:34:53 +08:00
|
|
|
PATH_EXPAND_TILDE = 1 << 1
|
|
|
|
};
|
|
|
|
typedef unsigned int path_flags_t;
|
2016-05-01 11:47:05 +08:00
|
|
|
bool is_potential_path(const wcstring &const_path, const wcstring_list_t &directories,
|
2018-09-19 12:03:01 +08:00
|
|
|
const environment_t &vars, path_flags_t flags);
|
2012-02-19 13:56:30 +08:00
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|