Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
46944c93
Commit
46944c93
authored
Sep 06, 2017
by
yann300
Committed by
GitHub
Sep 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #769 from ethereum/terminalFilter
add terminal menu bar with clear/filter/..
parents
a7e14ad1
3762100a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
314 additions
and
165 deletions
+314
-165
txLogger.js
src/app/execution/txLogger.js
+15
-9
file-explorer.js
src/app/files/file-explorer.js
+0
-1
editor-panel.js
src/app/panels/editor-panel.js
+50
-7
terminal.js
src/app/panels/terminal.js
+247
-146
compiling.js
test-browser/tests/compiling.js
+2
-2
No files found.
src/app/execution/txLogger.js
View file @
46944c93
...
@@ -16,19 +16,25 @@ class TxLogger {
...
@@ -16,19 +16,25 @@ class TxLogger {
constructor
(
opts
=
{})
{
constructor
(
opts
=
{})
{
this
.
event
=
new
EventManager
()
this
.
event
=
new
EventManager
()
this
.
opts
=
opts
this
.
opts
=
opts
opts
.
api
.
editorpanel
.
registerLogType
(
'knownTransaction'
,
(
data
)
=>
{
this
.
logKnownTX
=
opts
.
api
.
editorpanel
.
registerCommand
(
'knownTransaction'
,
(
args
,
cmds
,
append
)
=>
{
return
renderKnownTransaction
(
this
,
data
)
var
data
=
args
[
0
]
var
el
=
renderKnownTransaction
(
this
,
data
)
append
(
el
)
})
})
opts
.
api
.
editorpanel
.
registerLogType
(
'unknownTransaction'
,
(
data
)
=>
{
this
.
logUnknownTX
=
opts
.
api
.
editorpanel
.
registerCommand
(
'unknownTransaction'
,
(
args
,
cmds
,
append
)
=>
{
return
renderUnknownTransaction
(
this
,
data
)
var
data
=
args
[
0
]
var
el
=
renderUnknownTransaction
(
this
,
data
)
append
(
el
)
})
})
opts
.
api
.
editorpanel
.
registerLogType
(
'emptyBlock'
,
(
data
)
=>
{
this
.
logEmptyBlock
=
opts
.
api
.
editorpanel
.
registerCommand
(
'emptyBlock'
,
(
args
,
cmds
,
append
)
=>
{
return
renderEmptyBlock
(
this
,
data
)
var
data
=
args
[
0
]
var
el
=
renderEmptyBlock
(
this
,
data
)
append
(
el
)
})
})
opts
.
events
.
txListener
.
register
(
'newBlock'
,
(
block
)
=>
{
opts
.
events
.
txListener
.
register
(
'newBlock'
,
(
block
)
=>
{
if
(
!
block
.
transactions
.
length
)
{
if
(
!
block
.
transactions
.
length
)
{
opts
.
api
.
editorpanel
.
log
({
type
:
'emptyBlock'
,
value
:
{
block
:
block
}
})
this
.
logEmptyBlock
({
block
:
block
})
}
}
})
})
...
@@ -43,12 +49,12 @@ function log (self, tx, api) {
...
@@ -43,12 +49,12 @@ function log (self, tx, api) {
if
(
resolvedTransaction
)
{
if
(
resolvedTransaction
)
{
api
.
parseLogs
(
tx
,
resolvedTransaction
.
contractName
,
api
.
compiledContracts
(),
(
error
,
logs
)
=>
{
api
.
parseLogs
(
tx
,
resolvedTransaction
.
contractName
,
api
.
compiledContracts
(),
(
error
,
logs
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
api
.
editorpanel
.
log
({
type
:
'knownTransaction'
,
value
:
{
tx
:
tx
,
resolvedData
:
resolvedTransaction
,
logs
:
logs
}
})
self
.
logKnownTX
({
tx
:
tx
,
resolvedData
:
resolvedTransaction
,
logs
:
logs
})
}
}
})
})
}
else
{
}
else
{
// contract unknown - just displaying raw tx.
// contract unknown - just displaying raw tx.
api
.
editorpanel
.
log
({
type
:
'unknownTransaction'
,
value
:
{
tx
:
tx
}
})
self
.
logUnknownTX
({
tx
:
tx
})
}
}
}
}
...
...
src/app/files/file-explorer.js
View file @
46944c93
...
@@ -70,7 +70,6 @@ function fileExplorer (appAPI, files) {
...
@@ -70,7 +70,6 @@ function fileExplorer (appAPI, files) {
}
}
})
})
var
self
=
this
var
fileEvents
=
files
.
event
var
fileEvents
=
files
.
event
var
treeView
=
new
Treeview
({
var
treeView
=
new
Treeview
({
extractData
:
function
(
value
,
tree
,
key
)
{
extractData
:
function
(
value
,
tree
,
key
)
{
...
...
src/app/panels/editor-panel.js
View file @
46944c93
...
@@ -157,7 +157,49 @@ class EditorPanel {
...
@@ -157,7 +157,49 @@ class EditorPanel {
context
()
{
context
()
{
return
self
.
_api
.
context
()
return
self
.
_api
.
context
()
}
}
}
},
banner
:
`
/******************************************************************************
...........................................
.....................:.....................
....................o:;....................
...................oo:;;...................
..................ooo:;;;..................
.................oooo:;;;;.................
................ooooo:;;;;;................
...............oooooo:;;;;;;...............
..............ooooooo:;;;;;;;..............
.............ooooooo;:';;;;;;;.............
............ooooo;;;;:'''';;;;;............
...........oo;;;;;;;;:'''''''';;...........
..........;;;;;;;;;;;:'''''''''''..........
..............;;;;;;;:'''''''..............
...........oo...;;;;;:'''''...;;...........
............oooo...;;:''...;;;;............
..............oooo...:...;;;;..............
...............oooooo:;;;;;;...............
................ooooo:;;;;;................
.................oooo:;;;;.................
..................ooo:;;;..................
...................oo:;;...................
....................o:;....................
.....................:.....................
...........................................
######## ######## ## ## #### ## ##
## ## ## ### ### ## ## ##
## ## ## #### #### ## ## ##
######## ###### ## ### ## ## ###
## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
## ## ######## ## ## #### ## ##
welcome to browser solidity
******************************************************************************/
`
})
})
}
}
self
.
_components
.
terminal
.
event
.
register
(
'resize'
,
delta
=>
self
.
_adjustLayout
(
'top'
,
delta
))
self
.
_components
.
terminal
.
event
.
register
(
'resize'
,
delta
=>
self
.
_adjustLayout
(
'top'
,
delta
))
...
@@ -194,6 +236,11 @@ class EditorPanel {
...
@@ -194,6 +236,11 @@ class EditorPanel {
var
self
=
this
var
self
=
this
self
.
_view
.
tabs
.
onmouseenter
()
self
.
_view
.
tabs
.
onmouseenter
()
}
}
log
(
data
=
{})
{
var
self
=
this
var
command
=
self
.
_components
.
terminal
.
commands
[
data
.
type
]
if
(
typeof
command
===
'function'
)
command
(
data
.
value
)
}
render
()
{
render
()
{
var
self
=
this
var
self
=
this
if
(
self
.
_view
.
el
)
return
self
.
_view
.
el
if
(
self
.
_view
.
el
)
return
self
.
_view
.
el
...
@@ -215,13 +262,9 @@ class EditorPanel {
...
@@ -215,13 +262,9 @@ class EditorPanel {
self
.
_adjustLayout
(
'top'
,
self
.
data
.
_layout
.
top
.
offset
)
self
.
_adjustLayout
(
'top'
,
self
.
data
.
_layout
.
top
.
offset
)
return
self
.
_view
.
el
return
self
.
_view
.
el
}
}
registerLogType
(
typename
,
template
)
{
registerCommand
(
name
,
command
)
{
var
self
=
this
self
.
_components
.
terminal
.
registerType
(
typename
,
template
)
}
log
()
{
var
self
=
this
var
self
=
this
self
.
_components
.
terminal
.
_output
.
apply
(
self
.
_components
.
terminal
,
arguments
)
return
self
.
_components
.
terminal
.
registerCommand
(
name
,
command
)
}
}
_renderTabsbar
()
{
_renderTabsbar
()
{
var
self
=
this
var
self
=
this
...
...
src/app/panels/terminal.js
View file @
46944c93
/* global Node */
/* global Node
, requestAnimationFrame
*/
var
yo
=
require
(
'yo-yo'
)
var
yo
=
require
(
'yo-yo'
)
var
csjs
=
require
(
'csjs-inject'
)
var
csjs
=
require
(
'csjs-inject'
)
var
javascriptserialize
=
require
(
'javascript-serialize'
)
var
javascriptserialize
=
require
(
'javascript-serialize'
)
...
@@ -9,6 +9,7 @@ var EventManager = require('ethereum-remix').lib.EventManager
...
@@ -9,6 +9,7 @@ var EventManager = require('ethereum-remix').lib.EventManager
var
Web3
=
require
(
'web3'
)
var
Web3
=
require
(
'web3'
)
var
executionContext
=
require
(
'../../execution-context'
)
var
executionContext
=
require
(
'../../execution-context'
)
var
Dropdown
=
require
(
'../ui/dropdown'
)
var
css
=
csjs
`
var
css
=
csjs
`
.panel {
.panel {
...
@@ -27,17 +28,29 @@ var css = csjs`
...
@@ -27,17 +28,29 @@ var css = csjs`
.bar {
.bar {
display : flex;
display : flex;
justify-content : flex-end;
min-height : 1.7em;
min-height : 1.7em;
padding : 2px;
padding : 2px;
cursor : ns-resize;
background-color : #eef;
background-color : #eef;
z-index : 3;
}
.menu {
position : relative;
display : flex;
align-items : center;
width : 100%;
}
.title {
margin-right : 15px;
}
}
.minimize {
.minimize {
text-align : center;
margin-left : auto;
padding-top : 3px;
width : 10px;
width : 10px;
min-height : 100%;
cursor : pointer;
color : black;
}
.clear {
margin-right : 5px;
font-size : 15px;
cursor : pointer;
cursor : pointer;
color : black;
color : black;
}
}
...
@@ -78,17 +91,7 @@ var css = csjs`
...
@@ -78,17 +91,7 @@ var css = csjs`
outline : none;
outline : none;
font-family : monospace;
font-family : monospace;
}
}
.error {
color : red;
}
.info {
color : blue;
}
.log {
color : black;
}
.dragbarHorizontal {
.dragbarHorizontal {
position : absolute;
position : absolute;
top : 0;
top : 0;
...
@@ -120,63 +123,49 @@ var ghostbar = yo`<div class=${css.ghostbar}></div>`
...
@@ -120,63 +123,49 @@ var ghostbar = yo`<div class=${css.ghostbar}></div>`
class
Terminal
{
class
Terminal
{
constructor
(
opts
=
{
auto
:
true
})
{
constructor
(
opts
=
{
auto
:
true
})
{
var
self
=
this
var
self
=
this
self
.
event
=
new
EventManager
()
self
.
_api
=
opts
.
api
self
.
data
=
{
self
.
data
=
{
lineLength
:
opts
.
lineLength
||
80
,
lineLength
:
opts
.
lineLength
||
80
,
session
:
[],
session
:
[],
banner
:
opts
.
banner
||
`
banner
:
opts
.
banner
,
/******************************************************************************
activeFilters
:
{
commands
:
{},
input
:
''
}
...........................................
.....................:.....................
....................o:;....................
...................oo:;;...................
..................ooo:;;;..................
.................oooo:;;;;.................
................ooooo:;;;;;................
...............oooooo:;;;;;;...............
..............ooooooo:;;;;;;;..............
.............ooooooo;:';;;;;;;.............
............ooooo;;;;:'''';;;;;............
...........oo;;;;;;;;:'''''''';;...........
..........;;;;;;;;;;;:'''''''''''..........
..............;;;;;;;:'''''''..............
...........oo...;;;;;:'''''...;;...........
............oooo...;;:''...;;;;............
..............oooo...:...;;;;..............
...............oooooo:;;;;;;...............
................ooooo:;;;;;................
.................oooo:;;;;.................
..................ooo:;;;..................
...................oo:;;...................
....................o:;....................
.....................:.....................
...........................................
######## ######## ## ## #### ## ##
## ## ## ### ### ## ## ##
## ## ## #### #### ## ## ##
######## ###### ## ### ## ## ###
## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
## ## ######## ## ## #### ## ##
welcome to browser solidity
new features:
- dom terminal v0.0.1-alpha
******************************************************************************/
`
}
}
self
.
event
=
new
EventManager
()
self
.
_api
=
opts
.
api
self
.
_view
=
{
el
:
null
,
bar
:
null
,
input
:
null
,
term
:
null
,
journal
:
null
,
cli
:
null
}
self
.
_view
=
{
el
:
null
,
bar
:
null
,
input
:
null
,
term
:
null
,
journal
:
null
,
cli
:
null
}
self
.
_templates
=
{}
self
.
_components
=
{}
self
.
logger
=
{}
self
.
_components
.
dropdown
=
new
Dropdown
({
;[
'log'
,
'info'
,
'error'
].
forEach
(
typename
=>
{
options
:
[
self
.
registerType
(
typename
,
self
.
_blocksRenderer
(
typename
))
'knownTransaction'
,
'unknownTransaction'
,
'script'
],
defaults
:
[
'knownTransaction'
,
'script'
]
})
self
.
_components
.
dropdown
.
event
.
register
(
'deselect'
,
function
(
label
)
{
self
.
updateJournal
({
type
:
'deselect'
,
value
:
label
})
})
self
.
_components
.
dropdown
.
event
.
register
(
'select'
,
function
(
label
)
{
self
.
updateJournal
({
type
:
'select'
,
value
:
label
})
})
self
.
_commands
=
{}
self
.
commands
=
{}
self
.
_JOURNAL
=
[]
self
.
_jobs
=
[]
self
.
_INDEX
=
{}
self
.
_INDEX
.
all
=
[]
self
.
_INDEX
.
allMain
=
[]
self
.
_INDEX
.
commands
=
{}
self
.
_INDEX
.
commandsMain
=
{}
self
.
registerCommand
(
'log'
,
self
.
_blocksRenderer
(
'log'
))
self
.
registerCommand
(
'info'
,
self
.
_blocksRenderer
(
'info'
))
self
.
registerCommand
(
'error'
,
self
.
_blocksRenderer
(
'error'
))
self
.
registerCommand
(
'script'
,
function
execute
(
args
,
scopedCommands
,
append
)
{
var
script
=
String
(
args
[
0
])
scopedCommands
.
log
(
`>
${
script
}
`
)
self
.
_shell
(
script
,
scopedCommands
,
function
(
error
,
output
)
{
if
(
error
)
scopedCommands
.
error
(
error
)
else
scopedCommands
.
log
(
output
)
})
})
})
self
.
_jsSandboxContext
=
{}
self
.
_jsSandboxContext
=
{}
self
.
_jsSandbox
=
vm
.
createContext
(
self
.
_jsSandboxContext
)
self
.
_jsSandbox
=
vm
.
createContext
(
self
.
_jsSandboxContext
)
...
@@ -198,14 +187,23 @@ class Terminal {
...
@@ -198,14 +187,23 @@ class Terminal {
`
`
self
.
_view
.
icon
=
yo
`<i onmouseenter=
${
hover
}
onmouseleave=
${
hover
}
onmousedown=
${
minimize
}
class="
${
css
.
minimize
}
fa fa-angle-double-down"></i>`
self
.
_view
.
icon
=
yo
`<i onmouseenter=
${
hover
}
onmouseleave=
${
hover
}
onmousedown=
${
minimize
}
class="
${
css
.
minimize
}
fa fa-angle-double-down"></i>`
self
.
_view
.
dragbar
=
yo
`<div onmousedown=
${
mousedown
}
class=
${
css
.
dragbarHorizontal
}
></div>`
self
.
_view
.
dragbar
=
yo
`<div onmousedown=
${
mousedown
}
class=
${
css
.
dragbarHorizontal
}
></div>`
self
.
_view
.
dropdown
=
self
.
_components
.
dropdown
.
render
()
self
.
_view
.
bar
=
yo
`
self
.
_view
.
bar
=
yo
`
<div class=
${
css
.
bar
}
>
<div class=
${
css
.
bar
}
>
${
self
.
_view
.
dragbar
}
${
self
.
_view
.
dragbar
}
${
self
.
_view
.
icon
}
<div class=
${
css
.
menu
}
>
<div class=
${
css
.
title
}
>Remix Terminal</div>
<div class=
${
css
.
clear
}
onclick=
${
clear
}
>
<i class="fa fa-ban" aria-hidden="true" onmouseenter=
${
hover
}
onmouseleave=
${
hover
}
></i>
</div>
${
self
.
_view
.
dropdown
}
<input type="text" class=
${
css
.
filter
}
onkeyup=
${
filter
}
></div>
${
self
.
_view
.
icon
}
</div>
</div>
</div>
`
`
self
.
_view
.
term
=
yo
`
self
.
_view
.
term
=
yo
`
<div class=
${
css
.
terminal
}
onscroll=
${
throttle
(
reattach
,
5
0
)}
onclick=
${
focusinput
}
>
<div class=
${
css
.
terminal
}
onscroll=
${
throttle
(
reattach
,
1
0
)}
onclick=
${
focusinput
}
>
${
self
.
_view
.
journal
}
${
self
.
_view
.
journal
}
${
self
.
_view
.
cli
}
${
self
.
_view
.
cli
}
</div>
</div>
...
@@ -216,18 +214,17 @@ class Terminal {
...
@@ -216,18 +214,17 @@ class Terminal {
${
self
.
_view
.
term
}
${
self
.
_view
.
term
}
</div>
</div>
`
`
self
.
_output
(
self
.
data
.
banner
)
if
(
self
.
data
.
banner
)
self
.
commands
.
log
(
self
.
data
.
banner
)
function
focusinput
(
event
)
{
function
throttle
(
fn
,
wait
)
{
if
(
self
.
_view
.
journal
.
offsetHeight
-
(
self
.
_view
.
term
.
scrollTop
+
self
.
_view
.
term
.
offsetHeight
)
<
50
)
{
var
time
=
Date
.
now
()
refocus
()
return
function
debounce
()
{
if
((
time
+
wait
-
Date
.
now
())
<
0
)
{
fn
.
apply
(
this
,
arguments
)
time
=
Date
.
now
()
}
}
}
}
}
function
refocus
()
{
self
.
_view
.
input
.
focus
()
reattach
({
currentTarget
:
self
.
_view
.
term
})
self
.
scroll2bottom
()
}
var
css2
=
csjs
`
var
css2
=
csjs
`
.anchor {
.anchor {
position : static;
position : static;
...
@@ -264,18 +261,20 @@ class Terminal {
...
@@ -264,18 +261,20 @@ class Terminal {
var
placeholder
=
yo
`<div class=
${
css2
.
anchor
}
>
${
background
}${
text
}
</div>`
var
placeholder
=
yo
`<div class=
${
css2
.
anchor
}
>
${
background
}${
text
}
</div>`
var
inserted
=
false
var
inserted
=
false
function
throttle
(
fn
,
wait
)
{
function
focusinput
(
event
)
{
var
time
=
Date
.
now
()
if
(
self
.
_view
.
journal
.
offsetHeight
-
(
self
.
_view
.
term
.
scrollTop
+
self
.
_view
.
term
.
offsetHeight
)
<
50
)
{
return
function
()
{
refocus
()
if
((
time
+
wait
-
Date
.
now
())
<
0
)
{
fn
.
apply
(
this
,
arguments
)
time
=
Date
.
now
()
}
}
}
}
}
function
refocus
()
{
self
.
_view
.
input
.
focus
()
reattach
({
currentTarget
:
self
.
_view
.
term
})
delete
self
.
scroll2bottom
self
.
scroll2bottom
()
}
function
reattach
(
event
)
{
function
reattach
(
event
)
{
var
el
=
event
.
currentTarget
var
el
=
event
.
currentTarget
var
isBottomed
=
el
.
scrollHeight
-
el
.
scrollTop
<
el
.
clientHeight
+
30
var
isBottomed
=
el
.
scrollHeight
-
el
.
scrollTop
-
el
.
clientHeight
<
30
if
(
isBottomed
)
{
if
(
isBottomed
)
{
if
(
inserted
)
{
if
(
inserted
)
{
text
.
innerText
=
''
text
.
innerText
=
''
...
@@ -320,11 +319,11 @@ class Terminal {
...
@@ -320,11 +319,11 @@ class Terminal {
background
.
style
.
height
=
(
self
.
_view
.
journal
.
offsetHeight
-
(
placeholder
.
offsetTop
+
placeholder
.
offsetHeight
))
+
'px'
background
.
style
.
height
=
(
self
.
_view
.
journal
.
offsetHeight
-
(
placeholder
.
offsetTop
+
placeholder
.
offsetHeight
))
+
'px'
background
.
onclick
=
undefined
background
.
onclick
=
undefined
background
.
style
.
cursor
=
'default'
background
.
style
.
cursor
=
'default'
background
.
style
.
pointerEvents
=
'none'
}
else
{
}
else
{
background
.
style
=
''
background
.
style
=
''
text
.
style
=
''
text
.
style
=
''
background
.
onclick
=
function
(
event
)
{
background
.
onclick
=
function
(
event
)
{
console
.
error
(
'background click'
)
placeholder
.
scrollIntoView
()
placeholder
.
scrollIntoView
()
check
()
check
()
}
}
...
@@ -341,6 +340,14 @@ class Terminal {
...
@@ -341,6 +340,14 @@ class Terminal {
self
.
event
.
trigger
(
'resize'
,
[])
self
.
event
.
trigger
(
'resize'
,
[])
}
}
}
}
function
filter
(
event
)
{
var
input
=
event
.
currentTarget
self
.
updateJournal
({
type
:
'search'
,
value
:
input
.
value
})
}
function
clear
(
event
)
{
refocus
()
self
.
_view
.
journal
.
innerHTML
=
''
}
// ----------------- resizeable ui ---------------
// ----------------- resizeable ui ---------------
function
mousedown
(
event
)
{
function
mousedown
(
event
)
{
event
.
preventDefault
()
event
.
preventDefault
()
...
@@ -385,7 +392,7 @@ class Terminal {
...
@@ -385,7 +392,7 @@ class Terminal {
putCursor2End
(
self
.
_view
.
input
)
putCursor2End
(
self
.
_view
.
input
)
}
else
{
// <enter>
}
else
{
// <enter>
event
.
preventDefault
()
event
.
preventDefault
()
self
.
execute
(
self
.
_view
.
input
.
innerText
)
self
.
commands
.
script
(
self
.
_view
.
input
.
innerText
)
self
.
_view
.
input
.
innerHTML
=
''
self
.
_view
.
input
.
innerHTML
=
''
}
}
}
}
...
@@ -418,12 +425,78 @@ class Terminal {
...
@@ -418,12 +425,78 @@ class Terminal {
editable
.
focus
()
editable
.
focus
()
}
}
}
}
updateJournal
(
filterEvent
)
{
var
self
=
this
var
commands
=
self
.
data
.
activeFilters
.
commands
var
value
=
filterEvent
.
value
if
(
filterEvent
.
type
===
'select'
)
{
commands
[
value
]
=
true
if
(
!
self
.
_INDEX
.
commandsMain
[
value
])
return
self
.
_INDEX
.
commandsMain
[
value
].
forEach
(
item
=>
{
item
.
root
.
steps
.
forEach
(
item
=>
{
self
.
_JOURNAL
[
item
.
gidx
]
=
item
})
self
.
_JOURNAL
[
item
.
gidx
]
=
item
})
}
else
if
(
filterEvent
.
type
===
'deselect'
)
{
commands
[
value
]
=
false
if
(
!
self
.
_INDEX
.
commandsMain
[
value
])
return
self
.
_INDEX
.
commandsMain
[
value
].
forEach
(
item
=>
{
item
.
root
.
steps
.
forEach
(
item
=>
{
self
.
_JOURNAL
[
item
.
gidx
]
=
undefined
})
self
.
_JOURNAL
[
item
.
gidx
]
=
undefined
})
}
else
if
(
filterEvent
.
type
===
'search'
)
{
if
(
value
!==
self
.
data
.
activeFilters
.
input
)
{
var
query
=
self
.
data
.
activeFilters
.
input
=
value
var
items
=
self
.
_JOURNAL
for
(
var
gidx
=
0
,
len
=
items
.
length
;
gidx
<
len
;
gidx
++
)
{
var
item
=
items
[
gidx
]
if
(
item
)
{
var
show
=
query
.
length
?
match
(
item
.
args
,
query
)
:
true
item
.
hide
=
!
show
}
}
}
}
var
df
=
document
.
createDocumentFragment
()
self
.
_JOURNAL
.
forEach
(
item
=>
{
if
(
item
&&
item
.
el
&&
!
item
.
hide
)
df
.
appendChild
(
item
.
el
)
})
requestAnimationFrame
(
function
updateDOM
()
{
self
.
_view
.
journal
.
innerHTML
=
''
self
.
_view
.
journal
.
appendChild
(
df
)
})
}
_shouldAdd
(
item
)
{
var
self
=
this
if
(
self
.
data
.
activeFilters
.
commands
[
item
.
root
.
cmd
])
{
var
query
=
self
.
data
.
activeFilters
.
input
var
args
=
item
.
args
return
query
.
length
?
match
(
args
,
query
)
:
true
}
}
_appendItem
(
item
)
{
var
self
=
this
var
{
el
,
gidx
}
=
item
self
.
_JOURNAL
[
gidx
]
=
item
if
(
!
self
.
_jobs
.
length
)
{
requestAnimationFrame
(
function
updateTerminal
()
{
self
.
_jobs
.
forEach
(
el
=>
self
.
_view
.
journal
.
appendChild
(
el
))
self
.
scroll2bottom
()
self
.
_jobs
=
[]
})
}
self
.
_jobs
.
push
(
el
)
}
scroll2bottom
()
{
var
self
=
this
setTimeout
(
function
()
{
self
.
_view
.
term
.
scrollTop
=
self
.
_view
.
term
.
scrollHeight
},
0
)
}
_blocksRenderer
(
mode
)
{
_blocksRenderer
(
mode
)
{
var
self
=
this
var
self
=
this
var
modes
=
{
log
:
true
,
info
:
true
,
error
:
true
}
mode
=
{
log
:
'black'
,
info
:
'blue'
,
error
:
'red'
}[
mode
]
// defaults
if
(
modes
[
mode
])
{
if
(
mode
)
{
return
function
render
()
{
return
function
logger
(
args
,
scopedCommands
,
append
)
{
var
args
=
[].
slice
.
call
(
arguments
)
var
types
=
args
.
map
(
type
)
var
types
=
args
.
map
(
type
)
var
values
=
javascriptserialize
.
apply
(
null
,
args
).
map
(
function
(
val
,
idx
)
{
var
values
=
javascriptserialize
.
apply
(
null
,
args
).
map
(
function
(
val
,
idx
)
{
if
(
typeof
args
[
idx
]
===
'string'
)
val
=
args
[
idx
]
if
(
typeof
args
[
idx
]
===
'string'
)
val
=
args
[
idx
]
...
@@ -432,69 +505,71 @@ class Terminal {
...
@@ -432,69 +505,71 @@ class Terminal {
var
lines
=
val
.
match
(
new
RegExp
(
pattern
,
'g'
))
var
lines
=
val
.
match
(
new
RegExp
(
pattern
,
'g'
))
return
lines
.
map
(
str
=>
document
.
createTextNode
(
`
${
str
}
\n`
))
return
lines
.
map
(
str
=>
document
.
createTextNode
(
`
${
str
}
\n`
))
})
})
return
values
append
(
yo
`<span style="color:
${
mode
}
;">
${
values
}
</span>`
)
}
}
}
else
{
}
else
{
throw
new
Error
(
'mode is not supported'
)
throw
new
Error
(
'mode is not supported'
)
}
}
}
}
execute
(
script
)
{
_scopeCommands
(
append
)
{
var
self
=
this
var
self
=
this
script
=
String
(
script
)
var
scopedCommands
=
{}
self
.
_output
({
type
:
'log'
,
value
:
`>
${
script
}
`
})
Object
.
keys
(
self
.
commands
).
forEach
(
function
makeScopedCommand
(
cmd
)
{
self
.
_shell
(
script
,
function
(
error
,
output
)
{
var
command
=
self
.
_commands
[
cmd
]
if
(
error
)
{
scopedCommands
[
cmd
]
=
function
_command
()
{
self
.
_output
({
type
:
'error'
,
value
:
error
})
var
args
=
[...
arguments
]
return
error
command
(
args
,
scopedCommands
,
el
=>
append
(
cmd
,
args
,
blockify
(
el
)))
}
else
{
self
.
_output
({
type
:
'log'
,
value
:
output
})
return
output
}
}
})
})
return
scopedCommands
}
}
register
Type
(
typename
,
template
)
{
register
Command
(
name
,
command
)
{
var
self
=
this
var
self
=
this
if
(
typeof
template
!==
'function'
)
throw
new
Error
(
'invalid template'
)
name
=
String
(
name
)
self
.
_templates
[
typename
]
=
template
if
(
self
.
_commands
[
name
])
throw
new
Error
(
`command "
${
name
}
" exists already`
)
self
.
logger
[
typename
]
=
function
()
{
if
(
typeof
command
!==
'function'
)
throw
new
Error
(
`invalid command:
${
command
}
`
)
var
args
=
[...
arguments
].
map
(
x
=>
({
type
:
typename
,
value
:
x
}))
self
.
_commands
[
name
]
=
command
self
.
_output
.
apply
(
self
,
args
)
self
.
_INDEX
.
commands
[
name
]
=
[]
self
.
_INDEX
.
commandsMain
[
name
]
=
[]
self
.
commands
[
name
]
=
function
_command
()
{
var
args
=
[...
arguments
]
var
steps
=
[]
var
root
=
{
steps
,
cmd
:
name
}
var
ITEM
=
{
root
,
cmd
:
name
}
root
.
gidx
=
self
.
_INDEX
.
allMain
.
push
(
ITEM
)
-
1
root
.
idx
=
self
.
_INDEX
.
commandsMain
[
name
].
push
(
ITEM
)
-
1
function
append
(
cmd
,
params
,
el
)
{
var
item
if
(
cmd
)
{
// subcommand
item
=
{
el
,
cmd
,
root
}
}
else
{
// command
item
=
ITEM
item
.
el
=
el
cmd
=
name
}
item
.
gidx
=
self
.
_INDEX
.
all
.
push
(
item
)
-
1
item
.
idx
=
self
.
_INDEX
.
commands
[
cmd
].
push
(
item
)
-
1
item
.
step
=
steps
.
push
(
item
)
-
1
item
.
args
=
params
if
(
self
.
_shouldAdd
(
item
))
self
.
_appendItem
(
item
)
}
var
scopedCommands
=
self
.
_scopeCommands
(
append
)
command
(
args
,
scopedCommands
,
el
=>
append
(
null
,
args
,
blockify
(
el
)))
}
}
var
help
=
typeof
command
.
help
===
'string'
?
command
.
help
:
[
`// no help available for:`
,
`terminal.commands.
${
name
}
(...)`
].
join
(
'
\
n'
)
self
.
commands
[
name
].
toString
=
_
=>
{
return
help
}
self
.
commands
[
name
].
help
=
help
return
self
.
commands
[
name
]
}
}
log
()
{
_shell
(
script
,
scopedCommands
,
done
)
{
// default shell
// @TODO: temporary to not break stuff that uses the old API
this
.
_output
.
apply
(
this
,
arguments
)
}
_output
()
{
var
self
=
this
var
args
=
[...
arguments
]
self
.
data
.
session
.
push
(
args
)
args
.
forEach
(
function
(
data
)
{
if
(
!
data
||
!
data
.
type
)
data
=
{
type
:
'log'
,
value
:
data
}
var
render
=
self
.
_templates
[
data
.
type
]
var
blocks
=
render
(
data
.
value
)
blocks
=
[].
concat
(
blocks
)
blocks
.
forEach
(
function
(
block
)
{
self
.
_view
.
journal
.
appendChild
(
yo
`
<div class="
${
css
.
block
}
${
css
[
data
.
type
]
||
data
.
type
}
">
${
block
}
</div>
`
)
self
.
scroll2bottom
()
})
})
}
scroll2bottom
()
{
var
self
=
this
setTimeout
(
function
()
{
self
.
_view
.
term
.
scrollTop
=
self
.
_view
.
term
.
scrollHeight
},
0
)
}
_shell
(
script
,
done
)
{
// default shell
var
self
=
this
var
self
=
this
var
context
=
domTerminalFeatures
(
self
,
scopedCommands
)
try
{
try
{
var
c
ontext
=
vm
.
createContext
(
Object
.
assign
(
self
.
_jsSandboxContext
,
domTerminalFeatures
(
self
)
))
var
c
mds
=
vm
.
createContext
(
Object
.
assign
(
self
.
_jsSandboxContext
,
context
))
var
result
=
vm
.
runInContext
(
script
,
c
ontext
)
var
result
=
vm
.
runInContext
(
script
,
c
mds
)
self
.
_jsSandboxContext
=
Object
.
assign
({},
context
)
self
.
_jsSandboxContext
=
Object
.
assign
({},
context
)
done
(
null
,
result
)
done
(
null
,
result
)
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -503,14 +578,40 @@ class Terminal {
...
@@ -503,14 +578,40 @@ class Terminal {
}
}
}
}
function
domTerminalFeatures
(
self
)
{
function
domTerminalFeatures
(
self
,
scopedCommands
)
{
// @TODO add all the `console` functions
return
{
return
{
web3
:
executionContext
.
getProvider
()
!==
'vm'
?
new
Web3
(
executionContext
.
web3
().
currentProvider
)
:
null
,
web3
:
executionContext
.
getProvider
()
!==
'vm'
?
new
Web3
(
executionContext
.
web3
().
currentProvider
)
:
null
,
console
:
{
console
:
{
log
:
function
()
{
self
.
_output
.
apply
(
self
,
arguments
)
}
log
:
function
()
{
scopedCommands
.
log
.
apply
(
scopedCommands
,
arguments
)
},
info
:
function
()
{
scopedCommands
.
info
.
apply
(
scopedCommands
,
arguments
)
},
error
:
function
()
{
scopedCommands
.
error
.
apply
(
scopedCommands
,
arguments
)
}
}
}
}
}
}
}
function
findDeep
(
object
,
fn
,
found
=
{
break
:
false
,
value
:
undefined
})
{
if
(
typeof
object
!==
'object'
||
object
===
null
)
return
for
(
var
i
in
object
)
{
if
(
found
.
break
)
break
var
el
=
object
[
i
]
if
(
!
fn
(
el
,
i
,
object
))
findDeep
(
el
,
fn
,
found
)
else
if
(
found
.
break
=
true
)
return
found
.
value
=
el
// eslint-disable-line
}
return
found
.
value
}
function
match
(
args
,
query
)
{
query
=
query
.
trim
()
var
isMatch
=
!!
findDeep
(
args
,
function
check
(
value
,
key
)
{
if
(
value
===
undefined
||
value
===
null
)
return
false
if
(
typeof
value
===
'function'
)
return
false
if
(
typeof
value
===
'object'
)
return
false
var
contains
=
String
(
value
).
indexOf
(
query
.
trim
())
!==
-
1
return
contains
})
return
isMatch
}
function
blockify
(
el
)
{
return
yo
`<div class=
${
css
.
block
}
>
${
el
}
</div>`
}
module
.
exports
=
Terminal
module
.
exports
=
Terminal
test-browser/tests/compiling.js
View file @
46944c93
...
@@ -32,8 +32,8 @@ function runTests (browser) {
...
@@ -32,8 +32,8 @@ function runTests (browser) {
.
click
(
'#runTabView div[class^="create"]'
)
.
click
(
'#runTabView div[class^="create"]'
)
.
waitForElementPresent
(
'.instance button[title="f - transact (not payable)"]'
)
.
waitForElementPresent
(
'.instance button[title="f - transact (not payable)"]'
)
.
click
(
'.instance button[title="f - transact (not payable)"]'
)
.
click
(
'.instance button[title="f - transact (not payable)"]'
)
.
waitForElementPresent
(
'#editor-container div[class^="terminal"]
.knownTransaction
span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]'
)
.
waitForElementPresent
(
'#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]'
)
.
assert
.
containsText
(
'#editor-container div[class^="terminal"]
.knownTransaction
span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]'
,
'(vm): from:0xca3...a733c, to:0x692...77b3a, browser/Untitled.sol:TestContract.f(), value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc,DetailsDebug'
)
.
assert
.
containsText
(
'#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]'
,
'(vm): from:0xca3...a733c, to:0x692...77b3a, browser/Untitled.sol:TestContract.f(), value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc,DetailsDebug'
)
.
end
()
.
end
()
/*
/*
@TODO: need to check now the return value of the function
@TODO: need to check now the return value of the function
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment