-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hs.styledtext support to hs.chooser #1624
Comments
@latenitefilms do you mean to the search box, or the results? |
Results would be amazing! |
Note to self:
|
So, I think the branch I just pushed should address this, but I can't get it to actually do anything. I can see from the debugger that diff --git a/Spoons/Seal.spoon/seal_apps.lua b/Spoons/Seal.spoon/seal_apps.lua
index 5cb3111..cda6f77 100644
--- a/Spoons/Seal.spoon/seal_apps.lua
+++ b/Spoons/Seal.spoon/seal_apps.lua
@@ -79,7 +79,10 @@ function obj.choicesApps(query)
instances = hs.application.applicationsForBundleID(app["bundleID"])
end
if #instances > 0 then
- choice["text"] = name .. " (Running)"
+-- choice["text"] = name .. " (Running)"
+ styled = hs.styledtext.new(name .. " (Running)")
+ styled:setStyle({color=hs.drawing.color.hammerspoon.osx_red}, -9, -1)
+ choice["text"] = styled
else
choice["text"] = name
end I've never used |
@latenitefilms maybe you could try my branch and let me know if you get any luck with it? |
@cmsj - Soooooooo close! The Maybe this line is the issue? Here's my testing code: local chooser = require("hs.chooser")
local console = require("hs.console")
local inspect = require("hs.inspect")
local styledtext = require("hs.styledtext")
local completionFn = function(result)
print(string.format("Result: %s", result and inspect(result)))
end
local fancyText = styledtext.new("First Choice", {
color = {hex = "#FF0000", alpha = 1},
font = { name = "Futura", size = 20 },
})
local fancySubText = styledtext.new("This is the subtext of the first choice", {
color = {hex = "#FF0000", alpha = 1},
font = { name = "Futura", size = 20 },
})
console.printStyledtext(fancyText)
console.printStyledtext(fancySubText)
local choices = {
{
["text"] = fancyText,
["subText"] = fancySubText,
["uuid"] = "0001"
},
{
["text"] = "Second Option",
["subText"] = "I wonder what I should type here?",
["uuid"] = "Bbbb"
},
{
["text"] = "Third Possibility",
["subText"] = "What a lot of choosing there is going on here!",
["uuid"] = "III3"
},
}
theChooser = chooser.new(completionFn)
:choices(choices)
:show() |
@latenitefilms try now? |
No luck I'm afraid. Here's my test code: local chooser = require("hs.chooser")
local console = require("hs.console")
local inspect = require("hs.inspect")
local styledtext = require("hs.styledtext")
console.clearConsole()
local completionFn = function(result)
print(string.format("Result: %s", result and inspect(result)))
print("text:")
console.printStyledtext(result.text)
print("subText:")
console.printStyledtext(result.subText)
end
local text = styledtext.new("First Choice", {
color = {hex = "#FF0000", alpha = 1},
font = { name = "Futura", size = 20 },
})
local subText = styledtext.new("This is the subtext of the first choice", {
color = {hex = "#FF0000", alpha = 1},
font = { name = "Futura", size = 20 },
})
print("text:")
console.printStyledtext(text)
print("subText:")
console.printStyledtext(subText)
local choices = {
{
["text"] = text,
["subText"] = subText,
["uuid"] = "1"
},
{
["text"] = text,
["subText"] = subText,
["uuid"] = "2"
},
{
["text"] = text,
["subText"] = subText,
["uuid"] = "3"
},
}
theChooser = chooser.new(completionFn)
:choices(choices)
:show() This is what it looks like: Console looks like this: I'll keep trying to work out why Thanks for all your help!! |
@cmsj - Note, you need to remove the second value from both the Text row without the subtext and the one below it without. |
This test code: local chooser = require("hs.chooser")
local console = require("hs.console")
local inspect = require("hs.inspect")
local styledtext = require("hs.styledtext")
console.clearConsole()
local completionFn = function(result)
print(string.format("Result: %s", result and inspect(result)))
print("text:")
console.printStyledtext(result.text)
print("subText:")
console.printStyledtext(result.subText)
end
local text = styledtext.new("Styled Text", {
color = {hex = "#FF0000", alpha = 1},
font = { name = "Futura", size = 18 },
})
local subText = styledtext.new("Styled Subtext", {
color = {hex = "#800000", alpha = 1},
font = { name = "Futura", size = 10 },
})
print("text:")
console.printStyledtext(text)
print("subText:")
console.printStyledtext(subText)
local choices = {
{
["text"] = text,
["subText"] = subText,
["uuid"] = "1"
},
{
["text"] = "Plain Text",
["subText"] = "Plain Text Subchoice",
["uuid"] = "2"
},
{
["text"] = text,
["uuid"] = "3"
},
{
["text"] = "Plain Text",
["uuid"] = "3"
},
}
theChooser = chooser.new(completionFn)
:choices(choices)
:show() ...gives me: |
…ing hs.styledtext in Chooser choices. Closes Hammerspoon#1624
@latenitefilms good catch! thanks :) |
@cmsj - Amazing! THANK YOU! Is it worth adding a note that |
Good point :) |
@cmsj - Not sure what's changed, but this now seems to be broken in 0.9.66? Using the same test code above, now gives me: I think maybe something has gone funky in LuaSkin - given we're also seeing this: Thoughts? |
Doh! Sorry - ignore me, I was testing in 0.9.66, rather than the latest |
@cmsj - Ok, I've worked out what's broken - but not sure how to fix. This works: local chooser = require("hs.chooser")
local console = require("hs.console")
local inspect = require("hs.inspect")
local styledtext = require("hs.styledtext")
console.clearConsole()
local completionFn = function(result)
print(string.format("Result: %s", result and inspect(result)))
print("text:")
console.printStyledtext(result.text)
print("subText:")
console.printStyledtext(result.subText)
end
local text = styledtext.new("Styled Text", {
color = {hex = "#FF0000", alpha = 1},
font = { name = "Futura", size = 18 },
})
local subText = styledtext.new("Styled Subtext", {
color = {hex = "#800000", alpha = 1},
font = { name = "Futura", size = 10 },
})
print("text:")
console.printStyledtext(text)
print("subText:")
console.printStyledtext(subText)
local choices = {}
for i, v in pairs(styledtext.fontNames()) do
local choice = {}
if string.sub(v, 1, 1) ~= "." then
local displayName = styledtext.fontInfo(v).displayName
choice.text = styledtext.new(displayName, {
font = { name = v, size = 18 },
})
choice.subText = ""
choice.uuid = choice.text
table.insert(choices, choice)
end
end
theChooser = chooser.new(completionFn)
:choices(choices)
:show() ...but if you remove Any ideas? |
@cmsj - I was thinking about using
hs.chooser
as a font selection tool. Is it possible to addhs.styledtext
support tohs.chooser
?To clarify, it would be great if the "text" and "subText" for each individual "choice" could be a
hs.styledtext
object - so that I could usehs.chooser
as a font selection tool (i.e. each result will be displayed as a different font).The text was updated successfully, but these errors were encountered: