src/nvim/screen.c
/*
 * Draw the tab pages line at the top of the Vim window.
 */
Draw the tab pages line at the top of the Vim window.
Draw the tab pages line at the top of the Vim window .
void draw_tabline(void)
{
  int tabcount = 0;
  int tabwidth = 0;
  int col = 0;
  int scol = 0;
  int attr;
  win_T       *wp;
  win_T       *cwp;
  int wincount;
  int modified;
  int c;
  int len;
  int attr_nosel = HL_ATTR(HLF_TP);
  int attr_fill = HL_ATTR(HLF_TPF);
  char_u      *p;
  int room;
  int use_sep_chars = (t_colors < 8
                       );
  if (default_grid.chars == NULL) {
    return;
  }
  redraw_tabline = false;
  if (ui_has(kUITabline)) {
    ui_ext_tabline_update();
    return;
  }
  if (tabline_height() < 1)
    return;
  assert(Columns == tab_page_click_defs_size);
  clear_tab_page_click_defs(tab_page_click_defs, tab_page_click_defs_size);
  if (*p_tal != NUL) {
    int saved_did_emsg = did_emsg;
    did_emsg = false;
    win_redr_custom(NULL, false);
    if (did_emsg) {
      set_string_option_direct((char_u *)"tabline", -1,
                               (char_u *)"", OPT_FREE, SID_ERROR);
    }
    did_emsg |= saved_did_emsg;
  } else {
    FOR_ALL_TABS(tp) {
      ++tabcount;
    }
    if (tabcount > 0) {
      tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
    }
    if (tabwidth < 6) {
      tabwidth = 6;
    }
    attr = attr_nosel;
    tabcount = 0;
    FOR_ALL_TABS(tp) {
      if (col >= Columns - 4) {
        break;
      }
      scol = col;
      if (tp == curtab) {
        cwp = curwin;
        wp = firstwin;
      } else {
        cwp = tp->tp_curwin;
        wp = tp->tp_firstwin;
      }
      if (tp->tp_topframe == topframe) {
        attr = win_hl_attr(cwp, HLF_TPS);
      }
      if (use_sep_chars && col > 0) {
        grid_putchar(&default_grid, '|', 0, col++, attr);
      }
      if (tp->tp_topframe != topframe) {
        attr = win_hl_attr(cwp, HLF_TP);
      }
      grid_putchar(&default_grid, ' ', 0, col++, attr);
      modified = false;
      for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) {
        if (bufIsChanged(wp->w_buffer)) {
          modified = true;
        }
      }
      if (modified || wincount > 1) {
        if (wincount > 1) {
          vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount);
          len = (int)STRLEN(NameBuff);
          if (col + len >= Columns - 3) {
            break;
          }
          grid_puts_len(&default_grid, NameBuff, len, 0, col,
                        hl_combine_attr(attr, win_hl_attr(cwp, HLF_T)));
          col += len;
        }
        if (modified) {
          grid_puts_len(&default_grid, (char_u *)"+", 1, 0, col++, attr);
        }
        grid_putchar(&default_grid, ' ', 0, col++, attr);
      }
      room = scol - col + tabwidth - 1;
      if (room > 0) {
        get_trans_bufname(cwp->w_buffer);
        (void)shorten_dir(NameBuff);
        len = vim_strsize(NameBuff);
        p = NameBuff;
        while (len > room) {
          len -= ptr2cells(p);
          MB_PTR_ADV(p);
        }
        if (len > Columns - col - 1) {
          len = Columns - col - 1;
        }
        grid_puts_len(&default_grid, p, (int)STRLEN(p), 0, col, attr);
        col += len;
      }
      grid_putchar(&default_grid, ' ', 0, col++, attr);
      tabcount++;
      while (scol < col) {
        tab_page_click_defs[scol++] = (StlClickDefinition) {
          .type = kStlClickTabSwitch,
          .tabnr = tabcount,
          .func = NULL,
        };
      }
    }
    if (use_sep_chars)
      c = '_';
    else
      c = ' ';
    grid_fill(&default_grid, 0, 1, col, Columns, c, c, attr_fill);
    if (first_tabpage->tp_next != NULL) {
      grid_putchar(&default_grid, 'X', 0, Columns - 1, attr_nosel);
      tab_page_click_defs[Columns - 1] = (StlClickDefinition) {
        .type = kStlClickTabClose,
        .tabnr = 999,
        .func = NULL,
      };
    }
  }
  redraw_tabline = FALSE;
}
void draw_tabline ( void ) { int tabcount = 0 ; int tabwidth = 0 ; int col = 0 ; int scol = 0 ; int attr ; win_T * wp ; win_T * cwp ; int wincount ; int modified ; int c ; int len ; int attr_nosel = HL_ATTR ( HLF_TP ) ; int attr_fill = HL_ATTR ( HLF_TPF ) ; char_u * p ; int room ; int use_sep_chars = ( t_colors < 8 ) ; if ( default_grid . chars == NULL ) { return ; } redraw_tabline = false ; if ( ui_has ( kUITabline ) ) { ui_ext_tabline_update ( ) ; return ; } if ( tabline_height ( ) < 1 ) return ; assert ( Columns == tab_page_click_defs_size ) ; clear_tab_page_click_defs ( tab_page_click_defs , tab_page_click_defs_size ) ; if ( * p_tal != NUL ) { int saved_did_emsg = did_emsg ; did_emsg = false ; win_redr_custom ( NULL , false ) ; if ( did_emsg ) { set_string_option_direct ( ( char_u * ) " " , -1 , ( char_u * ) " " , OPT_FREE , SID_ERROR ) ; } did_emsg |= saved_did_emsg ; } else { FOR_ALL_TABS ( tp ) { ++ tabcount ; } if ( tabcount > 0 ) { tabwidth = ( Columns - 1 + tabcount / 2 ) / tabcount ; } if ( tabwidth < 6 ) { tabwidth = 6 ; } attr = attr_nosel ; tabcount = 0 ; FOR_ALL_TABS ( tp ) { if ( col >= Columns - 4 ) { break ; } scol = col ; if ( tp == curtab ) { cwp = curwin ; wp = firstwin ; } else { cwp = tp -> tp_curwin ; wp = tp -> tp_firstwin ; } if ( tp -> tp_topframe == topframe ) { attr = win_hl_attr ( cwp , HLF_TPS ) ; } if ( use_sep_chars && col > 0 ) { grid_putchar ( & default_grid , ' ' , 0 , col ++ , attr ) ; } if ( tp -> tp_topframe != topframe ) { attr = win_hl_attr ( cwp , HLF_TP ) ; } grid_putchar ( & default_grid , ' ' , 0 , col ++ , attr ) ; modified = false ; for ( wincount = 0 ; wp != NULL ; wp = wp -> w_next , ++ wincount ) { if ( bufIsChanged ( wp -> w_buffer ) ) { modified = true ; } } if ( modified || wincount > 1 ) { if ( wincount > 1 ) { vim_snprintf ( ( char * ) NameBuff , MAXPATHL , " " , wincount ) ; len = ( int ) STRLEN ( NameBuff ) ; if ( col + len >= Columns - 3 ) { break ; } grid_puts_len ( & default_grid , NameBuff , len , 0 , col , hl_combine_attr ( attr , win_hl_attr ( cwp , HLF_T ) ) ) ; col += len ; } if ( modified ) { grid_puts_len ( & default_grid , ( char_u * ) " " , 1 , 0 , col ++ , attr ) ; } grid_putchar ( & default_grid , ' ' , 0 , col ++ , attr ) ; } room = scol - col + tabwidth - 1 ; if ( room > 0 ) { get_trans_bufname ( cwp -> w_buffer ) ; ( void ) shorten_dir ( NameBuff ) ; len = vim_strsize ( NameBuff ) ; p = NameBuff ; while ( len > room ) { len -= ptr2cells ( p ) ; MB_PTR_ADV ( p ) ; } if ( len > Columns - col - 1 ) { len = Columns - col - 1 ; } grid_puts_len ( & default_grid , p , ( int ) STRLEN ( p ) , 0 , col , attr ) ; col += len ; } grid_putchar ( & default_grid , ' ' , 0 , col ++ , attr ) ; tabcount ++ ; while ( scol < col ) { tab_page_click_defs [ scol ++ ] = ( StlClickDefinition ) { . type = kStlClickTabSwitch , . tabnr = tabcount , . func = NULL , } ; } } if ( use_sep_chars ) c = ' ' ; else c = ' ' ; grid_fill ( & default_grid , 0 , 1 , col , Columns , c , c , attr_fill ) ; if ( first_tabpage -> tp_next != NULL ) { grid_putchar ( & default_grid , ' ' , 0 , Columns - 1 , attr_nosel ) ; tab_page_click_defs [ Columns - 1 ] = ( StlClickDefinition ) { . type = kStlClickTabClose , . tabnr = 999 , . func = NULL , } ; } } redraw_tabline = FALSE ; }
Draw the tab pages line at the top of the Vim window.
Draw the tab pages line at the top of the Vim window .
// Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. /* Use the 'tabline' option if it's set. */ // Check for an error.  If there is one we would loop in redrawing the // screen.  Avoid that by making 'tabline' empty. /* Get buffer name in NameBuff[] */ // Store the tab page number in tab_page_click_defs[], so that // jump_to_mouse() knows where each one is. /* Put an "X" for closing the current tab if there are several. */ /* Reset the flag here again, in case evaluating 'tabline' causes it to be
   * set. */