Rename 'new-mode' to 'sets-mode', prepare for selection support.

This commit is contained in:
Julian Aron Prenner 2014-01-15 11:39:19 +01:00
parent 874d3aca45
commit dede320630
3 changed files with 53 additions and 28 deletions

View file

@ -415,9 +415,9 @@ static void builtin_bind_list(const wchar_t *bind_mode)
std::vector<wcstring> ecmds;
wcstring mode;
wcstring new_mode;
wcstring sets_mode;
input_mapping_get(seq, ecmds, mode, new_mode);
input_mapping_get(seq, ecmds, mode, sets_mode);
if(bind_mode != NULL && wcscmp(mode.c_str(), bind_mode))
{
@ -427,7 +427,7 @@ static void builtin_bind_list(const wchar_t *bind_mode)
wcstring tname;
if (input_terminfo_get_name(seq, tname))
{
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", tname.c_str(), mode.c_str(), new_mode.c_str());
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", tname.c_str(), mode.c_str(), sets_mode.c_str());
for(int i = 0; i < ecmds.size(); i++)
{
wcstring ecmd = ecmds.at(i);
@ -438,7 +438,7 @@ static void builtin_bind_list(const wchar_t *bind_mode)
else
{
const wcstring eseq = escape_string(seq, 1);
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", eseq.c_str(), mode.c_str(), new_mode.c_str());
append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", eseq.c_str(), mode.c_str(), sets_mode.c_str());
for(int i = 0; i < ecmds.size(); i++)
{
wcstring ecmd = ecmds.at(i);
@ -486,7 +486,7 @@ static void builtin_bind_function_names()
Add specified key binding.
*/
static int builtin_bind_add(const wchar_t *seq, const wchar_t **cmds, size_t cmds_len,
const wchar_t *mode, const wchar_t *new_mode, int terminfo)
const wchar_t *mode, const wchar_t *sets_mode, int terminfo)
{
if (terminfo)
@ -494,7 +494,7 @@ static int builtin_bind_add(const wchar_t *seq, const wchar_t **cmds, size_t cmd
wcstring seq2;
if (input_terminfo_get_sequence(seq, &seq2))
{
input_mapping_add(seq2.c_str(), cmds, cmds_len, mode, new_mode);
input_mapping_add(seq2.c_str(), cmds, cmds_len, mode, sets_mode);
}
else
{
@ -527,7 +527,7 @@ static int builtin_bind_add(const wchar_t *seq, const wchar_t **cmds, size_t cmd
}
else
{
input_mapping_add(seq, cmds, cmds_len, mode, new_mode);
input_mapping_add(seq, cmds, cmds_len, mode, sets_mode);
}
return 0;
@ -627,7 +627,7 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
}
,
{
L"new-mode", required_argument, 0, 'm'
L"sets-mode", required_argument, 0, 'm'
}
,
{

View file

@ -70,11 +70,11 @@ struct input_mapping_t
wcstring seq; /**< Character sequence which generates this event */
std::vector<wcstring> commands; /**< commands that should be evaluated by this mapping */
wcstring mode; /**< mode in which this command should be evaluated */
wcstring new_mode; /** new mode that should be switched to after command evaluation */
wcstring sets_mode; /** new mode that should be switched to after command evaluation */
input_mapping_t(const wcstring &s, const std::vector<wcstring> &c,
const wcstring &m = DEFAULT_BIND_MODE,
const wcstring &nm = DEFAULT_BIND_MODE) : seq(s), commands(c), mode(m), new_mode(nm) {}
const wcstring &sm = DEFAULT_BIND_MODE) : seq(s), commands(c), mode(m), sets_mode(sm) {}
};
/**
@ -287,12 +287,12 @@ bool input_set_bind_mode(const wchar_t *bm)
*/
void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t commands_len,
const wchar_t *mode, const wchar_t *new_mode)
const wchar_t *mode, const wchar_t *sets_mode)
{
CHECK(sequence,);
CHECK(commands,);
CHECK(mode,);
CHECK(new_mode,);
CHECK(sets_mode,);
// debug( 0, L"Add mapping from %ls to %ls in mode %ls", escape(sequence, 1), escape(command, 1 ), mode);
@ -304,17 +304,17 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t **commands, size_t
if (m.seq == sequence && m.mode == mode)
{
m.commands = commands_vector;
m.new_mode = new_mode;
m.sets_mode = sets_mode;
return;
}
}
mapping_list.push_back(input_mapping_t(sequence, commands_vector, mode, new_mode));
mapping_list.push_back(input_mapping_t(sequence, commands_vector, mode, sets_mode));
}
void input_mapping_add(const wchar_t *sequence, const wchar_t *command,
const wchar_t *mode, const wchar_t *new_mode)
const wchar_t *mode, const wchar_t *sets_mode)
{
input_mapping_add(sequence, &command, 1, mode, new_mode);
input_mapping_add(sequence, &command, 1, mode, sets_mode);
}
/**
@ -483,7 +483,7 @@ static void input_mapping_execute(const input_mapping_t &m)
}
}
input_set_bind_mode(m.new_mode.c_str());
input_set_bind_mode(m.sets_mode.c_str());
}
@ -546,7 +546,7 @@ static void input_mapping_execute_matching_or_generic()
const input_mapping_t &m = mapping_list.at(i);
//debug(0, L"trying mapping (%ls,%ls,%ls)\n", escape(m.seq.c_str(), 1),
// m.mode.c_str(), m.new_mode.c_str());
// m.mode.c_str(), m.sets_mode.c_str());
if(wcscmp(m.mode.c_str(), input_get_bind_mode()))
{
@ -661,7 +661,7 @@ bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode)
return result;
}
bool input_mapping_get(const wcstring &sequence, std::vector<wcstring> &cmds, wcstring &mode, wcstring &new_mode)
bool input_mapping_get(const wcstring &sequence, std::vector<wcstring> &cmds, wcstring &mode, wcstring &sets_mode)
{
size_t i, sz = mapping_list.size();
@ -672,7 +672,7 @@ bool input_mapping_get(const wcstring &sequence, std::vector<wcstring> &cmds, wc
{
cmds = m.commands;
mode = m.mode;
new_mode = m.new_mode;
sets_mode = m.sets_mode;
return true;
}
}

View file

@ -255,6 +255,15 @@ public:
/** The current position of the cursor in buff. */
size_t buff_pos;
/** Indicates whether a selection is currently active */
bool sel_active;
/** The start position of the current selection, if one. */
size_t sel_start_pos;
/** The stop position of the current selection, if one. */
size_t sel_stop_pos;
/** Name of the current application */
wcstring app_name;
@ -339,6 +348,9 @@ public:
token_history_pos(0),
search_pos(0),
buff_pos(0),
sel_active(0),
sel_start_pos(0),
sel_stop_pos(0),
complete_func(0),
highlight_function(0),
test_func(0),
@ -432,6 +444,16 @@ static void term_donate()
}
/**
Update the cursor position
*/
static void update_buff_pos(int buff_pos)
{
data->buff_pos = buff_pos;
}
/**
Grab control of terminal
*/
@ -792,7 +814,7 @@ bool reader_data_t::expand_abbreviation_as_necessary(size_t cursor_backtrack)
size_t new_buff_pos = this->buff_pos + new_cmdline.size() - this->command_line.size();
this->command_line.swap(new_cmdline);
data->buff_pos = new_buff_pos;
update_buff_pos(new_buff_pos);
data->command_line_changed();
result = true;
}
@ -1566,7 +1588,7 @@ static void accept_autosuggestion(bool full)
data->command_line.push_back(wc);
}
}
data->buff_pos = data->command_line.size();
update_buff_pos(data->command_line.size());
data->command_line_changed();
reader_super_highlight_me_plenty(data->buff_pos);
reader_repaint();
@ -2153,7 +2175,7 @@ static void set_command_line_and_position(const wcstring &new_str, size_t pos)
{
data->command_line = new_str;
data->command_line_changed();
data->buff_pos = pos;
update_buff_pos(pos);
reader_super_highlight_me_plenty(data->buff_pos);
reader_repaint();
}
@ -2402,7 +2424,7 @@ static void move_word(bool move_right, bool erase, enum move_word_style_t style,
}
else
{
data->buff_pos = buff_pos;
update_buff_pos(buff_pos);
reader_repaint();
}
@ -2434,7 +2456,7 @@ void reader_set_buffer(const wcstring &b, size_t pos)
if (pos > command_line_len)
pos = command_line_len;
data->buff_pos = pos;
update_buff_pos(pos);
data->search_mode = NO_SEARCH;
data->search_buff.clear();
@ -3143,7 +3165,7 @@ const wchar_t *reader_readline(void)
case R_BEGINNING_OF_BUFFER:
{
data->buff_pos = 0;
update_buff_pos(0);
reader_repaint();
break;
@ -3154,6 +3176,8 @@ const wchar_t *reader_readline(void)
{
data->buff_pos = data->command_length();
update_buff_pos(data->command_length());
reader_repaint();
break;
}
@ -3239,7 +3263,7 @@ const wchar_t *reader_readline(void)
/* Move the cursor to the end */
if (data->buff_pos != end_of_token_offset)
{
data->buff_pos = end_of_token_offset;
update_buff_pos(end_of_token_offset);
reader_repaint();
}
@ -3704,7 +3728,8 @@ const wchar_t *reader_readline(void)
line_offset_old = data->buff_pos - parse_util_get_offset_from_line(data->command_line, line_old);
total_offset_new = parse_util_get_offset(data->command_line, line_new, line_offset_old - 4*(indent_new-indent_old));
data->buff_pos = total_offset_new;
update_buff_pos(total_offset_new);
reader_repaint();
}