Skip to content

Custom component functions #34

Answered by rootiest
rootiest asked this question in Q&A
Discussion options

You must be logged in to vote

Scratch that, I figured out why it wasn't working.

I overlooked that tab_index was changed to index very recently and was trying to use the incorrect component name for my tabline version.

Here is my code if anyone wants to do the same:

-- Function to convert a number to its ordinal string representation
local function ordinal(n)
	local suffixes = { "th", "st", "nd", "rd" }
	local mod100 = n % 100
	return n .. (suffixes[(mod100 - 20) % 10 + 1] or suffixes[1])
end

Then this component:

{
	"index",
	fmt = function(n)
		return ordinal(n)
	end,
	padding = { left = 0, right = 0 },
},

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by michaelbrusegard
Comment options

You must be logged in to vote
1 reply
@rootiest
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants