Code Monkey home page Code Monkey logo

fterm.nvim's Introduction

FTerm.nvim

๐Ÿ”ฅ No-nonsense floating terminal plugin for neovim ๐Ÿ”ฅ

FTerm

๐Ÿš€ Installation

use "numToStr/FTerm.nvim"
Plug 'numToStr/FTerm.nvim'

โš’๏ธ Setup (optional)

FTerm default terminal has sane defaults. If you want to use the default configuration then you don't have to do anything but you can override the default configuration by calling setup().

require'FTerm'.setup({
    border = 'double',
    dimensions  = {
        height = 0.9,
        width = 0.9,
    },
})

-- Example keybindings
vim.keymap.set('n', '<A-i>', '<CMD>lua require("FTerm").toggle()<CR>')
vim.keymap.set('t', '<A-i>', '<C-\\><C-n><CMD>lua require("FTerm").toggle()<CR>')

Configuration

Following options can be provided when calling setup(). Below is the default configuration:

{
    ---Filetype of the terminal buffer
    ---@type string
    ft = 'FTerm',

    ---Command to run inside the terminal
    ---NOTE: if given string[], it will skip the shell and directly executes the command
    ---@type fun():(string|string[])|string|string[]
    cmd = os.getenv('SHELL'),

    ---Neovim's native window border. See `:h nvim_open_win` for more configuration options.
    border = 'single',

    ---Close the terminal as soon as shell/command exits.
    ---Disabling this will mimic the native terminal behaviour.
    ---@type boolean
    auto_close = true,

    ---Highlight group for the terminal. See `:h winhl`
    ---@type string
    hl = 'Normal',

    ---Transparency of the floating window. See `:h winblend`
    ---@type integer
    blend = 0,

    ---Object containing the terminal window dimensions.
    ---The value for each field should be between `0` and `1`
    ---@type table<string,number>
    dimensions = {
        height = 0.8, -- Height of the terminal window
        width = 0.8, -- Width of the terminal window
        x = 0.5, -- X axis of the terminal window
        y = 0.5, -- Y axis of the terminal window
    },

    ---Replace instead of extend the current environment with `env`.
    ---See `:h jobstart-options`
    ---@type boolean
    clear_env = false,

    ---Map of environment variables extending the current environment.
    ---See `:h jobstart-options`
    ---@type table<string,string>|nil
    env = nil,

    ---Callback invoked when the terminal exits.
    ---See `:h jobstart-options`
    ---@type fun()|nil
    on_exit = nil,

    ---Callback invoked when the terminal emits stdout data.
    ---See `:h jobstart-options`
    ---@type fun()|nil
    on_stdout = nil,

    ---Callback invoked when the terminal emits stderr data.
    ---See `:h jobstart-options`
    ---@type fun()|nil
    on_stderr = nil,
}

๐Ÿ”ฅ Usage

  • Opening the terminal
require('FTerm').open()

-- or create a vim command
vim.api.nvim_create_user_command('FTermOpen', require('FTerm').open, { bang = true })
  • Closing the terminal

This will close the terminal window but preserves the actual terminal session

require('FTerm').close()

-- or create a vim command
vim.api.nvim_create_user_command('FTermClose', require('FTerm').close, { bang = true })
  • Exiting the terminal

Unlike closing, this will remove the terminal session

require('FTerm').exit()

-- or create a vim command
vim.api.nvim_create_user_command('FTermExit', require('FTerm').exit, { bang = true })
  • Toggling the terminal
require('FTerm').toggle()

-- or create a vim command
vim.api.nvim_create_user_command('FTermToggle', require('FTerm').toggle, { bang = true })
  • Running commands

If you want to run some commands, you can do that by using the run method. This method uses the default terminal and doesn't override the default command (which is usually your shell). Because of this when the command finishes/exits, the terminal won't close automatically.

-- run() can take `string` or `table` just like `cmd` config
require('FTerm').run('man ls') -- with string
require('FTerm').run({'yarn', 'build'})
require('FTerm').run({'node', vim.api.nvim_get_current_buf()})

-- Or you can do this
vim.api.nvim_create_user_command('ManLs', function()
    require('FTerm').run('man ls')
end, { bang = true })

vim.api.nvim_create_user_command('YarnBuild', function()
    require('FTerm').run({'yarn', 'build'})
end, { bang = true })

โšก Scratch Terminal

You can also create scratch terminal for ephemeral processes like build commands. Scratch terminal will be created when you can invoke it and will be destroyed when the command exits. You can use the scratch({config}) method to create it which takes same options as setup(). This uses custom terminal under the hood.

require('FTerm').scratch({ cmd = 'yarn build' })
require('FTerm').scratch({ cmd = {'cargo', 'build', '--target', os.getenv('RUST_TARGET')} })

-- Scratch terminals are awesome because you can do this
vim.api.nvim_create_user_command('YarnBuild', function()
    require('FTerm').scratch({ cmd = {'yarn', 'build'} })
end, { bang = true })

vim.api.nvim_create_user_command('CargoBuild', function()
    require('FTerm').scratch({ cmd = {'cargo', 'build', '--target', os.getenv("RUST_TARGET")} })
end, { bang = true })

-- Code Runner - execute commands in a floating terminal
local runners = { lua = 'lua', javascript = 'node' }

vim.keymap.set('n', '<leader><Enter>', function()
    local buf = vim.api.nvim_buf_get_name(0)
    local ftype = vim.filetype.match({ filename = buf })
    local exec = runners[ftype]
    if exec ~= nil then
        require('FTerm').scratch({ cmd = { exec, buf } })
    end
end)

โœจ Custom Terminal

By default FTerm only creates and manage one terminal instance but you can create your terminal by using the FTerm:new() function and overriding the default command. This is useful if you want a separate terminal and the command you want to run is a long-running process. If not, see scratch terminal.

Below are some examples:

local fterm = require("FTerm")

local gitui = fterm:new({
    ft = 'fterm_gitui', -- You can also override the default filetype, if you want
    cmd = "gitui",
    dimensions = {
        height = 0.9,
        width = 0.9
    }
})

-- Use this to toggle gitui in a floating terminal
vim.keymap.set('n', '<A-g>', function()
    gitui:toggle()
end)

Screenshot

gitui

local fterm = require("FTerm")

local btop = fterm:new({
    ft = 'fterm_btop',
    cmd = "btop"
})

 -- Use this to toggle btop in a floating terminal
vim.keymap.set('n', '<A-b>', function()
    btop:toggle()
end)

Screenshot

btop

๐Ÿ’ Credits

fterm.nvim's People

Contributors

acksld avatar beauwilliams avatar delphinus avatar lukaswrz avatar numtostr avatar utilyre avatar xuyuanp avatar zhufenggood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fterm.nvim's Issues

Dynamic `cmd`

Good day to you!

For opening csv files in certain program i have this code:

local fterm = require("FTerm")

function _G.fterm.visidata()
    local visidata = fterm:new({
        ft = "fterm_visidata", -- You can also override the default filetype, if you want
        cmd = "visidata " .. vim.fn.expand("%"),
        dimensions = {
            x = 1,
            y = 0,
            height = 0.9,
            width = 0.9,
        },
    })
    -- if vim.bo.filetype == "csv" then
    visidata:toggle()
    -- end
end

right now it creates new fterm-instance in function.

Question:

is it possible to define template without cmd attribute, but set it in dynamic
function, so cmd could be dynamic because of expansion of %?

something like this (i've tried this, but get only shell float window):

local fterm = require("FTerm")
local visidata = fterm:new({
    ft = "fterm_visidata", -- You can also override the default filetype, if you want
    dimensions = {
        x = 1,
        y = 0,
        height = 0.9,
        width = 0.9,
    },
})

function _G.fterm.visidata()
    visidata.cmd = "visidata " .. vim.fn.expand("%") -- if vim.bo.filetype == "csv" then
    visidata:toggle()
    -- end
end

Thank you!

It didn't start from `pwd`?

I ran :pwd in a buffer and got ~/.config, while when I execute :lua require("FTerm").toggle() the path is at ~.

Update: I have tested other folders under ~, this bug only happens on ~/.config.

black rectangle appearing after window resizing

nvim v0.5.0-865-gfb52790d1
sway version 1.5.1
alacritty 0.6.0 (04cbf767)
Arch 5.9.1-rt20-1-rt

this sort of stuff happens when I resize my window (for bigger) after calling :FTermToggle on opening nvim.

scrn-2020-12-11-04-29-32

and this sort of stuff happens when I resize my window (for smaller) after calling :FTermToggle on opening nvim.

scrn-2020-12-11-04-43-45

in both cases i have to toggle FTerm off/on to create the issue.

can you reproduce on your wm / system ?

and thanks for a nice plugin.

Question on escape key!

Hi! Coming from reddit. Not sure if this is the best place to ask something.

If I toggle the term, what does pressing escape do? Does it shift the focus to the buffer that was last opened before opening a floating term?

If yes, can this behavior be changed? E.g. disabling esc key in the floating term

I'm asking because I'll like to use fterm with lazygit and would need to use esc there.. many thanks in advance for your help!!

How to toggle the terminal?

I've installed FTerm and am using lua require('FTerm').toggle() to toggle the terminal, which opens it, but once the terminal is open, how to I toggle it closed again as I can't enter neovim's command mode inside the terminal?

Terminal output shifted left after opening an existing FTerm instance

First of all, I love your plugin! As I'm sure others have done, I use it to wrap lf as a built-in file browser. It forms what I think is the most ergonomic part of my setup, and the API you've put together basically made it so I didn't even need to think about the terminal side of things. ๐Ÿš€

The issue I'm running into is that when I toggle the FTerm instance that contains my lf process and then open it back up again, the existing output re-appears shifted to the left by several characters part of the time.

This only appears to happen when the output produced by lf is wider than the window size defined by FTerm. This is almost certainly something I can fix on the lf side of things (seems to be caused by my file preview script, and only happens when I'm currently previewing a file that is wider than some threshold).

I wonder, though, if it makes sense to have FTerm scroll back to the left of the terminal output when restoring the terminal buffer's contents so that the left edge of the output is always visible?

Feat: make col and row options for position depend on vim.o.col and vim.o.row

Hi!
Thanks for the awesome plugin.
I've noticed that the row and col are calculated as

local col = math.ceil((cl - width) * opts.x)
local row = math.ceil((ln - height) * opts.y - 1)

which means the position depends on the free space.
My dimensions config looks as follow

{ height = 0.3, width = 0.2, x = 0.8, y = 0 }

But the result is not the expected. If I want to place the terminal at the top right, then the x position must be 1 which feels counter intuitive.

{ height = 0.3, width = 0.2, x = 1, y = 0 }

Previous window lost when float term closed

Reproduce:

Start nvim and execute :split, we can use <C-w>p or :wincmd p to switch to previous window.

Open and close a float term, we can't switch back to previous window, because it's overwritten by the closed floating window which is not what we expected.

lualine-rendered statusline reverts to built-in statusline settings when FTerm is invoked in a buffer

When FTerm is invoked in a buffer (in this case, to use gitui) the plugin lualine reverts to the built-in statusline. However, after switching buffers (:bn or bp), the statusline rendered by lualine returns. I do not see this behavior with other plugins that use floating windows such as rnvimr or fzf.vim.

The desired behavior is that the statusline does not revert to the built-in statusline after invoking FTerm.

I'm not sure how to go about looking into this further, but here are some relevant configs:

" A blazing fast and easy to configure neovim statusline written in pure lua.                                                                                                                                                       Plug 'hoob3rt/lualine.nvim' 

require('lualine').setup {
    options = {theme = 'everforest'}
}
local term = require("FTerm.terminal")

local gitui = term:new():setup({
    cmd = "gitui",
    dimensions = {
        height = 0.9,
        width = 0.9
    }
})

 -- Use this to toggle gitui in a floating terminal
function _G.__fterm_gitui()
    gitui:toggle()
end

-- Keybinding
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }

map('', '<leader>t', '<CMD>lua _G.__fterm_gitui()<CR>', opts)
map('', '<leader>T', '<C-\\><C-n><CMD>lua _G.__fterm_gitui()<CR>', opts)

Please let me know if there is any other relevant info that I can post.

toggle custom terminal: close the toggle

First of all thank you very much for the great plugin!

I am creating a terminal instance where a pass a certain custom command as per the docs: in particular a minimal reproducible example can be thought of as

local function hello()
  return fterm:new({ cmd = 'echo "hello"' })
end

vim.keymap.set('n', '<A-g>', function()
    hello():toggle()
end)

This works fine when toggling the terminal in normal mode, however whilst in terminal mode (with the command already toggled and the custom terminal already active) the only way to close it is via q rather than via <A-g> again. If I explicitly define a command in terminal mode as shown

vim.keymap.set('t', '<A-g>', '<C-\\><C-n><CMD>lua hello()<CR>')

I get exceptions of "attempt to index a boolean value" (also if I fully qualify the path to the custom function fully requiring the whole module). I wonder if the object fterm:new() really returns a toggleable instance, or perhaps I am merely making silly grammar mistakes while defining the keymap in terminal mode?

how to use fterm

I want known how can i get something done like :FloatermNew --autoclose=0 gcc % -o %< && ./%:h, i know there's require("FTerm").run but i don't know , how can i get current buffer name , current buffer name without extension , current line number or something else . anyone knows if there a help manual?

Feat: Pre start in background

The first time that a terminal window is opened takes some seconds to be able to use, mainly if you have a lot of configurations to start the terminal.
Would be nice a pre start feature, without to show a terminal, starting in background.

Module 'FTerm' not found

Hello,

I am currently trying to configure FTerm.
Whenever I execute the keybind for toggling FTerm i get this error message

E5108: Error executing lua [string ":lua"]:1: module 'FTerm' not found: no field package.preload['FTerm'] no file './FTerm.lua' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/share/luajit-2.1.0-beta3/FTerm.lua' no file '/usr/local/share/lua/5.1/FTerm.lua' no file '/usr/local/share/lua/5.1/FTerm/init.lua' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/share/lua/5.1/FTerm.lua' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/share/lua/5.1/FTerm/init.lua' no file './FTerm.so' no file '/usr/local/lib/lua/5.1/FTerm.so' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/lib/lua/5.1/FTerm.so' no file '/usr/local/lib/lua/5.1/loadall.so'

Now, I already deleted my whole nvim/state folder, reinstalled all of my Plugins, ran
:PackerSync and PackerInstall which tells me that FTerm is installed btw.

I'll have to keep using floaterm until this issue is fixed;

Colour configuration

I see there's no way to modify colours. I got a PR concerning the colours not showing on FTerm. my attempt to fix it locally seems to not be working.

local filetype = vim.api.nvim_buf_get_option(0, "filetype")

 -- File/buffer specific settings
 if filetype == "FTerm"  then
   colors.black = "#fff"
   colors.bg2 = "#fff"
 end

I think the problem might be stemming from this. Any help or suggestions would be appreciated. Thanks

Invalid key 'border'

nvim --version:

NVIM v0.5.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: 
Compiled by nixbld

Features: +acl +iconv +tui
See ":help feature-compile"

minimal init.lua:

local path = vim.fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'

if vim.fn.empty(vim.fn.glob(path)) > 0 then
	vim.api.nvim_command('!git clone https://github.com/wbthomason/packer.nvim '..path)
end

-- Required if packer is in `opt` path
vim.cmd('packadd packer.nvim')

local packer = require('packer')

return packer.startup(function()
  local use = packer.use

  use { 'wbthomason/packer.nvim', opt = true }
  use {
    "numtostr/FTerm.nvim",
    config = function()
      require'FTerm'.setup()
    end
  }

end)

Commands FTermOpen or FTermToggle:
E5108: Error executing lua ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:93: Invalid key 'border'
I tried:

require'FTerm'.setup({
    dimensions  = {
        height = 0.8,
        width = 0.8,
        x = 0.5,
        y = 0.5
    },
    border = 'single'
    -- border = '|'
})

with the same result.
Thanks for your work.

[Question] Add vifm-buit in

Hi! I've got a little question. I'm using the vifm file manager and I'm wondering if I should add a PR for a default vifm-floating-terminal. What do you think about that?

Run custom command returns an error on Windows

Running this command :lua require('FTerm').run('lazygit') (or anything in quotes) returns an empty window, with an error message on windows:

E5108: Error executing lua Vim:E475: Invalid argument: expected a String or List

image

Scratch Terminal issue

I noticed there's no option to save current buffer before executing the scratch terminal in this plugin so I did that myself by calling vim.cmd. Here's a part of my config for that (executing a code inside of buffer 0):

local fterm = require('FTerm')
local fterm_dimensions = {
  height = 0.35,
  width = 1.0,
  y = 1.0
}
fterm.setup({ dimensions = fterm_dimensions })
local runners = {
  python = 'python3.7',
  sh = 'bash'
}
map('n', '<Leader>e', function()
  vim.cmd('write')
  local buf = vim.api.nvim_buf_get_name(0)
  local ftype = vim.filetype.match({ filename = buf })
  local exec = runners[ftype]
  if exec ~= nil then
    fterm.scratch({
      cmd = { exec, buf },
      dimensions = fterm_dimensions
    })
  end
  end
)

Environment:
OS: debian10
NVIM version: the latest 0.9.0 dev

The problem is that if I do execute that action over unsaved buffer too fast. the contents of it displays in the terminal buffer. How to reproduce that with the config above:

  1. Edit some code (do not save that buffer);
  2. Type <Leader>e hotkey.

All the actions above must be performed as quick as you can. And whatever you do in the main buffer (buffer 0) is mirrored to the terminal buffer.

This's a little video showing that behaviour (starting from 0:56 sec)
https://user-images.githubusercontent.com/6321554/199979073-ecd3b7b5-d949-4d11-afd9-ff1f96fb10a6.mp4

[Feature Request] Allow functions in `cmd`

I'm trying to run a terminal with 'cd "'..vim.fn.expand('%:h')..'" ; cd "$(git rev-parse --show-toplevel)" ; lazygit' everytime the terminal is (re)opened. This is not currently possible, as the cmd is only evaluated upon creation.

It would be nice if the I could use a function instead of a string on cmd, which would be called on every startup of the terminal:

require("FTerm"):new({
	...
	cmd = function() return 'cd "'..vim.fn.expand('%:h')..'" ; cd "$(git rev-parse --show-toplevel)" ; lazygit' end,
	...
})

Note: I'm posting this request because terminal:run() won't suffice, as run will re-run the command on every execution, while setting cmd would only re-run the command when the terminal is closed and reopened.

Launch terminal with command

It would be great to have the ability to pass a command to a floating terminal.
I would use this to launch lazygit with a single keybind.

Reroute anything that opens in fterm window to another window

One thing that I really like about nvim-tree.lua is that when ever I try to open a file inside its window, it'll open it up inside another window.

This behavior is extremely helpful especially in a terminal window. I have git setup to open the COMMIT buffer directly in neovim when it is a subprocess of another neovim process (rather than having a new instance of neovim nested in the integrated terminal) but my problem is that right after I run git commit to edit my commit message in neovim, the buffer will be opened inside the floating terminal window instead of a sensible window for example a window that contains a buffer with vim.bo.buftype equal to ""

Can't background an FTerm terminal running `k9s`

Thanks for maintaining FTerm.nvim! It's a really cool project :)

I use k9s to monitor my kubernetes clusters in the terminal, and was previously using nvim-k8s to launch a floating window in neovim with k9s running in it. I wanted to consolidate my plugins and use fterm for k9s instead, because nvim-k8s is not actively maintained right now anyway. Here's what I put together in my lua config:

local fterm = require("FTerm")

-- must install k9s in advance, see: https://k9scli.io/topics/install/
local k9s = fterm:new({
    ft = 'fterm_k9s',
    cmd = "k9s",
    dimensions = {
        height = 0.9,
        width = 0.9
    }
})

-- Use this to toggle k9s in a floating terminal
-- first arg of 'n' is for normal mode in neovim
-- <A-b> are keys: Alt + b (alt is option on macOS)
vim.keymap.set('n', '<A-b>', function()
    k9s:toggle()
end)

Launching k9s in a floating terminal with Alt+b works fine, but I can't background it with the same key combination and I'm not sure why. I think k9s is capturing the key input, but I'm not really sure how to fix this. I know in nvim-k8s they used the keys Alt+p for toggling the floating window, and that worked fine, but I have no idea why it doesn't work for fterm.

I tried with Alt+p instead of the config above and I get the same result of it working for opening the terminal, but not for backgrounding it.

Do you have any ideas on how to solve this? It doesn't look like k9s is actually using Alt for anything according to their docs, so I'm a bit confused ๐Ÿค”

Lazy Loading

hello I have an issue. How can I lazy load FTerm. I am trying to find this so that I can implement this on StarVim

run() function stopped working

Problem

When a new terminal is created with the run() function, instead of running the inputted command, something like: $ table: HEXNUM is run instead.

After doing some testing, this broke in commit f3fb0fe.

Recreating

With a fresh version of FTerm.nvim, put this in your init.vim:

nnoremap <leader>r :w<CR> :lua require('FTerm').run({'echo', 'hello'})<CR>

or whatever the equivalent is in Lua.

Now when r is pressed, the command doesn't work and behaves as described in the 'Problem' section.

After going back to the commit before f3fb0fe, everything worked again.

Weird highlight colors

I imagine I have some conflicting settings causing this, but any tips as to why my default Normal highlight looks wonky in the terminal?

FWIW things look good if I override the default with a blank: hl = '', otherwise they look like the below screenshots

image
image

Border colours are inverted

Update: For others joining in, I misinterpreted the issue at first. See my next comment below for describing the real problem.


With Neovim v0.5.0-dev+1302-g8a93d1028, when I run the following, the border style looks exactly the same as if single was replaced with double:

:lua require'FTerm'.setup({border = 'single'})

Adjusting this setting through an init file has the same results.

On the other hand, using the values none and shadow (taken from :h nvim_open_win) works as expected.

Sometimes it shows this error when using with `fzf-lua`.

E5108: Error executing lua ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:97: Window was closed immediately
stack traceback:
        [C]: in function 'nvim_open_win'
        ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:97: in function 'create_win'
        ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:163: in function 'open'
        ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:208: in function 'toggle'
        ...are/nvim/site/pack/packer/start/FTerm.nvim/lua/FTerm.lua:37: in function 'toggle'
        [string ":lua"]:1: in main chunk

I encountered this error when using fzf-lua's git_status function. I pressed <ESC> after I finished reading the git diff of files.

Callback for scratch terminals

After a process in a scratch terminal is executed, it would be useful to be able to execute a lua function taking the exit_status of the job as it's input.

I think the implementation should be pretty straight-forward as the building blocks already seems to be in place (jobwait).

I'm thinking about two main api:

  • A table field in the scratch paramater:
    lua require('FTerm').scratch({ cmd = 'yarn build' , on_exit = function})

  • A function call( is this possible in lua?):
    lua require('FTerm').scratch({ cmd = 'yarn build' }).on_exit(function)

My main goal is to be able to interact with nvim-notify nicely.

Add argument to cmd options

Hi all,

I love the scratch terminal and have used it forever since its release. Very fast and super useful.

Still, I need the ability to pass the arguments along with cmd option in config. My example use case would be like this

-- debug current python script
vim.cmd('command! Pudb lua require("FTerm").scratch({ cmd = "pudb" args = "%" })')

Of course, "%" is a vim feature for expanding the current filename. I haven't had much experience with vim API in lua yet. Maybe some of you guys know how to do it right away and have some suggesting idea. I think this feature could add even more flexibility to Fterm.

Thank you in advance!

FTerm crashes on Windows due to latest commit

Hi! I mean a58dc7a. I tried setting cmd in my require'FTerm'.setup(), but it didn't work because it always asserts os.getenv('SHELL') regardless of what I set cmd to. Reverting line 26 in utils.lua makes it work again.

[Bug?] "FTerm: setup() is optional..." On call to fterm.new()

Hello!

Having a small issue.

I have the following function:

function LazygitFloat()
    local cfg = {
        ft = 'lazygit',
        cmd = "lazygit",
        auto_close = true,
        dimensions = {
            height = 0.8, -- Height of the terminal window
            width = 0.8, -- Width of the terminal window
        },
    }

    local term = require('FTerm').new(cfg)

    if not term then
        return
    end

    term.open()
end

When I attempt to run this, I get this message:

FTerm: setup() is optional. Please remove it!

What am I doing wrong in the above function to get this?

If I just run require('FTerm').run("lazygit"), it works fine enough, but I am unable to customize the options in this case.

small update:
from init.lua for FTerm

---Creates a custom terminal
---@param cfg Config
---@return Term
function M:new(cfg)
    print(cfg)
    return Term:new():setup(cfg)
end

I'm getting a nil for the print(cfg) I added. I must be doing something wrong.

Any help is greatly appreciated.

Thanks!

Error when trying to quit with :xa

Steps to reproduce:

  • toggle term on
  • toggle term off
  • try to quit with :xa

Error:

E948: Job still running                                                                                                                                                                                                                      
E676: No matching autocommands for acwrite buffer   

Nvim version: nightly@fe808f0

Broken after update: FTerm.nvim/lua/FTerm/terminal.lua:156: Expected Lua number

Run nvim -v:

NVIM v0.7.0-dev+817-gbe255557c

E5108: Error executing lua ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:156: Expected Lua number
stack traceback:
        [C]: in function 'nvim_buf_set_option'
        ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:156: in function 'open_term'
        ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:178: in function 'open'
        ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:221: in function 'toggle'
        ...vim/site/pack/packer/start/FTerm.nvim/lua/FTerm/init.lua:37: in function 'toggle'
        [string ":lua"]:1: in main chunk
Press ENTER or type command to continue

project root

launching the terminal in project root possibly ?

border highlight

Is there a way to control border highlighting?

Looks inaccurate by default.
image

In Floaterm I do

highlight link FloatermBorder Normal

Which looks much nicier
image

How to run statically-typed language by scratch terminal (Such as c/cpp/java)

Hi, thx for this great project!
I don't know how to set compile and execute commands in scratch terminal cmd config. Firstly, I've tried this by follow readme :

local runners = { c = 'gcc', cpp = 'g++' }

vim.keymap.set('n', '<leader><Enter>', function()
    local buf = vim.api.nvim_buf_get_name(0)
    local ftype = vim.filetype.match({ filename = buf })
    local fname = string.gsub(buf, ftype, '')
    local exec = runners[ftype]
    if exec ~= nil then
    	if exec == 'c' then
    		local cbin_fname = fname..'out'
        	require('FTerm').scratch({
        		cmd = { exec, buf, '-o', '&&', './'..cbin_fname }
        	})
        end
    end
end)

But this didn't work what I expect. The result is same as cmd = { exec, buf }, just compile to a default a.out file, and didn't executed.

image

Then I tried this to only execute a.out :

local runners = { c = 'gcc', cpp = 'g++' }

vim.keymap.set('n', '<leader><Enter>', function()
    local buf = vim.api.nvim_buf_get_name(0)
    local ftype = vim.filetype.match({ filename = buf })
    local exec = runners[ftype]
    if exec ~= nil then
    	if exec == 'c' then
        	require('FTerm').scratch({
        		cmd = { exec, buf, '&&', './a.out' }
        	})
        end
    end
end)

This had same result as I firstly tried. So I wonder to know how to set commands to auto compile and run statically-typed language.

Get buffer number of a terminal

Is it possible to get the buffer number of a custom terminal? I would like to be able to set a custom keymap for a specific terminal. This would also be useful for other buffer-local settings. Something like the (not working) example below:

local uvicorn = fterm:new {
    cmd = 'poetry run uvicorn api.main:app --host 0.0.0.0 --reload',
    ft = 'fterm__uvicorn'
}
vim.keymap.set(
    't',
    'q',
    function() uvicorn:close() end,
    { buffer = uvicorn:get_buf(), desc = 'Close uvicorn window' }
)

Behavior similar to the integrated terminal

I am creating a code runner like the one in vscode, but when executing the terminal it is immediately sawed and does not show the output. Attached how I would like it to behave, it is the output in the default terminal of neovim.
neovim term

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.