Skip to content

Commit

Permalink
Merge branch 'multiline-status-line'
Browse files Browse the repository at this point in the history
Add %N macro to 'statusline' option, which adds a line break and
increases height of the status line.

Thanks to Jose Riha (a.k.a. jose1711), qsmodo and jcarreja.

Fix incorrect colors on redrawing wild menu popup on terminal resize.
  • Loading branch information
xaizek committed May 13, 2021
2 parents bc5093a + aaa1c35 commit cfb79fc
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 110 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
Added %Pl and %Pz macros for redirecting list of files to background
processes. Thanks to PRESFIL.

Added %N macro to 'statusline' option, which adds a line break and
increases height of the status line. Thanks to Jose Riha (a.k.a.
jose1711), qsmodo and jcarreja.

Made :VifmCs of the plugin fail when 'termguicolors' produces a 24-bit color
value. Thanks to AtomToast.

Expand Down Expand Up @@ -145,6 +149,8 @@
Fixed permission dialog on *nix systems not showing all information
correctly after a redraw.

Fixed incorrect colors on redrawing wild menu popup on terminal resize.

0.11-beta to 0.11 (2020-09-24)

Recommend against setting 'shellcmdflag' to "-ic" value.
Expand Down
2 changes: 2 additions & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ j-xella
Jakob Helmecke
Jason Dreisbach (a.k.a. jtdreisb)
Jason W. Ryan
jcarreja
Jeet Sukumaran (jeetsukumaran)
Jeffrey C. Albro (jalbro)
Jing Liu
Expand Down Expand Up @@ -189,6 +190,7 @@ Pierre Dorbais (chdorb)
piotryordanov
PRESFIL
qinghao (haobug)
qsmodo
r0ck
r44083
rafasc
Expand Down
7 changes: 5 additions & 2 deletions data/man/vifm.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH VIFM 1 "April 30, 2021" "vifm 0.11"
.TH VIFM 1 "May 13, 2021" "vifm 0.11"
.\" ---------------------------------------------------------------------------
.SH NAME
.\" ---------------------------------------------------------------------------
Expand Down Expand Up @@ -3317,7 +3317,7 @@ Execute command in horizontally split window of active terminal multiplexer
Same as %s, but splits vertically.
.TP
.BI %n
Forbid using of terminal multiplexer to run the command.
Forbid use of terminal multiplexer to run the command.
.TP
.BI %i
Completely ignore command output. For background jobs this suppresses error
Expand Down Expand Up @@ -4687,6 +4687,9 @@ Empty string means use same format like in previous versions. Following macros
are supported:
.RS
.IP \- 2
%N \- line break (increases height of the status line accordingly), ignores
%[ %] blocks
.IP \- 2
%t \- file name (considering value of the 'classify' option)
.IP \- 2
%T - symbolic link target (empty for other filetypes)
Expand Down
6 changes: 4 additions & 2 deletions data/vim/doc/app/vifm-app.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*vifm-app.txt* For Vifm version 0.11 Last change: 2021 Apr 30
*vifm-app.txt* For Vifm version 0.11 Last change: 2021 Mar 13

Email for bugs and suggestions: <xaizek@posteo.net>

Expand Down Expand Up @@ -2732,7 +2732,7 @@ The command macros may be used in user commands.
*vifm-%v*
%v same as %s, but splits vertically.
*vifm-%n*
%n forbid using of terminal multiplexer to run the command.
%n forbid use of terminal multiplexer to run the command.
*vifm-%i*
%i completely ignore command output. For background jobs this
suppresses error dialogs, while still storing errors
Expand Down Expand Up @@ -3935,6 +3935,8 @@ default: ""
Determines the content of the status line (the line right above command-line).
Empty string means use same format like in previous versions. Following macros
are supported:
%N - line break (increases height of the status line accordingly), ignores
%[ %] blocks
%t - file name (considering value of the |vifm-'classify'| option)
%T - symbolic link target (empty for other filetypes)
%f - file name relative to current directory (considers 'classify')
Expand Down
2 changes: 1 addition & 1 deletion src/cfg/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ typedef struct config_t
* sizes. */
int flexible_splitter;

/* Whether statusline is visible. */
/* Whether displaying status line is enabled. */
int display_statusline;

/* Per line pattern for borders. */
Expand Down
125 changes: 83 additions & 42 deletions src/modes/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,41 @@ PromptState;
/* Holds state of the command-line editing mode. */
typedef struct
{
wchar_t *line; /* the line reading */
wchar_t *initial_line; /* initial state of the line */
int index; /* index of the current character in cmdline */
int curs_pos; /* position of the cursor in status bar*/
int len; /* length of the string */
int cmd_pos; /* position in the history */
wchar_t prompt[NAME_MAX + 1]; /* prompt */
int prompt_wid; /* width of prompt */
int complete_continue; /* if non-zero, continue previous completion */
int dot_pos; /* history pos for dot completion, or < 0 */
size_t dot_index; /* dot completion line index */
size_t dot_len; /* dot completion previous completion len */
HIST history_search; /* HIST_* */
int hist_search_len; /* length of history search pattern */
wchar_t *line_buf; /* content of line before using history */
int reverse_completion;
complete_cmd_func complete;
int search_mode;
int old_top; /* for search_mode */
int old_pos; /* for search_mode */
int line_edited; /* Cache for whether input line changed flag. */
int enter_mapping_state; /* The mapping state at entering the mode. */
int expanding_abbrev; /* Abbreviation expansion is in progress. */
PromptState state; /* Prompt state with regard to current input. */
/* Line editing state. */
wchar_t *line; /* The line reading. */
wchar_t *initial_line; /* Initial state of the line. */
int index; /* Index of the current character in cmdline. */
int curs_pos; /* Position of the cursor in status bar. */
int len; /* Length of the string. */
int cmd_pos; /* Position in the history. */
wchar_t prompt[NAME_MAX + 1]; /* Prompt message. */
int prompt_wid; /* Width of the prompt. */

/* Dot completion. */
int dot_pos; /* History position or < 0 if it's not active. */
size_t dot_index; /* Line index. */
size_t dot_len; /* Previous completion length. */

/* Command completion. */
int complete_continue; /* If non-zero, continue previous completion. */
int reverse_completion; /* Completion in the opposite direction. */
complete_cmd_func complete; /* Completion function. */

/* History completion. */
HIST history_search; /* One of the HIST_* constants. */
int hist_search_len; /* Length of history search pattern. */
wchar_t *line_buf; /* Content of line before using history. */

/* For search prompt. */
int search_mode; /* If it's a search prompt. */
int old_top; /* Saved top for interactive searching. */
int old_pos; /* Saved position for interactive searching. */

/* Other state. */
int line_edited; /* Cache for whether input line changed flag. */
int enter_mapping_state; /* The mapping state at entering the mode. */
int expanding_abbrev; /* Abbreviation expansion is in progress. */
PromptState state; /* Prompt state with regard to current input. */
}
line_stats_t;

Expand Down Expand Up @@ -158,6 +169,7 @@ static void do_completion(void);
static void draw_wild_menu(int op);
static int draw_wild_bar(int *last_pos, int *pos, int *len);
static int draw_wild_popup(int *last_pos, int *pos, int *len);
static int compute_wild_menu_height(void);
static void cmd_ctrl_k(key_info_t key_info, keys_info_t *keys_info);
static void cmd_return(key_info_t key_info, keys_info_t *keys_info);
static int is_input_line_empty(void);
Expand Down Expand Up @@ -670,7 +682,7 @@ modcline_redraw(void)
}
else
{
update_screen(UT_REDRAW);
ui_redraw_as_background();
if(prev_mode == SORT_MODE)
{
redraw_sort_dialog();
Expand All @@ -690,6 +702,11 @@ modcline_redraw(void)
{
draw_wild_menu(-1);
}

if(prev_mode != MENU_MODE)
{
update_all_windows();
}
}

/* Performs all necessary preparations for command-line mode to start
Expand Down Expand Up @@ -1072,6 +1089,16 @@ do_completion(void)

update_cmdline_size();
update_cmdline_text(&input_stat);

/* Indicate that status line is being reused for wild menu and there is a
* potential usage conflict due to size differences. */
if(cfg.display_statusline && !curr_stats.reusing_statusline &&
cfg.wild_menu && vle_compl_get_count() > 2 && getmaxy(stat_win) > 1)
{
curr_stats.reusing_statusline = 1;
wresize(stat_win, compute_wild_menu_height(), getmaxx(stdscr));
modcline_redraw();
}
}

/*
Expand Down Expand Up @@ -1133,8 +1160,10 @@ draw_wild_bar(int *last_pos, int *pos, int *len)
const vle_compl_t *const items = vle_compl_get_items();
const int count = vle_compl_get_count() - 1;

wresize(stat_win, compute_wild_menu_height(), getmaxx(stdscr));
checked_wmove(stat_win, 0, 0);
werase(stat_win);
ui_stat_reposition(getmaxy(status_bar), 1);

if(*pos < *last_pos)
{
Expand Down Expand Up @@ -1194,9 +1223,7 @@ draw_wild_popup(int *last_pos, int *pos, int *len)
{
const vle_compl_t *const items = vle_compl_get_items();
const int count = vle_compl_get_count() - 1;
const int max_height = getmaxy(stdscr) - getmaxy(status_bar)
- ui_stat_job_bar_height() - 1;
const int height = MIN(count, MIN(10, max_height));
const int height = compute_wild_menu_height();
size_t max_title_width;
int i, j;

Expand All @@ -1205,9 +1232,11 @@ draw_wild_popup(int *last_pos, int *pos, int *len)
*last_pos = MAX(0, *last_pos - height);
}

ui_stat_reposition(getmaxy(status_bar), height);
wresize(stat_win, height, getmaxx(stdscr));
ui_set_attr(stat_win, &cfg.cs.color[STATUS_LINE_COLOR],
cfg.cs.pair[STATUS_LINE_COLOR]);
werase(stat_win);
ui_stat_reposition(getmaxy(status_bar), 1);

max_title_width = 0U;
for(i = *last_pos, j = 0; i < count && j < height; ++i, ++j)
Expand Down Expand Up @@ -1243,6 +1272,21 @@ draw_wild_popup(int *last_pos, int *pos, int *len)
return i;
}

/* Computes height needed for wild menu (bar or popup). Returns the height. */
static int
compute_wild_menu_height(void)
{
if(!cfg.wild_popup)
{
return 1;
}

const int count = vle_compl_get_count() - 1;
const int max_height = getmaxy(stdscr) - getmaxy(status_bar)
- ui_stat_job_bar_height() - 1;
return MIN(count, MIN(10, max_height));
}

static void
cmd_ctrl_k(key_info_t key_info, keys_info_t *keys_info)
{
Expand Down Expand Up @@ -2472,8 +2516,10 @@ update_cmdline_size(void)

if(prev_mode != MENU_MODE)
{
if(ui_stat_reposition(required_height,
cfg.wild_menu && cfg.wild_popup && input_stat.complete_continue))
int stat_height = cfg.wild_menu
&& cfg.wild_popup
&& input_stat.complete_continue;
if(ui_stat_reposition(required_height, stat_height ? getmaxy(stat_win) : 0))
{
ui_stat_refresh();
}
Expand Down Expand Up @@ -2654,21 +2700,16 @@ stop_regular_completion(void)
return;
}

if(curr_stats.reusing_statusline)
{
curr_stats.reusing_statusline = 0;
}

input_stat.complete_continue = 0;
vle_compl_reset();
if(cfg.wild_menu && input_stat.complete != NULL)
{
if(sub_mode == CLS_MENU_COMMAND)
{
modmenu_full_redraw();
}
else
{
update_screen(UT_REDRAW);
}
update_cmdline_size();
update_cmdline_text(&input_stat);
curs_set(1);
modcline_redraw();
}
}

Expand Down
59 changes: 35 additions & 24 deletions src/modes/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,41 @@ PromptState;
/* Holds state of the command-line editing mode. */
typedef struct
{
wchar_t *line; /* the line reading */
wchar_t *initial_line; /* initial state of the line */
int index; /* index of the current character */
int curs_pos; /* position of the cursor */
int len; /* length of the string */
int cmd_pos; /* position in the history */
wchar_t prompt[NAME_MAX + 1]; /* prompt */
int prompt_wid; /* width of prompt */
int complete_continue; /* if non-zero, continue previous completion */
int dot_pos; /* history pos for dot completion, or < 0 */
size_t dot_index; /* dot completion line index */
size_t dot_len; /* dot completion previous completion len */
HIST history_search; /* HIST_* */
int hist_search_len; /* length of history search pattern */
wchar_t *line_buf; /* content of line before using history */
int reverse_completion;
complete_cmd_func complete;
int search_mode;
int old_top; /* for search_mode */
int old_pos; /* for search_mode */
int line_edited; /* Cache for whether input line changed flag. */
int enter_mapping_state; /* The mapping state at entering the mode. */
int expanding_abbrev; /* Abbreviation expansion is in progress. */
PromptState state; /* Prompt state with regard to current input. */
/* Line editing state. */
wchar_t *line; /* The line reading. */
wchar_t *initial_line; /* Initial state of the line. */
int index; /* Index of the current character in cmdline. */
int curs_pos; /* Position of the cursor in status bar. */
int len; /* Length of the string. */
int cmd_pos; /* Position in the history. */
wchar_t prompt[NAME_MAX + 1]; /* Prompt message. */
int prompt_wid; /* Width of the prompt. */

/* Dot completion. */
int dot_pos; /* History position or < 0 if it's not active. */
size_t dot_index; /* Line index. */
size_t dot_len; /* Previous completion length. */

/* Command completion. */
int complete_continue; /* If non-zero, continue previous completion. */
int reverse_completion; /* Completion in the opposite direction. */
complete_cmd_func complete; /* Completion function. */

/* History completion. */
HIST history_search; /* One of the HIST_* constants. */
int hist_search_len; /* Length of history search pattern. */
wchar_t *line_buf; /* Content of line before using history. */

/* For search prompt. */
int search_mode; /* If it's a search prompt. */
int old_top; /* Saved top for interactive searching. */
int old_pos; /* Saved position for interactive searching. */

/* Other state. */
int line_edited; /* Cache for whether input line changed flag. */
int enter_mapping_state; /* The mapping state at entering the mode. */
int expanding_abbrev; /* Abbreviation expansion is in progress. */
PromptState state; /* Prompt state with regard to current input. */
}
line_stats_t;
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/modes/dialogs/msg_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "../../engine/keys.h"
#include "../../engine/mode.h"
#include "../../modes/modes.h"
#include "../../ui/statusline.h"
#include "../../ui/ui.h"
#include "../../utils/macros.h"
#include "../../utils/str.h"
Expand Down Expand Up @@ -508,7 +509,7 @@ draw_msg(const char title[], const char msg[], const char ctrl_msg[],

ctrl_msg_n = MAX(measure_sub_lines(ctrl_msg, &wctrl_msg), 1U);

max_h = sh - 2 - ctrl_msg_n + !cfg.display_statusline;
max_h = sh - 2 - ctrl_msg_n - ui_stat_height();
h = max_h;
/* The outermost condition is for VLA below (to calm static analyzers). */
w = MAX(2 + 2*margin, MIN(sw - 2,
Expand Down
1 change: 1 addition & 0 deletions src/opt_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,7 @@ static void
statusline_handler(OPT_OP op, optval_t val)
{
(void)replace_string(&cfg.status_line, val.str_val);
stats_redraw_later();
}

/* Sets when to display key suggestions. */
Expand Down

0 comments on commit cfb79fc

Please sign in to comment.