Flutter Logs autoscroll working
This commit is contained in:
@@ -5,37 +5,23 @@ return {
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
"stevearc/dressing.nvim",
|
||||
"m00qek/baleia.nvim",
|
||||
},
|
||||
config = function()
|
||||
vim.opt.termguicolors = true
|
||||
vim.env.FLUTTER_FORCE_COLOR = "1"
|
||||
|
||||
local baleia = require("baleia").setup({
|
||||
strip_ansi_codes = true,
|
||||
})
|
||||
|
||||
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWinEnter", {
|
||||
pattern = "*__FLUTTER_DEV_LOG__*",
|
||||
callback = function(args)
|
||||
local bufnr = args.buf
|
||||
|
||||
if not vim.bo[bufnr].modifiable then
|
||||
vim.bo[bufnr].modifiable = true
|
||||
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
|
||||
vim.api.nvim_create_autocmd({ "TextChanged", "BufWinEnter" }, {
|
||||
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
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local last_line = vim.api.nvim_buf_line_count(buf)
|
||||
-- Only scroll if we aren't currently in Insert mode
|
||||
if vim.api.nvim_get_mode().mode ~= 'i' then
|
||||
vim.api.nvim_win_set_cursor(win, { last_line, 0 })
|
||||
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
|
||||
local user_command = vim.api.nvim_create_user_command
|
||||
|
||||
Reference in New Issue
Block a user