Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A general-purpose terminal wrapper and management plugin for neovim, written in lua

NotificationsYou must be signed in to change notification settings

pianocomposer321/consolation.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

A general-perpose terminal wrapper and management plugin for neovim, written in lua

screenshot

Demo

https://asciinema.org/a/88T1XmVG6Xak4580OHsrBV7kW

About

I know what you're thinking: "There are already dozens of terminal wrapper plugins for vim/neovim out there! Why yet another?" And you'd be partially right - the default configuration of consolation.nvim is basically the same asalltheotherterminalwrapperpluginsoutthere. But, as is the case with many vim and neovim plugins, consolation.nvim is much more than its default configuration.

The main reason thatthe author created this plugin is because while there is no shortage of either terminal management plugins (e.g.Neoterm) or floating terminal plugins (e.g.Floaterm), trying to get either the terminal management plugin to work with floating windows or the floating terminal plugin to accept input programmatically is a major pain. The idea of this plugin is to take absolutelyany asthetically enhancing terminal plugin and make it easy to use programmatically as well. What this means practically speaking is that you can have a floating terminal (like withFloaterm orFTerm) that can be controlled with lua functions similarly toNeoterm.

Installation

Packer.nvim:use 'pianocomposer321/consolation.nvim'vim-plug:Plug 'pianocomposer321/consolation.nvim'etc.

Usage

The way you interact with Consolation is through itsWrapper object.

Wrapper:new()

Returns a newWrapper object

Wrapper:setup(opts)

Setup theWrapper using the provided configuration options

Arguments
  • create (function): The function used to create the terminal
Default
function()vim.cmd("vnew | term")end
  • open (function): The function used to open the terminal.
Default
function(self)localwinnr=self.get_winnr()ifwinnr==-1thenvim.cmd("vnew")vim.cmd("b"..self.bufnr)elsevim.cmd(winnr.."wincmd w")endend
  • close (function): The function used to close the terminal.
Default
function(self)localwinnr=self.get_winnr()vim.cmd(winnr.."wincmd c")end
  • kill (function): The function used to kill the terminal.
Default
function (self)vim.cmd("bd!"..self.bufnr)end

Except forcreate, all of these functions accept one argument, which is a reference to theWrapper object iself. This way all of its variables likebufnr,winid, etc. are avaliable to the functions.

Wrapper:create()

Creates a new terminal buffer, using thecreate function specified in theWrapper:setup(opts) function, and updates values for the terminal'sbufnr,winid, etc.

Wrapper:open(args)

Opens the terminal using theopen function specified in theWrapper:setup(opts) function.

Arguments (optional)
  • cmd (string, defaultnil): Command to run upon opening the terminal
  • create (bool, defaulttrue): Whether to create the terminal if it does not already exist

Wrapper:close()

Closes the terminal using theclose function specified in theWrapper:setup(opts) function.

Wrapper:kill()

Kills the terminal using thekill function specified in theWrapper:setup(opts) function, and resets theWrapper object'schannel,winid, andbufnr variables tonil.

Wrapper:toggle(args)

Toggles the terminal using either theopen or theclose function specified in theWrapper:setup() opts function.

Arguments (optional)
  • create (bool, defaulttrue): Whether to create the terminal when opening it if it does not already exist

Wrapper:send_command(args)

Sends a command to the terminal.

Arguments
  • cmd (string, REQUIRED): The command to send
  • open (bool, defaulttrue): Whether to open the terminal before running the command
  • create (bool, defaulttrue): Whether to create the terminal if it does not already exist

Wrapper:is_open()

Utility function that returns whether the terminal buffer is currently displayed in a window (IOW, open).

Returns:bool

Wrapper:get_winnr()

Utility function that returns theWrapper object'swinnr. (:help bufwinnr())

Returns:int

Examples

Using neovim's builtin:term command in a vsplit

localWrapper=require("consolation").WrapperBuiltinTerminalWrapper=Wrapper:new()BuiltinTerminalWraper:setup {create=function()vim.cmd("vnew | term")end,open=function(self)ifself:is_open()thenlocalwinnr=vim.fn.bufwinnr(self.bufnr)vim.cmd(winnr.."wincmd w")elsevim.cmd("vnew")vim.cmd("b"..self.bufnr)endend,close=function(self)localwinnr=vim.fn.bufwinnr(self.bufnr)vim.cmd(winnr.."wincmd c")end,kill=function(self)vim.cmd("bd!"..self.bufnr)end}-- Try:-- BuiltinTerminalWraper:open {cmd = "echo hi"}-- BuiltinTerminalWraper:send_command {cmd = "echo hi again"}-- BuiltinTerminalWraper:close()-- BuiltinTerminalWraper:toggle()-- BuiltinTerminalWraper:kill()

Using FTerm.nvim

localterm=require("Fterm.terminal")Runner=term:new():setup()FtermWrapper=Wrapper:new()FtermWrapper:setup {create=function()Runner:open()end,open=function(_)Runner:open()end,close=function(_)Runner:close()end,kill=function(_)Runner:close(true)end}

About

A general-purpose terminal wrapper and management plugin for neovim, written in lua

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp