Skip to content

Commit

Permalink
Refactor for v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-418 committed Oct 17, 2022
1 parent e31872c commit aa59b0a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<CR>` |
| `new` | Open a new terminal buffer and `activate` it |
| `paste` | Send contents of the `"` register to the terminal buffer |
| `repeat` | Emulate pressing `<Up><CR>` in the terminal buffer |
| `repeat` | Emulate typing `<Up><CR>` 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 `<CR>` |

For example, to send the contents of some buffer to a REPL running in the
active terminal buffer: `:%Termitary send`.
Expand All @@ -51,25 +51,30 @@ 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
})
})
```

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
})
})
```

23 changes: 15 additions & 8 deletions lua/termitary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -92,7 +97,7 @@ M.setup = function(options)
local completion = function()
return {
'activate',
'execute',
'type',
'new',
'paste',
'repeat',
Expand All @@ -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

0 comments on commit aa59b0a

Please sign in to comment.