From 654c4779a42575d12edd8177e70263d63ae39833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Badst=C3=BCbner?= Date: Wed, 14 Aug 2024 12:48:11 +0200 Subject: [PATCH] feat: add ability to filter flutter output in dev log (#371) --- README.md | 3 +++ lua/flutter-tools/config.lua | 1 + lua/flutter-tools/log.lua | 1 + 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index d349d9c0..b07d4d6a 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,9 @@ require("flutter-tools").setup { }, dev_log = { enabled = true, + filter = nil, -- optional callback to filter the log + -- takes a log_line as string argument; returns a boolean or nil; + -- the log_line is only added to the output if the function returns true notify_errors = false, -- if there is an error whilst running then notify the user open_cmd = "tabedit", -- command to use to open the log buffer }, diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index 5ec27c18..9d57c5ea 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -128,6 +128,7 @@ local config = { __index = function(_, k) return k == "open_cmd" and get_split_cmd(0.3, 40) or nil end, }), dev_log = setmetatable({ + filter = nil, enabled = true, notify_errors = false, }, { diff --git a/lua/flutter-tools/log.lua b/lua/flutter-tools/log.lua index d4d18b2b..18ad5736 100644 --- a/lua/flutter-tools/log.lua +++ b/lua/flutter-tools/log.lua @@ -87,6 +87,7 @@ end function M.log(data, opts) if opts.enabled then if not exists() then create(opts) end + if opts.filter and not opts.filter(data) then return end append(M.buf, { data }) autoscroll(M.buf, M.win) end