Skip to content

Commit

Permalink
feat(stages): place bottom up (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsho committed Sep 4, 2022
1 parent 070c278 commit 6b779c9
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 196 deletions.
12 changes: 8 additions & 4 deletions doc/nvim-notify.txt
@@ -1,5 +1,5 @@
================================================================================
*nvim-notify*
NVIM-NOTIFY *nvim-notify*

A fancy, configurable notification manager for NeoVim

Expand Down Expand Up @@ -86,7 +86,8 @@ notify.setup({user_config}) *notify.setup()*
minimum_width = 50,
render = "default",
stages = "fade_in_slide_out",
timeout = 5000
timeout = 5000,
top_down = true
}

Parameters: ~
Expand Down Expand Up @@ -177,7 +178,7 @@ notify.instance({user_config}, {inherit}) *notify.instance()*


================================================================================
*notify.config*
CONFIG *notify.config*

notify.Config *notify.Config*

Expand Down Expand Up @@ -216,11 +217,14 @@ notify.Config *notify.Config*
animation stages, higher
value means smoother
animations but more CPU usage
{top_down} (boolean) whether or not to position
the notifications at the top
or not



================================================================================
*notify-render()*
NOTIFY-RENDER() *notify-render()*

Notification buffer rendering

Expand Down
6 changes: 6 additions & 0 deletions lua/notify/config/init.lua
Expand Up @@ -29,6 +29,7 @@ local default_config = {
on_close = nil,
minimum_width = 50,
fps = 30,
top_down = true,
icons = {
ERROR = "",
WARN = "",
Expand All @@ -51,6 +52,7 @@ local default_config = {
---@field render function | string: Function to render a notification buffer or a built-in renderer name
---@field minimum_width integer: Minimum width for notification windows
---@field fps integer: Frames per second for animation stages, higher value means smoother animations but more CPU usage
---@field top_down boolean: whether or not to position the notifications at the top or not

local opacity_warned = false

Expand Down Expand Up @@ -141,6 +143,10 @@ function Config.setup(custom_config)
return user_config.on_open
end

function config.top_down()
return user_config.top_down
end

function config.on_close()
return user_config.on_close
end
Expand Down
7 changes: 6 additions & 1 deletion lua/notify/init.lua
Expand Up @@ -9,6 +9,7 @@ local stages = require("notify.stages")
local Notification = require("notify.service.notification")
local WindowAnimator = require("notify.windows")
local NotificationService = require("notify.service")
local stage_util = require("notify.stages.util")

---@type Notification[]
local notifications = {}
Expand Down Expand Up @@ -158,7 +159,11 @@ function notify.instance(user_config, inherit)
local instance_config = config.setup(user_config)

local animator_stages = instance_config.stages()
animator_stages = type(animator_stages) == "string" and stages[animator_stages] or animator_stages
local direction = instance_config.top_down() and stage_util.DIRECTION.TOP_DOWN
or stage_util.DIRECTION.BOTTOM_UP

animator_stages = type(animator_stages) == "string" and stages[animator_stages](direction)
or animator_stages
local animator = WindowAnimator(animator_stages, instance_config)
local service = NotificationService(instance_config, animator)

Expand Down
91 changes: 46 additions & 45 deletions lua/notify/stages/fade.lua
@@ -1,47 +1,48 @@
local stages_util = require("notify.stages.util")

return {
function(state)
local next_height = state.message.height + 2
local next_row =
stages_util.available_slot(state.open_windows, next_height, stages_util.DIRECTION.TOP_DOWN)
if not next_row then
return nil
end
return {
relative = "editor",
anchor = "NE",
width = state.message.width,
height = state.message.height,
col = vim.opt.columns:get(),
row = next_row,
border = "rounded",
style = "minimal",
opacity = 0,
}
end,
function()
return {
opacity = { 100 },
col = { vim.opt.columns:get() },
}
end,
function()
return {
col = { vim.opt.columns:get() },
time = true,
}
end,
function()
return {
opacity = {
0,
frequency = 2,
complete = function(cur_opacity)
return cur_opacity <= 4
end,
},
col = { vim.opt.columns:get() },
}
end,
}
return function(direction)
return {
function(state)
local next_height = state.message.height + 2
local next_row = stages_util.available_slot(state.open_windows, next_height, direction)
if not next_row then
return nil
end
return {
relative = "editor",
anchor = "NE",
width = state.message.width,
height = state.message.height,
col = vim.opt.columns:get(),
row = next_row,
border = "rounded",
style = "minimal",
opacity = 0,
}
end,
function()
return {
opacity = { 100 },
col = { vim.opt.columns:get() },
}
end,
function()
return {
col = { vim.opt.columns:get() },
time = true,
}
end,
function()
return {
opacity = {
0,
frequency = 2,
complete = function(cur_opacity)
return cur_opacity <= 4
end,
},
col = { vim.opt.columns:get() },
}
end,
}
end
149 changes: 75 additions & 74 deletions lua/notify/stages/fade_in_slide_out.lua
@@ -1,76 +1,77 @@
local stages_util = require("notify.stages.util")

return {
function(state)
local next_height = state.message.height + 2
local next_row =
stages_util.available_slot(state.open_windows, next_height, stages_util.DIRECTION.TOP_DOWN)
if not next_row then
return nil
end
return {
relative = "editor",
anchor = "NE",
width = state.message.width,
height = state.message.height,
col = vim.opt.columns:get(),
row = next_row,
border = "rounded",
style = "minimal",
opacity = 0,
}
end,
function(state, win)
return {
opacity = { 100 },
col = { vim.opt.columns:get() },
row = {
stages_util.slot_after_previous(win, state.open_windows, stages_util.DIRECTION.TOP_DOWN),
frequency = 3,
complete = function()
return true
end,
},
}
end,
function(state, win)
return {
col = { vim.opt.columns:get() },
time = true,
row = {
stages_util.slot_after_previous(win, state.open_windows, stages_util.DIRECTION.TOP_DOWN),
frequency = 3,
complete = function()
return true
end,
},
}
end,
function(state, win)
return {
width = {
1,
frequency = 2.5,
damping = 0.9,
complete = function(cur_width)
return cur_width < 3
end,
},
opacity = {
0,
frequency = 2,
complete = function(cur_opacity)
return cur_opacity <= 4
end,
},
col = { vim.opt.columns:get() },
row = {
stages_util.slot_after_previous(win, state.open_windows, stages_util.DIRECTION.TOP_DOWN),
frequency = 3,
complete = function()
return true
end,
},
}
end,
}
return function(direction)
return {
function(state)
local next_height = state.message.height + 2
local next_row = stages_util.available_slot(state.open_windows, next_height, direction)
if not next_row then
return nil
end
return {
relative = "editor",
anchor = "NE",
width = state.message.width,
height = state.message.height,
col = vim.opt.columns:get(),
row = next_row,
border = "rounded",
style = "minimal",
opacity = 0,
}
end,
function(state, win)
return {
opacity = { 100 },
col = { vim.opt.columns:get() },
row = {
stages_util.slot_after_previous(win, state.open_windows, direction),
frequency = 3,
complete = function()
return true
end,
},
}
end,
function(state, win)
return {
col = { vim.opt.columns:get() },
time = true,
row = {
stages_util.slot_after_previous(win, state.open_windows, direction),
frequency = 3,
complete = function()
return true
end,
},
}
end,
function(state, win)
return {
width = {
1,
frequency = 2.5,
damping = 0.9,
complete = function(cur_width)
return cur_width < 3
end,
},
opacity = {
0,
frequency = 2,
complete = function(cur_opacity)
return cur_opacity <= 4
end,
},
col = { vim.opt.columns:get() },
row = {
stages_util.slot_after_previous(win, state.open_windows, direction),
frequency = 3,
complete = function()
return true
end,
},
}
end,
}
end
2 changes: 1 addition & 1 deletion lua/notify/stages/init.lua
Expand Up @@ -13,7 +13,7 @@ local M = {}
setmetatable(M, {
---@return Stages
__index = function(_, key)
return vim.deepcopy(require("notify.stages." .. key))
return require("notify.stages." .. key)
end,
})

Expand Down

0 comments on commit 6b779c9

Please sign in to comment.