forked from rndAdn/REPL-Nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReplView.coffee
executable file
·127 lines (112 loc) · 4.73 KB
/
ReplView.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fs = require 'fs'
REPL = require '../Repl/ReplClass'
REPLPython = require '../Repl/ReplClassPython'
REPLFormat = require '../Repl/ReplFormat'
stripAnsi = require 'strip-ansi'
{CompositeDisposable} = require 'event-kit'
module.exports =
class REPLView
dealWithInsert :(event) =>
buf = @replTextEditor.getCursorBufferPosition()
if !@ignore && (@lastBuf.row>buf.row || (@lastBuf.row == buf.row && @lastBuf.column > buf.column))
event.cancel()
interprete :(select) =>
#console.log(select)
@repl.writeInRepl(select,true)
remove :() =>
@subscribe.clear()
@repl.remove()
dealWithBackspace :() =>
buf = @replTextEditor.getCursorBufferPosition()
if(@lastBuf.row>buf.row || (@lastBuf.row == buf.row && @lastBuf.column >= buf.column))
@ignore = true
@replTextEditor.insertText(' ')
@ignore = false
return
dealWithDelete :() =>
'''Gerer suppression text Selection'''
buf = @replTextEditor.getCursorBufferPosition()
if(@lastBuf.row>buf.row || (@lastBuf.row == buf.row && @lastBuf.column > buf.column))
@ignore = true
@replTextEditor.insertText(' ')
@replTextEditor.moveLeft(1)
@ignore = false
return
dealWithEnter :() =>
#console.log('enter')
@replTextEditor.moveToBottom()
@replTextEditor.moveToEndOfLine()
buf = @replTextEditor.getCursorBufferPosition()
#console.log(@replTextEditor.getTextInBufferRange([@lastBuf,buf]))
@repl.writeInRepl(@replTextEditor.getTextInBufferRange([@lastBuf,buf])+'\n',false)
@lastBuf = buf
setGrammar : =>
grammars = atom.grammars.getGrammars()
gName = if @grammarName == 'Node' then 'JavaScript' else @grammarName
#console.log(grammars[0])
for grammar in grammars
if (grammar.name == gName)
#console.log(grammar)
@replTextEditor.setGrammar(grammar)
return
dealWithUp:()->
@replTextEditor.moveToEndOfLine()
buf = @replTextEditor.getCursorBufferPosition()
@repl.history(true,@replTextEditor.getTextInBufferRange([@lastBuf,buf]))
dealWithDown:()->
#console.log('down')
@replTextEditor.moveToEndOfLine()
buf = @replTextEditor.getCursorBufferPosition()
@repl.history(false,@replTextEditor.getTextInBufferRange([@lastBuf,buf]))
setTextEditor :(textEditor) =>
@replTextEditor = textEditor
#@replTextEditor.onDidChangeCursorPosition(@dealWithBuffer)
#@replTextEditor.onWillInsertText(@dealWithEnter)
@subscribe.add @replTextEditor.onWillInsertText(@dealWithInsert)
@subscribe.add textEditorElement = atom.views.getView(@replTextEditor)
@subscribe.add atom.commands.add textEditorElement, 'editor:newline': => @dealWithEnter()
@subscribe.add atom.commands.add textEditorElement, 'core:move-up': =>@dealWithUp()
@subscribe.add atom.commands.add textEditorElement, 'core:move-down': => @dealWithDown()
@subscribe.add atom.commands.add textEditorElement, 'core:backspace': => @dealWithBackspace()
@subscribe.add atom.commands.add textEditorElement, 'core:delete': => @dealWithDelete()
@setGrammar()
setRepl :(repl) =>
@repl = repl
dealWithRetour: (data,append) =>
if append
#console.log(@replTextEditor.constructor.name)
@replTextEditor.insertText(stripAnsi(""+data))
@lastBuf = @replTextEditor.getCursorBufferPosition()
else
'''
à amélioré , (saut de ligne et string vide etc...)
'''
@replTextEditor.moveToBottom()
@replTextEditor.moveToEndOfLine()
buf = @replTextEditor.getCursorBufferPosition()
@replTextEditor.setTextInBufferRange([@lastBuf,buf],(""+data),select = true)
#@replTextEditor.moveBottom(1)
#@replTextEditor.selectToBeginningOfLine()
#console.log(@replTextEditor.getSelectedText())
#@replTextEditor.moveToEndOfLine()
#@lastBuf = @replTextEditor.getCursorBufferPosition()
constructor: (@grammarName,file,callBackCreate) ->
self = this
@subscribe = new CompositeDisposable
format = new REPLFormat("../../Repls/"+file) # new REPLFormat(@key)
@lastBuf = 0
@ignore = false
#@minimaltext = ""
uri = "REPL: "+@grammarName
opts = split:'right' if atom.config.get('Repl.splitRight')
atom.workspace.open(uri, opts).done (textEditor) =>
pane = atom.workspace.getActivePane()
if(self.grammarName == "Python Console3" || self.grammarName == "Python Console2" || self.grammarName == "Python")
@grammarName = "Python Console"
self.setTextEditor(textEditor)
self.setRepl(new REPLPython(format,self.dealWithRetour))
else
if @grammarName == "OCaml" then @grammarName = "OCaml Toplevel"
self.setTextEditor(textEditor)
self.setRepl(new REPL(format,self.dealWithRetour))
callBackCreate(self,pane)