@@ -4,6 +4,7 @@ import { client } from '../connection'
4
4
import { customEnv } from '../connection/process/basic'
5
5
import { CompositeDisposable } from 'atom'
6
6
import { paths } from '../misc'
7
+ import evaluation from './evaluation'
7
8
import modules from './modules'
8
9
import * as pty from 'node-pty-prebuilt-multiarch'
9
10
import { debounce } from 'underscore-plus'
@@ -34,20 +35,21 @@ export function activate (_ink) {
34
35
35
36
process . env [ 'TERM' ] = 'xterm-256color'
36
37
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
+ )
48
51
49
52
terminal = ink . InkTerminal . fromId ( 'julia-terminal' , terminalOptions ( ) )
50
-
51
53
terminal . setTitle ( 'REPL' , true )
52
54
terminal . class = 'julia-terminal'
53
55
@@ -108,23 +110,38 @@ export function activate (_ink) {
108
110
if ( promptObserver ) promptObserver . dispose ( )
109
111
} )
110
112
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
+ )
128
145
129
146
// handle deserialized terminals
130
147
forEachPane ( item => {
@@ -149,11 +166,11 @@ export function close () {
149
166
return terminal . close ( )
150
167
}
151
168
152
- function newTerminal ( ) {
169
+ function newTerminal ( cwd ) {
153
170
const term = ink . InkTerminal . fromId ( `terminal-julia-${ Math . floor ( Math . random ( ) * 10000000 ) } ` , terminalOptions ( ) )
154
171
term . attachCustomKeyEventHandler ( ( e ) => handleKeybinding ( e , term ) )
155
172
addLinkHandler ( term . terminal )
156
- shellPty ( ) . then ( ( { pty, cwd} ) => {
173
+ shellPty ( cwd ) . then ( ( { pty, cwd} ) => {
157
174
term . attach ( pty , true , cwd )
158
175
term . setDefaultLocation ( atom . config . get ( 'julia-client.uiOptions.layouts.terminal.defaultLocation' ) )
159
176
term . open ( {
@@ -294,8 +311,8 @@ function shellPty (cwd) {
294
311
if ( cwd ) {
295
312
pr = new Promise ( ( resolve ) => resolve ( cwd ) )
296
313
} 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 ( ) , {
299
316
emptyMessage : 'Enter a custom path above.' ,
300
317
allowCustom : true
301
318
} )
@@ -309,7 +326,7 @@ function shellPty (cwd) {
309
326
} )
310
327
cwd = paths . home ( )
311
328
}
312
- env = customEnv ( )
329
+ const env = customEnv ( )
313
330
resolve ( {
314
331
pty : pty . fork ( atom . config . get ( "julia-client.consoleOptions.shell" ) , [ ] , {
315
332
cols : 100 ,
@@ -334,11 +351,7 @@ export function deactivate () {
334
351
item . detach ( )
335
352
item . close ( )
336
353
} , / t e r m i n a l \- r e m o t e \- j u l i a \- \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 ( )
343
356
subs = null
344
357
}
0 commit comments