#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/termios.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/poll.h>
#include <unistd.h>
#include <wctype.h>
#include <ncurses.h>
#include <termio.h>
#include <term.h>
#include <sys/select.h>
#include <signal.h>
#include <fcntl.h>
#include <dirent.h>
#include <wchar.h>
#include <assert.h>
#include "fallback.h"
#include "util.h"
#include "wutil.h"
#include "highlight.h"
#include "reader.h"
#include "proc.h"
#include "parser.h"
#include "complete.h"
#include "history.h"
#include "common.h"
#include "sanity.h"
#include "env.h"
#include "exec.h"
#include "expand.h"
#include "tokenizer.h"
#include "kill.h"
#include "input_common.h"
#include "input.h"
#include "function.h"
#include "output.h"
#include "screen.h"
#include "halloc.h"
#include "halloc_util.h"
#include "parse_util.h"
Data Structures | |
| struct | reader_data |
| A struct describing the state of the interactive reader. More... | |
Defines | |
| #define | PREFIX_MAX_LEN 8 |
| Maximum length of prefix string when printing completion list. | |
| #define | DEFAULT_PROMPT L"echo \"$USER@\"; hostname|cut -d . -f 1; echo \" \"; pwd; printf '> ';" |
| A simple prompt for reading shell commands that does not rely on fish specific commands, meaning it will work even if fish is not installed. | |
| #define | PROMPT_FUNCTION_NAME L"fish_prompt" |
| #define | DEFAULT_TITLE L"echo $_ \" \"; pwd" |
| The default title for the reader. | |
| #define | READAHEAD_MAX 256 |
| The maximum number of characters to read from the keyboard without repainting. | |
| #define | KILL_APPEND 0 |
| #define | KILL_PREPEND 1 |
| #define | NO_SEARCH 0 |
| #define | LINE_SEARCH 1 |
| #define | TOKEN_SEARCH 2 |
| #define | SEARCH_BACKWARD 0 |
| #define | SEARCH_FORWARD 1 |
Typedefs | |
| typedef reader_data | reader_data_t |
| A struct describing the state of the interactive reader. | |
Functions | |
| static void | reader_super_highlight_me_plenty (int match_highlight_pos, array_list_t *error) |
| Call specified external highlighting function and then do search highlighting. | |
| static void | term_donate () |
| Give up control of terminal. | |
| static void | term_steal () |
| Grab control of terminal. | |
| int | reader_exit_forced () |
| This function returns true if fish is exiting by force, i.e. | |
| static void | reader_repaint () |
| Repaint the entire commandline. | |
| static void | reader_kill (wchar_t *begin, int length, int mode, int new) |
| Internal helper function for handling killing parts of text. | |
| void | reader_handle_int (int sig) |
| The readers interrupt signal handler. | |
| wchar_t * | reader_current_filename () |
| Returns the filename of the file currently read. | |
| void | reader_push_current_filename (const wchar_t *fn) |
| Push a new filename on the stack of read files. | |
| wchar_t * | reader_pop_current_filename () |
| Pop the current filename from the stack of read files. | |
| static int | check_size () |
| Make sure buffers are large enough to hold current data plus one extra character. | |
| static int | completion_cmp (const void *a, const void *b) |
| static void | sort_completion_list (array_list_t *comp) |
| static void | remove_duplicates (array_list_t *l) |
| Remove any duplicate completions in the list. | |
| int | reader_interrupted () |
| Return the value of the interrupted flag, which is set by the sigint handler, and clear it if it was set. | |
| void | reader_write_title () |
| Write the title to the titlebar. | |
| static void | exec_prompt () |
| Reexecute the prompt command. | |
| void | reader_init () |
| Initialize the reader. | |
| void | reader_destroy () |
| Destroy and free resources used by the reader. | |
| void | reader_exit (int do_exit, int forced) |
| Tell the shell that it should exit after the currently running command finishes. | |
| void | reader_repaint_needed () |
| Call this function to tell the reader that a repaint is needed, and should be performed when possible. | |
| static void | remove_backward () |
| Remove the previous character in the character buffer and on the screen using syntax highlighting, etc. | |
| static int | insert_str (wchar_t *str) |
| Insert the characters of the string into the command line buffer and print them to the screen using syntax highlighting, etc. | |
| static int | insert_char (int c) |
| Insert the character into the command line buffer and print it to the screen using syntax highlighting, etc. | |
| static int | comp_len (const wchar_t *a, const wchar_t *b) |
| Calculate the length of the common prefix substring of two strings. | |
| static int | comp_ilen (const wchar_t *a, const wchar_t *b) |
| Calculate the case insensitive length of the common prefix substring of two strings. | |
| static wchar_t | get_quote (wchar_t *cmd, int len) |
| Find the outermost quoting style of current token. | |
| static void | get_param (wchar_t *cmd, int pos, wchar_t *quote, wchar_t **offset, wchar_t **string, int *type) |
| Calculates information on the parameter at the specified index. | |
| static void | completion_insert (const wchar_t *val, int flags) |
| Insert the string at the current cursor position. | |
| static void | run_pager (wchar_t *prefix, int is_quoted, array_list_t *comp) |
| Run the fish_pager command to display the completion list. | |
| static void | reader_flash () |
| static int | handle_completions (array_list_t *comp) |
| Handle the list of completions. | |
| static void | reader_interactive_init () |
| Initialize data for interactive use. | |
| static void | reader_interactive_destroy () |
| Destroy data for interactive use. | |
| void | reader_sanity_check () |
| Check that the reader is in a sane state. | |
| void | reader_replace_current_token (wchar_t *new_token) |
| Replace the current token with the specified string. | |
| static void | handle_history (const wchar_t *new_str) |
| Set the specified string from the history as the current buffer. | |
| static int | contains_al (const wchar_t *needle, array_list_t *haystack) |
| Check if the specified string is contained in the list, using wcscmp as a comparison function. | |
| static void | reset_token_history () |
| Reset the data structures associated with the token search. | |
| static void | handle_token_history (int forward, int reset) |
| Handles a token search command. | |
| static void | move_word (int dir, int erase, int new) |
| Move buffer position one word or erase one word. | |
| wchar_t * | reader_get_buffer () |
| Get the string of character currently entered into the command buffer, or 0 if interactive mode is uninitialized. | |
| void | reader_set_buffer (wchar_t *b, int p) |
| Set the string of characters in the command buffer, as well as the cursor position. | |
| int | reader_get_cursor_pos () |
| Get the current cursor position in the command line. | |
| void | reader_run_command (const wchar_t *cmd) |
| Run the specified command with the correct terminal modes, and while taking care to perform job notification, set the title, etc. | |
| int | reader_shell_test (wchar_t *b) |
| Test if the given shell command contains errors. | |
| static int | default_test (wchar_t *b) |
| Test if the given string contains error. | |
| void | reader_push (wchar_t *name) |
| Push a new reader environment. | |
| void | reader_pop () |
| Return to previous reader environment. | |
| void | reader_set_prompt (wchar_t *new_prompt) |
| Specify string of shell commands to be run in order to generate the prompt. | |
| void | reader_set_complete_function (void(*f)(const wchar_t *, array_list_t *)) |
| Specify function to use for finding possible tab completions. | |
| void | reader_set_highlight_function (void(*f)(wchar_t *, int *, int, array_list_t *)) |
| Specify function for syntax highlighting. | |
| void | reader_set_test_function (int(*f)(wchar_t *)) |
| Specify function for testing if the command buffer contains syntax errors that must be corrected before returning. | |
| int | exit_status () |
| Returns true if the shell is exiting, 0 otherwise. | |
| static void | handle_end_loop () |
| This function is called when the main loop notices that end_loop has been set while in interactive mode. | |
| static int | read_i () |
| Read interactively. | |
| static int | can_read (int fd) |
| Test if there are bytes available for reading on the specified file descriptor. | |
| static int | wchar_private (wchar_t c) |
| Test if the specified character is in the private use area that fish uses to store internal characters. | |
| static int | is_backslashed (const wchar_t *str, int pos) |
| Test if the specified character in the specified string is backslashed. | |
| wchar_t * | reader_readline () |
| Read one line of input. | |
| int | reader_search_mode () |
| Test whether the interactive reader is in search mode. | |
| static int | read_ni (int fd, io_data_t *io) |
| Read non-interactively. | |
| int | reader_read (int fd, io_data_t *io) |
Read commands from fd until encountering EOF. | |
Variables | |
| static reader_data_t * | data = 0 |
| The current interactive reading context. | |
| static int | is_interactive_read |
| This flag is set to true when fish is interactively reading from stdin. | |
| static int | end_loop = 0 |
| Flag for ending non-interactive shell. | |
| static array_list_t | current_filename |
| The list containing names of files that are being parsed. | |
| static pid_t | original_pid |
| Store the pid of the parent process, so the exit function knows whether it should reset the terminal or not. | |
| static int | interrupted = 0 |
| This variable is set to true by the signal handler when ^C is pressed. | |
| static struct termios | saved_modes |
| Stores the previous termios mode so we can reset the modes when we execute programs and when the shell exits. | |
| static int | exit_forced |
Variable to keep track of forced exits - see reader_exit_forced();. | |
If stdin is a keyboard, it supplies a killring, history, syntax highlighting, tab-completion and various other interactive features.
Internally the interactive mode functions rely in the functions of the input library to read individual characters of input.
Token search is handled incrementally. Actual searches are only done on when searching backwards, since the previous results are saved. The last search position is remembered and a new search continues from the last search position. All search results are saved in the list 'search_prev'. When the user searches forward, i.e. presses Alt-down, the list is consulted for previous search result, and subsequent backwards searches are also handled by consultiung the list up until the end of the list is reached, at which point regular searching will commence.
|
|
A simple prompt for reading shell commands that does not rely on fish specific commands, meaning it will work even if fish is not installed. This is used by read_i. |
|
|
The default title for the reader. This is used by reader_readline. |
|
|
Maximum length of prefix string when printing completion list. Longer prefixes will be ellipsized. |
|
|
The maximum number of characters to read from the keyboard without repainting. Note that this readahead will only occur if new characters are avaialble for reading, fish will never block for more input without repainting. |
|
|
A struct describing the state of the interactive reader. These states can be stacked, in case reader_readline() calls are nested. This happens when the 'read' builtin is used. |
|
||||||||||||
|
Insert the string at the current cursor position. The function checks if the string is quoted or not and correctly escapes the string.
|
|
|
Test if the given string contains error. Since this is the error detection for general purpose, there are no invalid strings, so this function always returns false. |
|
|
Reexecute the prompt command. The output is inserted into data->prompt_buff. |
|
||||||||||||||||||||||||||||
|
Calculates information on the parameter at the specified index.
|
|
||||||||||||
|
Find the outermost quoting style of current token. Returns 0 if token is not quoted. |
|
|
Handle the list of completions. This means the following:
|
|
|
This function is called when the main loop notices that end_loop has been set while in interactive mode. It checks if it is ok to exit. |
|
|
Set the specified string from the history as the current buffer. Do not modify prefix_width. |
|
||||||||||||
|
Handles a token search command.
|
|
||||||||||||||||
|
Move buffer position one word or erase one word. This function updates both the internal buffer and the screen. It is used by M-left, M-right and ^W to do block movement or block erase.
|
|
|
Read interactively. Read input from stdin while providing editing facilities. |
|
||||||||||||
|
Read non-interactively. Read input from stdin without displaying the prompt, using syntax highlighting. This is used for reading scripts and init files. |
|
|
This function returns true if fish is exiting by force, i.e. because stdin died |
|
|
Get the current cursor position in the command line. If interactive mode is uninitialized, return -1. |
|
|
The readers interrupt signal handler. Cancels all currently running blocks. |
|
|
Push a new filename on the stack of read files.
|
|
|
Read one line of input. Remove the current character in the character buffer and on the screen using syntax highlighting, etc. |
|
|
Repaint the entire commandline. This means reset and clear the commandline, write the prompt, perform syntax highlighting, write the commandline and move the cursor. |
|
|
Test whether the interactive reader is in search mode.
|
|
||||||||||||
|
Set the string of characters in the command buffer, as well as the cursor position.
|
|
|
Specify function to use for finding possible tab completions. The function must take these arguments:
|
|
|
Specify function for syntax highlighting. The function must take these arguments:
|
|
|
Test if the given shell command contains errors. Uses parser_test for testing. Suitable for reader_set_test_function(). |
|
||||||||||||
|
Call specified external highlighting function and then do search highlighting. Lastly, clear the background color under the cursor to avoid repaint issues on terminals where e.g. syntax highligthing maykes characters under the sursor unreadable.
|
|
|
Write the title to the titlebar. This function is called just before a new application starts executing and just after it finishes. |
|
|
Remove any duplicate completions in the list. This relies on the list first beeing sorted. |
|
||||||||||||||||
|
Run the fish_pager command to display the completion list. If the fish_pager outputs any text, it is inserted into the input backbuffer.
|
|
|
This flag is set to true when fish is interactively reading from stdin. It changes how a ^C is handled by the fish interrupt handler. |
1.4.4