From aa59b0ab24778064df768e63489fe3bf149f5b6c Mon Sep 17 00:00:00 2001 From: nat-418 <93013864+nat-418@users.noreply.github.com> Date: Mon, 17 Oct 2022 06:17:22 +0200 Subject: [PATCH] Refactor for v1.0.0 --- README.md | 35 ++++++++++++++++++++--------------- lua/termitary.lua | 23 +++++++++++++++-------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 49fb85e..2902244 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,11 @@ Termitary ships a single `:Termitary` command with a few subcommands: | name | action | | ---------------- | -------------------------------------------------------- | | `activate` | Set the current terminal buffer to work with Termitary | -| `execute {text}` | Send some `{text}` to the active terminal with a `` | | `new` | Open a new terminal buffer and `activate` it | | `paste` | Send contents of the `"` register to the terminal buffer | -| `repeat` | Emulate pressing `` in the terminal buffer | +| `repeat` | Emulate typing `` in the terminal buffer | | `{range}send` | Put some `{range}` of the current buffer in the terminal | +| `type {text}` | Send some `{text}` to the active terminal with a `` | For example, to send the contents of some buffer to a REPL running in the active terminal buffer: `:%Termitary send`. @@ -51,10 +51,14 @@ the default `Termitary` to `T` and add an integration with the ```lua require('termitary').setup({ - command_name = 'T', - custom_new = function() - require('FTerm').open() - end + local termitary = require('termitary') + termitary.setup({ + command_name = 'T', + custom_new = function() + require('FTerm').open() + termitary.activate() + end + }) }) ``` @@ -62,14 +66,15 @@ Or to open a new native terminal ten lines tall under the current buffer: ```lua require('termitary').setup({ - command_name = 'T', - custom_new = function() - vim.cmd({ - 'botright 10new', - 'terminal', - 'wincmd p' - }) - end + local termitary = require('termitary') + termitary.setup({ + command_name = 'T', + custom_new = function() + vim.cmd('botright 10new') + vim.cmd('terminal') + termitary.activate() + vim.cmd('wincmd p') + end + }) }) ``` - diff --git a/lua/termitary.lua b/lua/termitary.lua index baa3c8f..dd079f8 100644 --- a/lua/termitary.lua +++ b/lua/termitary.lua @@ -5,6 +5,11 @@ M.state = { terminal_id = nil } +M.activate = function() + M.state.terminal_id = vim.b.terminal_job_id + return true +end + M.run = function(args) if args == nil then return false end @@ -28,13 +33,13 @@ M.run = function(args) if M.state.custom_new == nil then vim.api.nvim_command('terminal') vim.api.nvim_command('norm G') + M.activate() + return true else - M.state.custom_new() + return M.state.custom_new() end - M.state.terminal_id = vim.b.terminal_job_id - - return true + return false end -- The following subcommands require a terminal_id @@ -43,9 +48,9 @@ M.run = function(args) return false end - if subcommand == 'execute' then + if subcommand == 'type' then if #args.fargs <= 0 then - print('Error: nothing to execute') + print('Error: nothing to type') return false end @@ -92,7 +97,7 @@ M.setup = function(options) local completion = function() return { 'activate', - 'execute', + 'type', 'new', 'paste', 'repeat', @@ -108,11 +113,13 @@ M.setup = function(options) M.state.custom_new = options.custom_new end - return vim.api.nvim_create_user_command( + vim.api.nvim_create_user_command( options.command_name, function(args) M.run(args) end, {nargs = '*', complete = completion, range = true} ) + + return true end return M