Flutter Logs autoscroll working

This commit is contained in:
2026-04-17 15:03:01 +02:00
parent c8d4ea3cd1
commit 43b72217c1
2 changed files with 12 additions and 49 deletions

View File

@@ -1,7 +1,6 @@
{ {
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
"LuaSnip": { "branch": "master", "commit": "a62e1083a3cfe8b6b206e7d3d33a51091df25357" }, "LuaSnip": { "branch": "master", "commit": "a62e1083a3cfe8b6b206e7d3d33a51091df25357" },
"baleia.nvim": { "branch": "main", "commit": "32617940adb2eea56e85a64883a19961ceac9641" },
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
"cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" },
"cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" },

View File

@@ -5,37 +5,23 @@ return {
dependencies = { dependencies = {
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
"stevearc/dressing.nvim", "stevearc/dressing.nvim",
"m00qek/baleia.nvim",
}, },
config = function() config = function()
vim.opt.termguicolors = true vim.opt.termguicolors = true
vim.env.FLUTTER_FORCE_COLOR = "1" vim.env.FLUTTER_FORCE_COLOR = "1"
local baleia = require("baleia").setup({ vim.api.nvim_create_autocmd({ "TextChanged", "BufWinEnter" }, {
strip_ansi_codes = true, pattern = "*__FLUTTER_DEV_LOG__*", -- Default name for flutter-tools logs
}) callback = function()
local buf = vim.api.nvim_get_current_buf()
-- Check if we are in the log buffer
if vim.bo[buf].filetype == "log" or vim.fn.bufname(buf):match("flutter%-dev%.log") then
vim.api.nvim_create_autocmd("BufWinEnter", { local win = vim.api.nvim_get_current_win()
pattern = "*__FLUTTER_DEV_LOG__*", local last_line = vim.api.nvim_buf_line_count(buf)
callback = function(args) -- Only scroll if we aren't currently in Insert mode
local bufnr = args.buf if vim.api.nvim_get_mode().mode ~= 'i' then
vim.api.nvim_win_set_cursor(win, { last_line, 0 })
if not vim.bo[bufnr].modifiable then
vim.bo[bufnr].modifiable = true
end end
baleia.automatically(bufnr)
end,
})
vim.api.nvim_create_autocmd("OptionSet", {
pattern = "modifiable",
callback = function(args)
local bufnr = args.buf
if not vim.bo[bufnr].modifiable then
vim.bo[bufnr].modifiable = true
end end
end, end,
}) })
@@ -69,28 +55,6 @@ return {
}, },
}) })
-- Some Flutter log lines include ANSI start codes but no explicit reset.
-- Baleia keeps style state across lines, so missing reset can "bleed"
-- colors into following lines. Normalize those log lines first.
do
local ok, flutter_log = pcall(require, "flutter-tools.log")
if ok and flutter_log and type(flutter_log.log) == "function" then
local raw_log = flutter_log.log
local ansi_pattern = "\27%[[0-9;]*m"
local ansi_reset = "\27[0m"
flutter_log.log = function(data)
if type(data) == "string" then
local has_ansi = data:find(ansi_pattern) ~= nil
local has_reset = data:find("\27%[0m") ~= nil
if has_ansi and not has_reset then
data = data .. ansi_reset
end
end
raw_log(data)
end
end
end
-- Custom Shorthand Commands -- Custom Shorthand Commands
local user_command = vim.api.nvim_create_user_command local user_command = vim.api.nvim_create_user_command