Skip to content

Commit 813a886

Browse files
authored
Merge pull request #702 from JunoLab/sp/terminaltooltips
terminal tooltips
2 parents b2ecd30 + b37a34b commit 813a886

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

lib/julia-client.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ toolbar = require './package/toolbar'
88
semver = require 'semver'
99

1010
# TODO: Update me when tagging a new relase:
11-
INK_VERSION_COMPAT = "^0.12.2"
11+
INK_VERSION_COMPAT = "^0.12.3"
1212

1313
INK_LINK = '[`ink`](https://github.com/JunoLab/atom-ink)'
1414
LANGUAGE_JULIA_LINK = '[`language-julia`](https://github.com/JuliaEditorSupport/atom-language-julia)'

lib/runtime/console.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ import * as ssh from 'ssh2'
1515
const { changeprompt, changemodule, fullpath } =
1616
client.import({ msg: ['changeprompt', 'changemodule', 'resetprompt'], rpc: ['validatepath', 'fullpath'] })
1717

18-
let uriRegex
19-
if (process.platform === 'win32') {
20-
uriRegex = /(@ ([^\s]+)\s(.*?)\:(\d+)|((([a-zA-Z]:|\.\.?|\~)|([^\0<>\?\|\/\s!$`&*()\[\]+'":;])+)?((\\|\/)([^\0<>\?\|\/\s!$`&*()\[\]+'":;])+)+)(\:\d+)?)/
21-
} else {
22-
uriRegex = /(@ ([^\s]+)\s(.*?)\:(\d+)|(((\.\.?|\~)|([^\0\s!$`&*()\[\]+'":;\\])+)?(\/([^\0\s!$`&*()\[\]+'":;\\])+)+)(\:\d+)?)/
23-
}
18+
const isWindows = process.platform === 'win32'
19+
const uriRegex = isWindows ?
20+
/(@ ([^\s]+)\s(.*?)\:(\d+)|((([a-zA-Z]:|\.\.?|\~)|([^\0<>\?\|\/\s!$`&*()\[\]+'":;])+)?((\\|\/)([^\0<>\?\|\/\s!$`&*()\[\]+'":;])+)+)(\:\d+)?)/ :
21+
/(@ ([^\s]+)\s(.*?)\:(\d+)|(((\.\.?|\~)|([^\0\s!$`&*()\[\]+'":;\\])+)?(\/([^\0\s!$`&*()\[\]+'":;\\])+)+)(\:\d+)?)/
2422

2523
var whitelistedKeybindingsREPL = []
2624
var whitelistedKeybindingsTerminal = []
@@ -52,6 +50,7 @@ export function activate (_ink) {
5250
terminal = ink.InkTerminal.fromId('julia-terminal', terminalOptions())
5351
terminal.setTitle('REPL', true)
5452
terminal.onDidOpenLink(hasKeyboardModifier)
53+
terminal.registerTooltipHandler(showTooltip, hideTooltip)
5554
terminal.class = 'julia-terminal'
5655

5756
subs.add(atom.config.observe('julia-client.uiOptions.layouts.console.defaultLocation', (defaultLocation) => {
@@ -157,6 +156,7 @@ export function activate (_ink) {
157156
item.attachCustomKeyEventHandler((e) => handleKeybinding(e, item))
158157
addLinkHandler(item.terminal)
159158
item.onDidOpenLink(hasKeyboardModifier)
159+
item.registerTooltipHandler(showTooltip, hideTooltip)
160160
shellPty(item.persistentState.cwd)
161161
.then(({pty, cwd}) => item.attach(pty, true, cwd))
162162
.catch(() => {})
@@ -179,6 +179,7 @@ function newTerminal (cwd) {
179179
const term = ink.InkTerminal.fromId(`terminal-julia-${Math.floor(Math.random()*10000000)}`, terminalOptions())
180180
term.attachCustomKeyEventHandler((e) => handleKeybinding(e, term))
181181
term.onDidOpenLink(hasKeyboardModifier)
182+
term.registerTooltipHandler(showTooltip, hideTooltip)
182183
addLinkHandler(term.terminal)
183184
shellPty(cwd).then(({pty, cwd}) => {
184185
term.attach(pty, true, cwd)
@@ -195,6 +196,7 @@ function newRemoteTerminal () {
195196
const term = ink.InkTerminal.fromId(`terminal-remote-julia-${Math.floor(Math.random()*10000000)}`, terminalOptions())
196197
term.attachCustomKeyEventHandler((e) => handleKeybinding(e, term))
197198
term.onDidOpenLink(hasKeyboardModifier)
199+
term.registerTooltipHandler(showTooltip, hideTooltip)
198200
addLinkHandler(term.terminal)
199201
remotePty().then(({pty, cwd, conf}) => {
200202
term.attach(pty, true, cwd)
@@ -260,7 +262,10 @@ function handleLink (event, uri) {
260262
pending: atom.config.get('core.allowPendingPaneItems')
261263
})
262264
} else {
263-
urimatch = uri.match(/([^\:]+)(?:\:(\d+))?/)
265+
const matchregex = isWindows ?
266+
/(([a-zA-Z]\:)?[^\:]+)(?:\:(\d+))?/ :
267+
/([^\:]+)(?:\:(\d+))?/
268+
urimatch = uri.match(matchregex)
264269
if (urimatch) {
265270
const line = urimatch[2] !== null ? parseInt(urimatch[2]) : 0
266271
ink.Opener.open(urimatch[1], line - 1, {
@@ -274,9 +279,53 @@ function handleLink (event, uri) {
274279
function addLinkHandler (terminal) {
275280
terminal.registerLinkMatcher(uriRegex, handleLink, {
276281
willLinkActivate: ev => hasKeyboardModifier(ev),
282+
tooltipCallback: (ev, uri, location) => showTooltip(ev, uri, location, terminal),
283+
leaveCallback: () => hideTooltip()
277284
})
278285
}
279286

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

styles/julia-client.less

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,12 @@ 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+
border: 1px solid fade(@text-color, 70%);
193+
}

0 commit comments

Comments
 (0)