Skip to content

Commit 535dd8f

Browse files
authored
Merge pull request #657 from JunoLab/avi/moredirs
open terminal from a current directory
2 parents 4197db5 + af4666c commit 535dd8f

File tree

4 files changed

+71
-44
lines changed

4 files changed

+71
-44
lines changed

lib/package/commands.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports =
124124
'julia-client:work-in-current-folder': (ev) ->
125125
requireClient 'change working folder', ->
126126
juno.runtime.evaluation.cdHere(ev.target)
127-
'julia-client:activate-current-folder': (ev) ->
127+
'julia-client:activate-environment-in-current-folder': (ev) ->
128128
requireClient 'activate an environment', ->
129129
juno.runtime.evaluation.activateProject(ev.target)
130130
'julia-client:activate-default-environment': (ev) ->

lib/package/menu.coffee

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ module.exports =
3636
label: 'Working Directory'
3737
submenu: [
3838
{label: 'Current File\'s Folder', command: 'julia-client:work-in-current-folder'}
39-
{label: 'Current Project\'s Folder', command: 'julia-client:work-in-project-folder'}
39+
{label: 'Select Project Folder', command: 'julia-client:work-in-project-folder'}
4040
{label: 'Home Folder', command: 'julia-client:work-in-home-folder'}
4141
{label: 'Select...', command: 'julia-client:select-working-folder'}
4242
]
4343
}
44+
{
45+
label: 'Environment',
46+
submenu: [
47+
{label: 'Environment in Current File\'s Folder', command: 'julia-client:activate-environment-in-current-folder'}
48+
{label: 'Default Environment', command: 'julia-client:activate-default-environment'}
49+
]
50+
}
4451
{label: 'Select Working Module', command: 'julia-client:select-working-module'}
4552

4653
{type: 'separator'}
@@ -66,7 +73,13 @@ module.exports =
6673

6774
{type: 'separator'}
6875

69-
{label: 'New Terminal', command: 'julia-client:new-terminal'}
76+
{
77+
label: 'New Terminal'
78+
submenu: [
79+
{label: 'Current File\'s Folder', command: 'julia-client:new-terminal-from-current-folder'}
80+
{label: 'Select Project Folder', command: 'julia-client:new-terminal'}
81+
]
82+
}
7083
{label: 'New Remote Terminal', command: 'julia-client:new-remote-terminal'}
7184

7285
{type: 'separator'}

lib/runtime/console.js

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { client } from '../connection'
44
import { customEnv } from '../connection/process/basic'
55
import { CompositeDisposable } from 'atom'
66
import { paths } from '../misc'
7+
import evaluation from './evaluation'
78
import modules from './modules'
89
import * as pty from 'node-pty-prebuilt-multiarch'
910
import { debounce } from 'underscore-plus'
@@ -34,20 +35,21 @@ export function activate (_ink) {
3435

3536
process.env['TERM'] = 'xterm-256color'
3637

37-
subs.add(atom.config.observe('julia-client.consoleOptions.whitelistedKeybindingsREPL', (kbds) => {
38-
whitelistedKeybindingsREPL = kbds.map(s => s.toLowerCase())
39-
}))
40-
subs.add(atom.config.observe('julia-client.consoleOptions.whitelistedKeybindingsTerminal', (kbds) => {
41-
whitelistedKeybindingsTerminal = kbds.map(s => s.toLowerCase())
42-
}))
43-
subs.add(atom.config.observe('julia-client.consoleOptions.cursorStyle', updateTerminalSettings))
44-
subs.add(atom.config.observe('julia-client.consoleOptions.maximumConsoleSize', updateTerminalSettings))
45-
subs.add(atom.config.observe('julia-client.consoleOptions.macOptionIsMeta', updateTerminalSettings))
46-
subs.add(atom.config.observe('julia-client.consoleOptions.rendererType', updateTerminalSettings))
47-
subs.add(atom.config.observe('julia-client.consoleOptions.cursorBlink', updateTerminalSettings))
38+
subs.add(
39+
atom.config.observe('julia-client.consoleOptions.whitelistedKeybindingsREPL', (kbds) => {
40+
whitelistedKeybindingsREPL = kbds.map(s => s.toLowerCase())
41+
}),
42+
atom.config.observe('julia-client.consoleOptions.whitelistedKeybindingsTerminal', (kbds) => {
43+
whitelistedKeybindingsTerminal = kbds.map(s => s.toLowerCase())
44+
}),
45+
atom.config.observe('julia-client.consoleOptions.cursorStyle', updateTerminalSettings),
46+
atom.config.observe('julia-client.consoleOptions.maximumConsoleSize', updateTerminalSettings),
47+
atom.config.observe('julia-client.consoleOptions.macOptionIsMeta', updateTerminalSettings),
48+
atom.config.observe('julia-client.consoleOptions.rendererType', updateTerminalSettings),
49+
atom.config.observe('julia-client.consoleOptions.cursorBlink', updateTerminalSettings)
50+
)
4851

4952
terminal = ink.InkTerminal.fromId('julia-terminal', terminalOptions())
50-
5153
terminal.setTitle('REPL', true)
5254
terminal.class = 'julia-terminal'
5355

@@ -108,23 +110,38 @@ export function activate (_ink) {
108110
if (promptObserver) promptObserver.dispose()
109111
})
110112

111-
subs.add(atom.commands.add('atom-workspace', 'julia-client:open-REPL', () => {
112-
open().then(() => terminal.show())
113-
}))
114-
115-
subs.add(atom.commands.add('atom-workspace', 'julia-client:clear-REPL', () => {
116-
terminal.clear()
117-
}))
118-
119-
subs.add(atom.commands.add('.julia-terminal', 'julia-client:copy-or-interrupt', () => {
120-
if (!terminal.copySelection()) {
121-
atom.commands.dispatch(terminal.view, 'julia-client:interrupt-julia')
122-
}
123-
}))
124-
125-
subs.add(atom.commands.add('atom-workspace', 'julia-client:new-terminal', newTerminal))
126-
127-
subs.add(atom.commands.add('atom-workspace', 'julia-client:new-remote-terminal', newRemoteTerminal))
113+
subs.add(
114+
// repl commands
115+
atom.commands.add('atom-workspace', {
116+
'julia-client:open-REPL': () => {
117+
open().then(() => terminal.show())
118+
},
119+
'julia-client:clear-REPL': () => {
120+
terminal.clear()
121+
},
122+
}),
123+
atom.commands.add('.julia-terminal', {
124+
'julia-client:copy-or-interrupt': () => {
125+
if (!terminal.copySelection()) {
126+
atom.commands.dispatch(terminal.view, 'julia-client:interrupt-julia')
127+
}
128+
}
129+
}),
130+
// terminal commands
131+
atom.commands.add('atom-workspace', {
132+
'julia-client:new-terminal': () => {
133+
newTerminal()
134+
},
135+
'julia-client:new-terminal-from-current-folder': ev => {
136+
const dir = evaluation.currentDir(ev.target)
137+
if (!dir) return
138+
newTerminal(dir)
139+
},
140+
'julia-client:new-remote-terminal': () => {
141+
newRemoteTerminal()
142+
}
143+
})
144+
)
128145

129146
// handle deserialized terminals
130147
forEachPane(item => {
@@ -149,11 +166,11 @@ export function close () {
149166
return terminal.close()
150167
}
151168

152-
function newTerminal () {
169+
function newTerminal (cwd) {
153170
const term = ink.InkTerminal.fromId(`terminal-julia-${Math.floor(Math.random()*10000000)}`, terminalOptions())
154171
term.attachCustomKeyEventHandler((e) => handleKeybinding(e, term))
155172
addLinkHandler(term.terminal)
156-
shellPty().then(({pty, cwd}) => {
173+
shellPty(cwd).then(({pty, cwd}) => {
157174
term.attach(pty, true, cwd)
158175
term.setDefaultLocation(atom.config.get('julia-client.uiOptions.layouts.terminal.defaultLocation'))
159176
term.open({
@@ -294,8 +311,8 @@ function shellPty (cwd) {
294311
if (cwd) {
295312
pr = new Promise((resolve) => resolve(cwd))
296313
} else {
297-
const projectPaths = atom.workspace.project.getDirectories().map((el) => el.path)
298-
pr = selector.show(projectPaths, {
314+
// show project paths
315+
pr = selector.show(atom.project.getPaths(), {
299316
emptyMessage: 'Enter a custom path above.',
300317
allowCustom: true
301318
})
@@ -309,7 +326,7 @@ function shellPty (cwd) {
309326
})
310327
cwd = paths.home()
311328
}
312-
env = customEnv()
329+
const env = customEnv()
313330
resolve({
314331
pty: pty.fork(atom.config.get("julia-client.consoleOptions.shell"), [], {
315332
cols: 100,
@@ -334,11 +351,7 @@ export function deactivate () {
334351
item.detach()
335352
item.close()
336353
}, /terminal\-remote\-julia\-\d+/)
337-
if (terminal) {
338-
terminal.detach()
339-
}
340-
if (subs) {
341-
subs.dispose()
342-
}
354+
if (terminal) terminal.detach()
355+
if (subs) subs.dispose()
343356
subs = null
344357
}

menus/julia-client.cson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
label: 'Juno',
2525
submenu: [
2626
{ label: 'Work in Folder', command: 'julia-client:work-in-current-folder' }
27-
{ label: 'Activate Project', command: 'julia-client:activate-current-folder' }
27+
{ label: 'Activate Environment in Folder', command: 'julia-client:activate-environment-in-current-folder' }
28+
{ label: 'New Terminal from Folder', command: 'julia-client:new-terminal-from-current-folder'}
2829
]
2930
}
3031
{type: 'separator'}

0 commit comments

Comments
 (0)