mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 11:59:40 -08:00
feat(cmd): add tooltip functionality
This commit is contained in:
parent
5c005f0fa8
commit
5ddb0d8896
|
@ -8,7 +8,7 @@ import Tabs from "@theme/Tabs";
|
|||
import TabItem from "@theme/TabItem";
|
||||
|
||||
:::info
|
||||
Due to limitations (or not having found a way just yet), this feature only works in `zsh` and `powershell` for
|
||||
Due to limitations (or not having found a way just yet), this feature only works in `zsh`, `powershell` and `cmd` (as of [clink][clink] version v1.2.46) for
|
||||
the time being.
|
||||
:::
|
||||
|
||||
|
@ -94,3 +94,5 @@ Restart your shell or reload `.zshrc` using `source ~/.zshrc` for the changes to
|
|||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
[clink]: https://chrisant996.github.io/clink/
|
||||
|
|
|
@ -217,7 +217,7 @@ func (e *engine) renderTooltip(tip string) string {
|
|||
Segments: []*Segment{tooltip},
|
||||
}
|
||||
switch e.env.getShellName() {
|
||||
case zsh:
|
||||
case zsh, winCMD:
|
||||
block.init(e.env, e.writer, e.ansi)
|
||||
return block.renderSegments()
|
||||
case pwsh, powershell5:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
local endedit_time
|
||||
local last_duration
|
||||
local tip_word
|
||||
|
||||
local function os_clock_millis()
|
||||
-- Clink v1.2.30 has a fix for Lua's os.clock() implementation failing after
|
||||
|
@ -56,6 +57,14 @@ function p:filter(prompt)
|
|||
return get_posh_prompt(false)
|
||||
end
|
||||
function p:rightfilter(prompt)
|
||||
if tip_word == nil then
|
||||
return get_posh_prompt(true), false
|
||||
end
|
||||
local prompt_exe = string.format('::OMP:: --config="::CONFIG::" --command="%s"', tip_word)
|
||||
tooltip = io.popen(prompt_exe):read("*a")
|
||||
if tooltip ~= "" then
|
||||
return tooltip, false
|
||||
end
|
||||
return get_posh_prompt(true), false
|
||||
end
|
||||
|
||||
|
@ -74,3 +83,19 @@ if clink.onbeginedit ~= nil and clink.onendedit ~= nil then
|
|||
clink.onbeginedit(builtin_modules_onbeginedit)
|
||||
clink.onendedit(builtin_modules_onendedit)
|
||||
end
|
||||
|
||||
-- Tooltips
|
||||
|
||||
function ohmyposh_space(rl_buffer)
|
||||
rl_buffer:insert(" ")
|
||||
local words = string.explode(rl_buffer:getbuffer(), ' ', [["]])
|
||||
if words[1] ~= tip_word then
|
||||
tip_word = words[1] -- remember the first word for use when filtering the prompt
|
||||
clink.refilterprompt() -- invoke the prompt filters so omp can update the prompt per the tip word
|
||||
end
|
||||
end
|
||||
|
||||
if rl.setbinding then
|
||||
clink.onbeginedit(function () tip_word = nil end)
|
||||
rl.setbinding(' ', [["luafunc:ohmyposh_space"]], 'emacs')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue