akinsho / toggleterm.nvim

A neovim lua plugin to help easily manage multiple terminal windows
GNU General Public License v3.0
4.38k stars 176 forks source link

[BUG] escaping appeared with starship #615

Closed sharpchen closed 2 weeks ago

sharpchen commented 3 weeks ago

Is there an existing issue for this?

Current Behavior

Inside toggleterm image

Expected Behavior

In normal terminal image

Steps To Reproduce

starship config ```toml "$schema" = 'https://starship.rs/config-schema.json' add_newline = true format = '$all' [aws] disabled = true [battery] disabled = true [cmd_duration] [directory] truncation_length = 3 [dotnet] symbol = ' ' format = '[$symbol($version )($tfm)]($style)' [env_var] disabled = true [elm] symbol = " " [git_branch] [git_commit] disabled = false commit_hash_length = 4 tag_disabled = false [git_state] disabled = true [git_status] [golang] symbol = "󰟓 " [kubernetes] symbol = "⎈ " [line_break] disabled = false [memory_usage] disabled = true [java] symbol = " " [julia] symbol = " " [nodejs] symbol = "" [package] symbol = "📦" [rust] symbol = '󱘗' [time] disabled = true [username] disabled = false ```
toggleterm config ```lua return { 'akinsho/toggleterm.nvim', version = '*', init = function() end, config = function() vim.o.shell = vim .iter({ 'bash', 'nu', 'pwsh', 'zsh' }) :filter(function(x) return vim.fn.executable(x) == 1 end) :peek() require('toggleterm').setup({ start_in_insert = true, direction = 'float', float_opts = { border = 'rounded', }, }) local Terminal = require('toggleterm.terminal').Terminal local rootTerm = Terminal:new({ count = 1 }) local bufTerm = Terminal:new({ count = 5 }) local bufPath = nil vim.keymap.set({ 'n', 'x', 't', 'v' }, '', function() rootTerm:toggle() end) vim.keymap.set({ 'n', 'x', 't', 'v' }, '', function() ---@type string local path = require('plenary.path'):new({ vim.api.nvim_buf_get_name(0) }):parent().filename if vim.fn.isdirectory(path) == 1 then local path_changed = path ~= bufPath bufPath = path_changed and path or bufPath if path_changed then if not bufTerm:is_open() then bufTerm:toggle() bufTerm:toggle() end if vim.o.shell == 'bash' then bufTerm:send({ ("cd '%s'; history -d $(history 1)"):format(path), 'clear; history -d $(history 1)' }) else bufTerm:send({ ("cd '%s'"):format(path), vim.o.shell == 'pwsh' and 'cls' or 'clear' }) end end end bufTerm:toggle() if vim.fn.mode() == 'n' and vim.o.filetype == 'toggleterm' then vim.cmd('execute "normal! i"') end end) vim.api.nvim_create_autocmd({ 'TermEnter' }, { callback = function() for _, buffers in ipairs(vim.fn.getbufinfo()) do local filetype = vim.api.nvim_buf_get_option(buffers.bufnr, 'filetype') if filetype == 'toggleterm' then vim.api.nvim_create_autocmd({ 'BufWriteCmd', 'FileWriteCmd', 'FileAppendCmd' }, { buffer = buffers.bufnr, command = 'q!', }) end end end, }) end, } ```
### Environment ```Markdown - OS: ArchWSL { machine = "x86_64", release = "5.15.153.1-microsoft-standard-WSL2", sysname = "Linux", version = "#1 SMP Fri Mar 29 23:14:13 UTC 2024" } - neovim version: NVIM v0.10.1 - Shell: bash ``` ### Anything else? _No response_
pierrot-lc commented 2 weeks ago

I have the same issue. I don't think that it is an issue related to toggleterm since if you open a standard neovim terminal (:term) the issue is also appearing.

Also, I only experience the issue when I'm inside a devShell.

akinsho commented 2 weeks ago

@pierrot-lc is right thanks for jumping in. Basically this plugin doesn't control how anything in the terminal is rendered only neovim can control that at a lower level. So this issue is likely somewhere between your shell, neovim and your prompt tool not here.

sharpchen commented 2 weeks ago

It seems manually set vim.o.shell = 'bash' causes the problem. Use default value fixed the problem.

return {
  'akinsho/toggleterm.nvim',
  version = '*',
  init = function() end,
  config = function()
-   vim.o.shell = vim
-   .iter({ 'bash', 'nu', 'zsh' })
-   :filter(function(x)
-     return vim.fn.executable(x) == 1
-   end)
-   :peek()

    require('toggleterm').setup({
      start_in_insert = true,
      direction = 'float',
      float_opts = {
        border = 'rounded',
      },
    })
  end,
}