src/nvim/screen.c
// Show the current mode and ruler.
//
// If clear_cmdline is TRUE, clear the rest of the cmdline.
// If clear_cmdline is FALSE there may be a message there that needs to be
// cleared only if a mode is shown.
// Return the length of the message (0 if no message).
Show the current mode and ruler.
If clear_cmdline is TRUE, clear the rest of the cmdline.
If clear_cmdline is FALSE there may be a message there that needs to be
cleared only if a mode is shown.
Return the length of the message (0 if no message).
Show the current mode and ruler . If clear_cmdline is TRUE clear the rest of the cmdline . If clear_cmdline is FALSE there may be a message there that needs to be cleared only if a mode is shown . Return the length of the message ( 0 if no message ) .
int showmode(void)
{
  int need_clear;
  int length = 0;
  int do_mode;
  int attr;
  int nwr_save;
  int sub_attr;
  if (ui_has(kUIMessages) && clear_cmdline) {
    msg_ext_clear(true);
  }
  msg_ext_ui_flush();
  msg_grid_validate();
  do_mode = ((p_smd && msg_silent == 0)
             && ((State & TERM_FOCUS)
                 || (State & INSERT)
                 || restart_edit
                 || VIsual_active));
  if (do_mode || reg_recording != 0) {
    if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) {
      redraw_cmdline = TRUE;                    
      return 0;
    }
    nwr_save = need_wait_return;
    check_for_delay(FALSE);
    need_clear = clear_cmdline;
    if (clear_cmdline && cmdline_row < Rows - 1) {
      msg_clr_cmdline();  
    }
    msg_pos_mode();
    attr = HL_ATTR(HLF_CM);                     
    msg_no_more = true;
    int save_lines_left = lines_left;
    lines_left = 0;
    if (do_mode) {
      MSG_PUTS_ATTR("--", attr);
      if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) {
        if (ui_has(kUIMessages)) {
          length = INT_MAX;
        } else {
          length = (Rows - msg_row) * Columns - 3;
        }
        if (edit_submode_extra != NULL) {
          length -= vim_strsize(edit_submode_extra);
        }
        if (length > 0) {
          if (edit_submode_pre != NULL)
            length -= vim_strsize(edit_submode_pre);
          if (length - vim_strsize(edit_submode) > 0) {
            if (edit_submode_pre != NULL) {
              msg_puts_attr((const char *)edit_submode_pre, attr);
            }
            msg_puts_attr((const char *)edit_submode, attr);
          }
          if (edit_submode_extra != NULL) {
            MSG_PUTS_ATTR(" ", attr);  
            if ((int)edit_submode_highl < (int)HLF_COUNT) {
              sub_attr = win_hl_attr(curwin, edit_submode_highl);
            } else {
              sub_attr = attr;
            }
            msg_puts_attr((const char *)edit_submode_extra, sub_attr);
          }
        }
      } else {
        if (State & TERM_FOCUS) {
          MSG_PUTS_ATTR(_(" TERMINAL"), attr);
        } else if (State & VREPLACE_FLAG)
          MSG_PUTS_ATTR(_(" VREPLACE"), attr);
        else if (State & REPLACE_FLAG)
          MSG_PUTS_ATTR(_(" REPLACE"), attr);
        else if (State & INSERT) {
          if (p_ri)
            MSG_PUTS_ATTR(_(" REVERSE"), attr);
          MSG_PUTS_ATTR(_(" INSERT"), attr);
        } else if (restart_edit == 'I' || restart_edit == 'i'
                   || restart_edit == 'a') {
          MSG_PUTS_ATTR(_(" (insert)"), attr);
        } else if (restart_edit == 'R') {
          MSG_PUTS_ATTR(_(" (replace)"), attr);
        } else if (restart_edit == 'V') {
          MSG_PUTS_ATTR(_(" (vreplace)"), attr);
        }
        if (p_hkmap) {
          MSG_PUTS_ATTR(_(" Hebrew"), attr);
        }
        if (State & LANGMAP) {
          if (curwin->w_p_arab) {
            MSG_PUTS_ATTR(_(" Arabic"), attr);
          } else if (get_keymap_str(curwin, (char_u *)" (%s)",
                                    NameBuff, MAXPATHL)) {
            MSG_PUTS_ATTR(NameBuff, attr);
          }
        }
        if ((State & INSERT) && p_paste)
          MSG_PUTS_ATTR(_(" (paste)"), attr);
        if (VIsual_active) {
          char *p;
          switch ((VIsual_select ? 4 : 0)
                  + (VIsual_mode == Ctrl_V) * 2
                  + (VIsual_mode == 'V')) {
          case 0: p = N_(" VISUAL"); break;
          case 1: p = N_(" VISUAL LINE"); break;
          case 2: p = N_(" VISUAL BLOCK"); break;
          case 4: p = N_(" SELECT"); break;
          case 5: p = N_(" SELECT LINE"); break;
          default: p = N_(" SELECT BLOCK"); break;
          }
          MSG_PUTS_ATTR(_(p), attr);
        }
        MSG_PUTS_ATTR(" --", attr);
      }
      need_clear = TRUE;
    }
    if (reg_recording != 0
        && edit_submode == NULL             
        ) {
      recording_mode(attr);
      need_clear = true;
    }
    mode_displayed = TRUE;
    if (need_clear || clear_cmdline)
      msg_clr_eos();
    msg_didout = FALSE;                 
    length = msg_col;
    msg_col = 0;
    msg_no_more = false;
    lines_left = save_lines_left;
    need_wait_return = nwr_save;        
  } else if (clear_cmdline && msg_silent == 0) {
    msg_clr_cmdline();
  }
  msg_ext_flush_showmode();
  if (VIsual_active)
    clear_showcmd();
  win_T *last = lastwin_nofloating();
  if (redrawing() && last->w_status_height == 0) {
    win_redr_ruler(last, true);
  }
  redraw_cmdline = false;
  clear_cmdline = false;
  return length;
}
int showmode ( void ) { int need_clear ; int length = 0 ; int do_mode ; int attr ; int nwr_save ; int sub_attr ; if ( ui_has ( kUIMessages ) && clear_cmdline ) { msg_ext_clear ( true ) ; } msg_ext_ui_flush ( ) ; msg_grid_validate ( ) ; do_mode = ( ( p_smd && msg_silent == 0 ) && ( ( State & TERM_FOCUS ) || ( State & INSERT ) || restart_edit || VIsual_active ) ) ; if ( do_mode || reg_recording != 0 ) { if ( ! redrawing ( ) || ( char_avail ( ) && ! KeyTyped ) || msg_silent != 0 ) { redraw_cmdline = TRUE ; return 0 ; } nwr_save = need_wait_return ; check_for_delay ( FALSE ) ; need_clear = clear_cmdline ; if ( clear_cmdline && cmdline_row < Rows - 1 ) { msg_clr_cmdline ( ) ; } msg_pos_mode ( ) ; attr = HL_ATTR ( HLF_CM ) ; msg_no_more = true ; int save_lines_left = lines_left ; lines_left = 0 ; if ( do_mode ) { MSG_PUTS_ATTR ( " " , attr ) ; if ( edit_submode != NULL && ! shortmess ( SHM_COMPLETIONMENU ) ) { if ( ui_has ( kUIMessages ) ) { length = INT_MAX ; } else { length = ( Rows - msg_row ) * Columns - 3 ; } if ( edit_submode_extra != NULL ) { length -= vim_strsize ( edit_submode_extra ) ; } if ( length > 0 ) { if ( edit_submode_pre != NULL ) length -= vim_strsize ( edit_submode_pre ) ; if ( length - vim_strsize ( edit_submode ) > 0 ) { if ( edit_submode_pre != NULL ) { msg_puts_attr ( ( const char * ) edit_submode_pre , attr ) ; } msg_puts_attr ( ( const char * ) edit_submode , attr ) ; } if ( edit_submode_extra != NULL ) { MSG_PUTS_ATTR ( " " , attr ) ; if ( ( int ) edit_submode_highl < ( int ) HLF_COUNT ) { sub_attr = win_hl_attr ( curwin , edit_submode_highl ) ; } else { sub_attr = attr ; } msg_puts_attr ( ( const char * ) edit_submode_extra , sub_attr ) ; } } } else { if ( State & TERM_FOCUS ) { MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } else if ( State & VREPLACE_FLAG ) MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; else if ( State & REPLACE_FLAG ) MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; else if ( State & INSERT ) { if ( p_ri ) MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } else if ( restart_edit == ' ' || restart_edit == ' ' || restart_edit == ' ' ) { MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } else if ( restart_edit == ' ' ) { MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } else if ( restart_edit == ' ' ) { MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } if ( p_hkmap ) { MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } if ( State & LANGMAP ) { if ( curwin -> w_p_arab ) { MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; } else if ( get_keymap_str ( curwin , ( char_u * ) " " , NameBuff , MAXPATHL ) ) { MSG_PUTS_ATTR ( NameBuff , attr ) ; } } if ( ( State & INSERT ) && p_paste ) MSG_PUTS_ATTR ( _ ( " " ) , attr ) ; if ( VIsual_active ) { char * p ; switch ( ( VIsual_select ? 4 : 0 ) + ( VIsual_mode == Ctrl_V ) * 2 + ( VIsual_mode == ' ' ) ) { case 0 : p = N_ ( " " ) ; break ; case 1 : p = N_ ( " " ) ; break ; case 2 : p = N_ ( " " ) ; break ; case 4 : p = N_ ( " " ) ; break ; case 5 : p = N_ ( " " ) ; break ; default : p = N_ ( " " ) ; break ; } MSG_PUTS_ATTR ( _ ( p ) , attr ) ; } MSG_PUTS_ATTR ( " " , attr ) ; } need_clear = TRUE ; } if ( reg_recording != 0 && edit_submode == NULL ) { recording_mode ( attr ) ; need_clear = true ; } mode_displayed = TRUE ; if ( need_clear || clear_cmdline ) msg_clr_eos ( ) ; msg_didout = FALSE ; length = msg_col ; msg_col = 0 ; msg_no_more = false ; lines_left = save_lines_left ; need_wait_return = nwr_save ; } else if ( clear_cmdline && msg_silent == 0 ) { msg_clr_cmdline ( ) ; } msg_ext_flush_showmode ( ) ; if ( VIsual_active ) clear_showcmd ( ) ; win_T * last = lastwin_nofloating ( ) ; if ( redrawing ( ) && last -> w_status_height == 0 ) { win_redr_ruler ( last , true ) ; } redraw_cmdline = false ; clear_cmdline = false ; return length ; }
Show the current mode and ruler.
Show the current mode and ruler .
// don't make non-flushed message part of the showmode // Don't show mode right now, when not redrawing or inside a mapping. // Call char_avail() only when we are going to show something, because // it takes a bit of time. /* show mode later */ /* wait a bit before overwriting an important message */ /* if the cmdline is more than one line high, erase top lines */ // will reset clear_cmdline /* Position on the last line in the window, column 0 */ // Highlight mode // When the screen is too narrow to show the entire mode messsage, // avoid scrolling and truncate instead. // CTRL-X in Insert mode // These messages can get long, avoid a wrap in a narrow window. // Prefer showing edit_submode_extra. With external messages there // is no imposed limit. // Add a space in between. /* Don't concatenate separate words to avoid translation
           * problems. */ // otherwise it gets too long /* overwrite this message */ // never ask for hit-return for this // Clear the whole command line.  Will reset "clear_cmdline". // NB: also handles clearing the showmode if it was emtpy or disabled /* In Visual mode the size of the selected area must be redrawn. */ // If the last window has no status line, the ruler is after the mode // message and must be redrawn