diff options
author | 2014-01-17 12:53:01 -0800 | |
---|---|---|
committer | 2014-01-17 12:53:01 -0800 | |
commit | 32054b6f326abab45c6d1e6047b50e643be49a7b (patch) | |
tree | cdcdbf239cb094f4a7016de1df228eca649422a3 | |
parent | c6e5201e15daf86fc25857164d51d5b9f29e0808 (diff) |
Implement and document new -P / --paging-mode flags to commandline, to support new
pager
-rw-r--r-- | builtin_commandline.cpp | 101 | ||||
-rw-r--r-- | doc_src/commandline.txt | 10 | ||||
-rw-r--r-- | reader.cpp | 12 | ||||
-rw-r--r-- | reader.h | 10 |
4 files changed, 62 insertions, 71 deletions
diff --git a/builtin_commandline.cpp b/builtin_commandline.cpp index 8b6c409a..564eee7b 100644 --- a/builtin_commandline.cpp +++ b/builtin_commandline.cpp @@ -213,6 +213,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) int cursor_mode = 0; int line_mode = 0; int search_mode = 0; + int paging_mode = 0; const wchar_t *begin, *end; current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer(); @@ -251,71 +252,24 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) static const struct woption long_options[] = { - { - L"append", no_argument, 0, 'a' - } - , - { - L"insert", no_argument, 0, 'i' - } - , - { - L"replace", no_argument, 0, 'r' - } - , - { - L"current-job", no_argument, 0, 'j' - } - , - { - L"current-process", no_argument, 0, 'p' - } - , - { - L"current-token", no_argument, 0, 't' - } - , - { - L"current-buffer", no_argument, 0, 'b' - } - , - { - L"cut-at-cursor", no_argument, 0, 'c' - } - , - { - L"function", no_argument, 0, 'f' - } - , - { - L"tokenize", no_argument, 0, 'o' - } - , - { - L"help", no_argument, 0, 'h' - } - , - { - L"input", required_argument, 0, 'I' - } - , - { - L"cursor", no_argument, 0, 'C' - } - , - { - L"line", no_argument, 0, 'L' - } - , - { - L"search-mode", no_argument, 0, 'S' - } - , - { - 0, 0, 0, 0 - } - } - ; + { L"append", no_argument, 0, 'a' }, + { L"insert", no_argument, 0, 'i' }, + { L"replace", no_argument, 0, 'r' }, + { L"current-job", no_argument, 0, 'j' }, + { L"current-process", no_argument, 0, 'p' }, + { L"current-token", no_argument, 0, 't' }, + { L"current-buffer", no_argument, 0, 'b' }, + { L"cut-at-cursor", no_argument, 0, 'c' }, + { L"function", no_argument, 0, 'f' }, + { L"tokenize", no_argument, 0, 'o' }, + { L"help", no_argument, 0, 'h' }, + { L"input", required_argument, 0, 'I' }, + { L"cursor", no_argument, 0, 'C' }, + { L"line", no_argument, 0, 'L' }, + { L"search-mode", no_argument, 0, 'S' }, + { L"paging-mode", no_argument, 0, 'P' }, + { 0, 0, 0, 0 } + }; int opt_index = 0; @@ -397,6 +351,10 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) case 'S': search_mode = 1; break; + + case 'P': + paging_mode = 1; + break; case 'h': builtin_print_help(parser, argv[0], stdout_buffer); @@ -415,7 +373,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) /* Check for invalid switch combinations */ - if (buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode) + if (buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode || paging_mode) { append_format(stderr_buffer, BUILTIN_ERR_COMBO, @@ -464,7 +422,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) /* Check for invalid switch combinations */ - if ((search_mode || line_mode || cursor_mode) && (argc-woptind > 1)) + if ((search_mode || line_mode || cursor_mode || paging_mode) && (argc-woptind > 1)) { append_format(stderr_buffer, @@ -475,7 +433,7 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) return 1; } - if ((buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode)) + if ((buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode || paging_mode)) { append_format(stderr_buffer, BUILTIN_ERR_COMBO, @@ -564,7 +522,12 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv) if (search_mode) { - return !reader_search_mode(); + return ! reader_search_mode(); + } + + if (paging_mode) + { + return ! reader_has_pager_contents(); } diff --git a/doc_src/commandline.txt b/doc_src/commandline.txt index ab771e96..1d13f79e 100644 --- a/doc_src/commandline.txt +++ b/doc_src/commandline.txt @@ -57,6 +57,16 @@ If \c commandline is called during a call to complete a given string using <code>complete -C STRING</code>, \c commandline will consider the specified string to be the current contents of the command line. +The following options output metadata about the commandline state: + +- \c -L or \c --line print the line that the cursor is on, with the topmost +line starting at 1 +- \c -S or \c --search-mode evaluates to true if the commandline is performing +a history search +- \c -P or \c --paging-mode evaluates to true if the commandline is showing +pager contents, such as tab completions + + \subsection commandline-example Example <tt>commandline -j $history[3]</tt> replaces the job under the cursor with the @@ -3872,7 +3872,17 @@ int reader_search_mode() return -1; } - return !!data->search_mode; + return !! data->search_mode; +} + +int reader_has_pager_contents() +{ + if (!data) + { + return -1; + } + + return data->current_page_rendering.screen_data.empty() ? 1 : 0; } @@ -239,10 +239,18 @@ int reader_shell_test(const wchar_t *b); /** Test whether the interactive reader is in search mode. - \return o if not in search mode, 1 if in search mode and -1 if not in interactive mode + \return 0 if not in search mode, 1 if in search mode and -1 if not in interactive mode */ int reader_search_mode(); +/** + Test whether the interactive reader has visible pager contents. + + \return 0 if it has pager contents, 1 if it does not have pager contents, and -1 if not in interactive mode + */ +int reader_has_pager_contents(); + + /* Given a command line and an autosuggestion, return the string that gets shown to the user. Exposed for testing purposes only. */ wcstring combine_command_and_autosuggestion(const wcstring &cmdline, const wcstring &autosuggestion); |