Add keyboard layout indicator (RU/EN) to lualine

Green background for EN, red for RU. Uses im-select on macOS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-02-24 00:12:29 +03:00
parent 5977cc1b4d
commit 26befe3de4

View File

@@ -1,3 +1,29 @@
local function keyboard_layout()
local handle = io.popen("im-select")
if not handle then
return ""
end
local result = handle:read("*a")
handle:close()
if result:find("Russian") then
return "RU"
end
return "EN"
end
local function keyboard_layout_color()
local handle = io.popen("im-select")
if not handle then
return { bg = "#a6e3a1", fg = "#1e1e2e", gui = "bold" }
end
local result = handle:read("*a")
handle:close()
if result:find("Russian") then
return { bg = "#f38ba8", fg = "#1e1e2e", gui = "bold" }
end
return { bg = "#a6e3a1", fg = "#1e1e2e", gui = "bold" }
end
return {
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
@@ -9,7 +35,12 @@ return {
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_b = {
{ keyboard_layout, color = keyboard_layout_color },
"branch",
"diff",
"diagnostics",
},
lualine_c = { { "filename", path = 1 } },
lualine_x = { "encoding", "filetype" },
lualine_y = { "progress" },