Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 0 additions & 189 deletions lua/nvim.lua

This file was deleted.

8 changes: 4 additions & 4 deletions lua/terminal.lua → lua/terminal/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- Highlights terminal CSI ANSI color codes.
-- @module terminal
local nvim = require 'nvim'
local nvim = require 'terminal.nvim'

local function rgb_to_hex(r,g,b)
return ("#%02X%02X%02X"):format(r,g,b)
Expand Down Expand Up @@ -39,7 +39,7 @@ local function initialize_terminal_colors()
result[i] = cterm_colors[i]
end
-- g:terminal_color_n overrides
if nvim.o.termguicolors then
if vim.o.termguicolors then
-- TODO only do 16 colors?
for i = 0, 255 do
local status, value = pcall(vim.api.nvim_get_var, 'terminal_color_'..i)
Expand Down Expand Up @@ -365,8 +365,8 @@ end
local function setup(rgb_color_table)
rgb_color_table = rgb_color_table or initialize_terminal_colors()
function TERMINAL_SETUP_HOOK()
nvim.win_set_option(0, 'conceallevel', 2)
nvim.win_set_option(0, 'wrap', false)
vim.wo.conceallevel = 2
vim.wo.wrap = false
attach_to_buffer(nvim.get_current_buf(), rgb_color_table)
end
nvim.ex.augroup("TerminalSetup")
Expand Down
57 changes: 57 additions & 0 deletions lua/terminal/nvim.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- Equivalent to `echo vim.inspect(...)`
local function nvim_print(...)
if select("#", ...) == 1 then
vim.api.nvim_out_write(vim.inspect((...)))
else
vim.api.nvim_out_write(vim.inspect {...})
end
vim.api.nvim_out_write("\n")
end

--- Equivalent to `echo` EX command
local function nvim_echo(...)
for i = 1, select("#", ...) do
local part = select(i, ...)
vim.api.nvim_out_write(tostring(part))
-- vim.api.nvim_out_write("\n")
vim.api.nvim_out_write(" ")
end
vim.api.nvim_out_write("\n")
end

-- `nvim.$method(...)` redirects to `nvim.api.nvim_$method(...)`
-- TODO `nvim.ex.$command(...)` is approximately `:$command {...}.join(" ")`
-- `nvim.print(...)` is approximately `echo vim.inspect(...)`
-- `nvim.echo(...)` is approximately `echo table.concat({...}, '\n')`
-- Both methods cache the inital lookup in the metatable, but there is a small overhead regardless.
return setmetatable({
print = nvim_print;
echo = nvim_echo;
ex = setmetatable({}, {
__index = function(self, k)
local mt = getmetatable(self)
local x = mt[k]
if x ~= nil then
return x
end
local command = k:gsub("_$", "!")
local f = function(...)
return vim.api.nvim_command(table.concat(vim.tbl_flatten {command, ...}, " "))
end
mt[k] = f
return f
end
});
}, {
__index = function(self, k)
local mt = getmetatable(self)
local x = mt[k]
if x ~= nil then
return x
end
local f = vim.api['nvim_'..k]
mt[k] = f
return f
end
})