Skip to content

tar80/loose.nvim

Repository files navigation

logo

theme

Note

New theme veil available. It is designed for transparent backgrounds.

veil

Requirements

  • Neovim >= 0.10.0

Features

Loose has a function to output the palettes (theme) that matches the background color. Since the difference from the default background color is only increased or decreased, the colors do not always appear beautifully.

create_theme

You can choose between the light, dark, muted and faded templates. If user.lua exists in the loose/lua/loose/color directory, you can also select user in the template. If you need the user template, create one by copying another template. If the template has a colors.feline table, a Feline theme with the same name will also be output.

Warning

loose.colors() has been renamed to loose.get_colors()

---Create user color palette
---@param name string Palette name
---@param template string Template name "light"|"dark"|"muted"|"faded"|"user"
---@param bakground string Base background color "light"|"dark"
---@param rgb string Specify the background color in the format "#rrggbb"
require('loose.util').create_theme(name, template, background, rgb)

---Delete user color palettes
require('loose.util').delete_theme()

---Color settings reference
---@param name string Palette name
---@return `table` {[name: string]: hex color code: string}
local colors = require('loose').get_colors(name)

---Get all color codes
---@param name string Palette name
---@return `string[]` hex color codes
local palette = require('loose').get_palette(name)

Each color consists of four types: high, normal, low and shade, and eight colors: gray, blue, cyan, green, olive, orange, red, and purple. That is, they are represented as high_xxx, xxx, low_xxx, and shade_xxx.

Plugin Support

Loose comes with some preset plugin highlights. These are disabled by default but can be optionally enabled. In addition to the highlight settings built into the base onenord.nvim, the author's favorite plugins are also added.

and

  • tiny-devicons-auto-colors.nvim

    Click to see devicons override configuration
    local opts = {...} -- tiny-devicons-auto-colors options
    local ok, loose = pcall(require, 'loose')
    if ok then
      opts.colors = loose.get_palette()
      require('tiny-devicons-auto-colors').setup(opts)
    end

User_plugins

To enable user-specific hlgroup settings, place a <plugin_name>.lua file in the lua/loose/user_plugins/ directory and add the user_plugins table to the options. This allows you to customize hlgroups, whether by defining them for plugins that Loose doesn't provide by default, or by modifying the existing ones.

For example, to modify the hlgroup for lsp, first create and edit the file lua/loose/user_plugins/lsp.lua. Refer to the lua/loose/user_plugins/.template file for the writing format. Next, exclude lsp from the plugins table, and then add it to the user_plugins table.

opts = {
    plugins = { lsp = false },
    User_plugins = { lsp = true },
}

Important

Here's an example of what not to do:

opts = {
    plugins = { lsp = true },
    User_plugins = { lsp = true },
}

This configuration is not allowed and will result in an error. This is to maintain a clear and consistent configuration, preventing potential issues and making it easier to understand and manage highlight settings. Therefore, the user_plugins option must configure the hlgroup for the entire plugin; partial application is not possible.

Configuration

Note

  • Added enable_usercmd. This registers the command LooseSwitch
  • theme option has been deparecated. and split into light_theme and dark_theme
  • Added depricated into styles option
  • Added statusline,tabline,tabsel,tabfill into disable option
  • Added lsp_semantic into plugins option
  • Added global valiable g:loose_theme. The current theme name will be saved
  • Added option user_plugins available

Important

  • Colorscheme is no longer loaded during loose.setup(). Execute Colorscheme loose to load the colorscheme.
  • custom_highlights has been changed so that it can be set per background.
Click to see default configuration
require("loose").setup({
    enable_usercmd = false, -- Enable user command "LooseSwitch"
    background = "dark", -- Background color applied at strtup. "light"|"dark"
    @depricated theme = "dark", -- A palette name
    light_theme = "light", -- A light palette name
    dark_theme = "dark", -- A dark palette name
    borders = true, -- Enable split window borders
    fade_nc = false, -- Change the background color of other buffers
    fade_tr = false, -- Transparent background of current buffer while changing background color of other buffers
    -- "NONE"|"[bold][,underline][,italic][,...]"]
    styles = {
        comments = "NONE",
        depricated = "NONE",
        diagnostics = "undercurl",
        functions = "NONE",
        keywords = "NONE",
        references = "underline",
        spell = "undercurl",
        strings = "NONE",
        variables = "NONE",
        virtualtext = "NONE",
    },
    disable = {
        background = false, -- Remove background color and enable transparency (fade_xx is ignored)
        cursorline = false,
        eob_lines = false,
        statusline = false,
        tabline = false,
        tabsel = false,
        tabfill = false,
    },
    -- Override or add to default settings. See `nvim_set_hl()` for details.
    -- highlight_group = {fg = "white", bg = "black", style = "underline"}
    custom_highlights = {light = {}, dark = {}},
    plugins = {
        -- maintained
        lsp = true,
        lsp_semantic = true,
        treesitter = true,
        dap = false,
        dap_virtual_text = false,
        flash = false,
        fret = false,
        gitsigns = false,
        lazy = false,
        lspconfig = false, -- @deprecated: LspInfo has been updated. Hlgroup is no longer used
        matchwith = false,
        mini_icons = false,
        noice = false,
        rereope = false,
        skkeleton_indicator = false,
        sandwich = false,
        staba = false,
        cmp = false,
        telescope = false, -- If "border_fade" is specified, the border background fades
        trouble = false,
        -- non maintained
        barbar = false,
        bufferline = false,
        conflict_marker = false,
        dashboard = false,
        fern = false,
        fuzzy_motion = false,
        hop = false,
        indent_blankline = false,
        illuminate = false,
        lightspeed = false,
        lspsaga = false,
        mini_diff = false,
        navic = false
        notify = false,
        neogit = false,
        nvimtree = false,
        rainbow_delimiters_high = false, -- Rainbow Delimiters can choose one of
        rainbow_delimiters_low = false,  -- either high contrast or low contrast
        snacks = false,
        sneak = false,
        treesitter_context = false,
        whichkey = false,
    },
    -- User's own specified plugins highlight groups
    -- Set the plugin name and value in the same way as the "plugins" table
    -- You can also set a value other than nil or false and use it as a flag
    user_plugins = {},
})

Statusline

To use statusline color theme, do the following:

Click to see load palette configuration
local set_palette = function(_)
    -- loose saves the name of the current color theme in g:loose_theme
    local theme = vim.g.loose_theme or vim.go.background
    palette = loose.get_colors(theme)
    local feline = require(('feline.themes.%s'):format(theme))
    palette = vim.tbl_deep_extend('force', palette, feline)

    -- local staline = require(('staline.themes.%s'):format(theme))
    -- palette = vim.tbl_deep_extend('force', palette, staline)
end

local palette = {}
local ok, loose = pcall(require, 'loose')

if ok then
    set_palette()

    local augroup = vim.api.nvim_create_augroup('loose', { clear = true })
    vim.api.nvim_create_autocmd('ColorScheme', {
    desc = 'Load color palette',
    group = augroup,
    callback = set_palette
    })
end

-- feline
require("feline").setup({
  theme = palette.theme,
  vi_mode_colors = palette.vi_mode,
})

-- staline
require('staline').setup({
  mode_colors = palette.vi_mod,
})

Please refer to the file in staline/themes or feline/themes for available colors.

Command

LooseSwitch [theme_name]

This command is registered when the option enable_usercmd is set to true. If theme_name is specified, it will be loaded, and the highlight will be updated. If nothing is specified, the background color will switch between light and dark.

Acknowledgments

loose.nvim is based on onenord.nvim.
However, the color settings themselves are unique and do not depend on it.

About

A colorscheme plugin for Neovim

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages