Skip to content

Commit ecb3c4c

Browse files
committed
terminal tooltips
1 parent d7bc55f commit ecb3c4c

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/runtime/console.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function activate (_ink) {
5252
terminal = ink.InkTerminal.fromId('julia-terminal', terminalOptions())
5353
terminal.setTitle('REPL', true)
5454
terminal.onDidOpenLink(hasKeyboardModifier)
55+
terminal.registerTooltipHandler(showTooltip, hideTooltip)
5556
terminal.class = 'julia-terminal'
5657

5758
subs.add(atom.config.observe('julia-client.uiOptions.layouts.console.defaultLocation', (defaultLocation) => {
@@ -179,6 +180,7 @@ function newTerminal (cwd) {
179180
const term = ink.InkTerminal.fromId(`terminal-julia-${Math.floor(Math.random()*10000000)}`, terminalOptions())
180181
term.attachCustomKeyEventHandler((e) => handleKeybinding(e, term))
181182
term.onDidOpenLink(hasKeyboardModifier)
183+
term.registerTooltipHandler(showTooltip, hideTooltip)
182184
addLinkHandler(term.terminal)
183185
shellPty(cwd).then(({pty, cwd}) => {
184186
term.attach(pty, true, cwd)
@@ -195,6 +197,7 @@ function newRemoteTerminal () {
195197
const term = ink.InkTerminal.fromId(`terminal-remote-julia-${Math.floor(Math.random()*10000000)}`, terminalOptions())
196198
term.attachCustomKeyEventHandler((e) => handleKeybinding(e, term))
197199
term.onDidOpenLink(hasKeyboardModifier)
200+
term.registerTooltipHandler(showTooltip, hideTooltip)
198201
addLinkHandler(term.terminal)
199202
remotePty().then(({pty, cwd, conf}) => {
200203
term.attach(pty, true, cwd)
@@ -274,9 +277,51 @@ function handleLink (event, uri) {
274277
function addLinkHandler (terminal) {
275278
terminal.registerLinkMatcher(uriRegex, handleLink, {
276279
willLinkActivate: ev => hasKeyboardModifier(ev),
280+
tooltipCallback: (ev, uri, location) => showTooltip(ev, uri, location, terminal),
281+
leaveCallback: () => hideTooltip()
277282
})
278283
}
279284

285+
let tooltip = null
286+
287+
function showTooltip (event, uri, location, terminal) {
288+
if (atom.config.get('julia-client.consoleOptions.linkModifier')) {
289+
let el = document.createElement('div')
290+
el.classList.add('terminal-link-tooltip')
291+
292+
const terminalRect = event.target.getBoundingClientRect()
293+
const colWidth = terminalRect.width / terminal.cols
294+
const rowHeight = terminalRect.height / terminal.rows
295+
296+
const leftPosition = location.start.x * colWidth + terminalRect.left
297+
const topPosition = (location.start.y - 1.5) * rowHeight + terminalRect.top
298+
299+
el.style.top = topPosition + 'px'
300+
el.style.left = leftPosition + 'px'
301+
302+
el.innerText = (process.platform == 'darwin' ? 'Cmd' : 'Ctrl') + '-Click to open link.'
303+
304+
tooltip = el
305+
document.body.appendChild(el)
306+
307+
return true
308+
} else {
309+
return false
310+
}
311+
}
312+
313+
function hideTooltip () {
314+
if (tooltip) {
315+
try {
316+
document.body.removeChild(tooltip)
317+
} catch (err) {
318+
319+
} finally {
320+
tooltip = null
321+
}
322+
}
323+
}
324+
280325
function handleKeybinding (e, term, binds = whitelistedKeybindingsTerminal) {
281326
if (process.platform !== 'win32' && e.keyCode === 13 && (e.altKey || e.metaKey) && e.type === 'keydown') {
282327
// Meta-Enter doesn't work properly with xterm.js atm, so we send the right escape sequence ourselves:

styles/julia-client.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,11 @@ atom-text-editor.editor[data-grammar$="source weave latex"] {
182182
}
183183
}
184184
}
185+
186+
.terminal-link-tooltip {
187+
z-index: 100;
188+
color: @text-color;
189+
background-color: @app-background-color;
190+
padding: 0.2em 0.5em;
191+
position: absolute;
192+
}

0 commit comments

Comments
 (0)