Repository: neovim/neovim
File: test/functional/ui/statusline_spec.lua (Lua)

Code before:
      {1:~                                       }|*5
      {101:B:[No Name]                             }|
                                              |
    ]])
  end)
end)

describe('default statusline', function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new(60, 16)
    screen:add_extra_attr_ids {
      [100] = { foreground = Screen.colors.Magenta1, bold = true },
    }
    command('set laststatus=2')
    command('set ruler')
  end)

  it('setting statusline to empty string sets default statusline', function()
    exec_lua("vim.o.statusline = 'asdf'")
    eq('asdf', eval('&statusline'))

    local default_statusline =
      "%<%f %h%w%m%r %=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &busy ? '<busy> ' : '' %}%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}"

    exec_lua("vim.o.statusline = ''")

    eq(default_statusline, eval('&statusline'))

    screen:expect([[
      ^                                                            |
      {1:~                                                           }|*13
      {3:[No Name]                                 0,0-1          All}|
                                                                  |
    ]])
  end)

  it('shows busy status when buffer is set to be busy', function()
    exec_lua("vim.o.statusline = ''")

    screen:expect([[
      ^                                                            |
      {1:~                                                           }|*13
      {3:[No Name]                                 0,0-1          All}|
                                                                  |
    ]])
    exec_lua('vim.o.busy = true')
    screen:expect([[
      ^                                                            |

Review comment (suggestion):
Followup: likely want an animated way, something like `vim.ui.spinner()` which generates an animation frame each time it is called, using chars like `⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏`.

Code after:
      {1:~                                       }|*5
      {101:B:[No Name]                             }|
                                              |
    ]])
  end)
end)

describe('default statusline', function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new(60, 16)
    screen:add_extra_attr_ids {
      [100] = { foreground = Screen.colors.Magenta1, bold = true },
    }
    command('set laststatus=2')
    command('set ruler')
  end)

  it('setting statusline to empty string sets default statusline', function()
    exec_lua("vim.o.statusline = 'asdf'")
    eq('asdf', eval('&statusline'))

    local default_statusline = table.concat({
      '%<',
      '%f %h%w%m%r ',
      '%=',
      "%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}",
      "%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}",
      "%{% &busy > 0 ? '◐ ' : '' %}",
      "%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
    })

    exec_lua("vim.o.statusline = ''")

    eq(default_statusline, eval('&statusline'))

    screen:expect([[
      ^                                                            |
      {1:~                                                           }|*13
      {3:[No Name]                                 0,0-1          All}|
                                                                  |
    ]])
  end)

  it('shows busy status when buffer is set to be busy', function()
    exec_lua("vim.o.statusline = ''")

    screen:expect([[
      ^                                                            |