mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
create reader_data_t.interruptible flag and infrastructure to make it work.
This commit is contained in:
parent
a0edee51fa
commit
abae08a9fb
3 changed files with 37 additions and 4 deletions
|
@ -507,7 +507,7 @@ wint_t input_readch()
|
|||
/*
|
||||
Clear the interrupted flag
|
||||
*/
|
||||
reader_interrupted();
|
||||
reader_reset_interrupted();
|
||||
|
||||
/*
|
||||
Search for sequence in mapping tables
|
||||
|
|
25
reader.cpp
25
reader.cpp
|
@ -323,6 +323,9 @@ public:
|
|||
/** Whether a screen reset is needed after a repaint. */
|
||||
bool screen_reset_needed;
|
||||
|
||||
/** Whether the reader should exit on ^C. */
|
||||
bool interruptible;
|
||||
|
||||
/** Constructor */
|
||||
reader_data_t() :
|
||||
allow_autosuggestion(0),
|
||||
|
@ -339,7 +342,8 @@ public:
|
|||
next(0),
|
||||
search_mode(0),
|
||||
repaint_needed(0),
|
||||
screen_reset_needed(0)
|
||||
screen_reset_needed(0),
|
||||
interruptible(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -373,7 +377,7 @@ static pid_t original_pid;
|
|||
/**
|
||||
This variable is set to true by the signal handler when ^C is pressed
|
||||
*/
|
||||
static int interrupted=0;
|
||||
static volatile int interrupted=0;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -632,11 +636,23 @@ static void remove_duplicates(std::vector<completion_t> &l)
|
|||
l.erase(std::unique(l.begin(), l.end()), l.end());
|
||||
}
|
||||
|
||||
|
||||
void reader_reset_interrupted()
|
||||
{
|
||||
interrupted = 0;
|
||||
}
|
||||
|
||||
int reader_interrupted()
|
||||
{
|
||||
int res=interrupted;
|
||||
if (res)
|
||||
{
|
||||
interrupted=0;
|
||||
}
|
||||
if (res && data && data->interruptible)
|
||||
{
|
||||
reader_exit(1, 0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -2380,6 +2396,11 @@ void reader_set_test_function(int (*f)(const wchar_t *))
|
|||
data->test_func = f;
|
||||
}
|
||||
|
||||
void reader_set_interruptible(bool i)
|
||||
{
|
||||
data->interruptible = i;
|
||||
}
|
||||
|
||||
void reader_import_history_if_necessary(void)
|
||||
{
|
||||
/* Import history from bash, etc. if our current history is empty */
|
||||
|
|
14
reader.h
14
reader.h
|
@ -111,9 +111,18 @@ void reader_set_buffer(const wcstring &b, size_t p);
|
|||
*/
|
||||
size_t reader_get_cursor_pos();
|
||||
|
||||
/**
|
||||
Clear the interrupted flag unconditionally without handling anything. The
|
||||
flag could have been set e.g. when an interrupt arrived just as we were
|
||||
ending an earlier \c reader_readline invocation but before the
|
||||
\c is_interactive_read flag was cleared.
|
||||
*/
|
||||
void reader_reset_interrupted();
|
||||
|
||||
/**
|
||||
Return the value of the interrupted flag, which is set by the sigint
|
||||
handler, and clear it if it was set.
|
||||
handler, and clear it if it was set. If the current reader is interruptible,
|
||||
call \c reader_exit().
|
||||
*/
|
||||
int reader_interrupted();
|
||||
|
||||
|
@ -181,6 +190,9 @@ void reader_set_right_prompt(const wcstring &prompt);
|
|||
/** Sets whether autosuggesting is allowed. */
|
||||
void reader_set_allow_autosuggesting(bool flag);
|
||||
|
||||
/** Sets whether the reader should exit on ^C. */
|
||||
void reader_set_interruptible(bool flag);
|
||||
|
||||
/**
|
||||
Returns true if the shell is exiting, 0 otherwise.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue