summaryrefslogtreecommitdiff
path: root/plugins/xC/fancy-prompt.lua
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-08-27 08:55:44 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-08-27 09:15:37 +0200
commitf7be510d2669646c60845b091087362d51ae29ea (patch)
treec66208c99c040ff6126ecd3ab6fd040f9acd812b /plugins/xC/fancy-prompt.lua
parent83764d1e1b7df02d788c323467fa44d993703e3a (diff)
downloadxK-f7be510d2669646c60845b091087362d51ae29ea.tar.gz
xK-f7be510d2669646c60845b091087362d51ae29ea.tar.xz
xK-f7be510d2669646c60845b091087362d51ae29ea.zip
xC: make fancy-prompt.lua alignment more reliable
And generally clean up that script.
Diffstat (limited to 'plugins/xC/fancy-prompt.lua')
-rw-r--r--plugins/xC/fancy-prompt.lua36
1 files changed, 22 insertions, 14 deletions
diff --git a/plugins/xC/fancy-prompt.lua b/plugins/xC/fancy-prompt.lua
index 8ec697a..0b7000c 100644
--- a/plugins/xC/fancy-prompt.lua
+++ b/plugins/xC/fancy-prompt.lua
@@ -1,7 +1,7 @@
--
-- fancy-prompt.lua: the fancy multiline prompt you probably want
--
--- Copyright (c) 2016, Přemysl Eric Janouch <p@janouch.name>
+-- Copyright (c) 2016 - 2022, Přemysl Eric Janouch <p@janouch.name>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted.
@@ -40,7 +40,7 @@ xC.hook_prompt (function (hook)
if buffer == current then
current_n = i
elseif buffer.new_messages_count ~= buffer.new_unimportant_count then
- if active ~= "" then active = active .. "," end
+ active = active .. ","
if buffer.highlighted then
active = active .. "!"
bg_color = "224"
@@ -48,7 +48,6 @@ xC.hook_prompt (function (hook)
active = active .. i
end
end
- if active ~= "" then active = "(" .. active .. ")" end
local x = current_n .. ":" .. current.name
if chan and chan.users_len ~= 0 then
local params = ""
@@ -56,25 +55,34 @@ xC.hook_prompt (function (hook)
params = params .. " +" .. mode .. " " .. param
end
local modes = chan.no_param_modes .. params:sub (3)
- if modes ~= "" then x = x .. "(+" .. modes .. ")" end
+ if modes ~= "" then
+ x = x .. "(+" .. modes .. ")"
+ end
x = x .. "{" .. chan.users_len .. "}"
end
- if current.hide_unimportant then x = x .. "<H>" end
-
- local lines, cols = xC.get_screen_size ()
- x = x .. " " .. active .. string.rep (" ", cols)
+ if current.hide_unimportant then
+ x = x .. "<H>"
+ end
+ if active ~= "" then
+ x = x .. " (" .. active:sub (2) .. ")"
+ end
-- Readline 7.0.003 seems to be broken and completely corrupts the prompt.
-- However 8.0.004 seems to be fine with these, as is libedit 20191231-3.1.
--x = x:gsub("[\128-\255]", "?")
- -- Cut off extra characters and apply formatting, including the hack.
- -- FIXME: this doesn't count with full-width or zero-width characters.
- -- We might want to export wcwidth() above term_from_utf8 somehow.
- local overflow = utf8.offset (x, cols - 1)
- if overflow then x = x:sub (1, overflow) end
+ -- Align to the terminal's width and apply formatting, including the hack.
+ local lines, cols = xC.get_screen_size ()
+ local trailing, width = " ", xC.measure (x)
+ while cols > 0 and width >= cols do
+ x = x:sub (1, utf8.offset (x, -1) - 1)
+ trailing, width = ">", xC.measure (x)
+ end
+
x = "\x01\x1b[0;4;1;38;5;16m\x1b[48;5;" .. bg_color .. "m\x02" ..
- x .. "\x01\x1b[0;4;1;7;38;5;" .. bg_color .. "m\x02 \x01\x1b[0;1m\x02"
+ x .. string.rep (" ", cols - width - 1) ..
+ "\x01\x1b[0;4;1;7;38;5;" .. bg_color .. "m\x02" ..
+ trailing .. "\x01\x1b[0;1m\x02"
local user_prefix = function (chan, user)
for i, chan_user in ipairs (chan.users) do