Skip to content

Commit ffe6f82

Browse files
committed
add .echo, placeholder $_, better help
1 parent 01fb6ed commit ffe6f82

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ An interactive Solidity shell with lightweight session recording.
2727

2828
* **Note**: Sessions can be saved and restored using the `.session` command. Your previous session is always stored and can be loaded via `.session load previous` (not safe when running concurrent shells).
2929
* **Note**: `.reset` completely removes all statements. `.undo` removes the last statement.
30-
* **Note**: see what's been generated under the hood? call `.dump`.
31-
* **Note**: settings are saved on exit (not safe when running concurrent shells). call `config set <key> <value>` to change settings like ganache port, ganache autostart, etc.
32-
* **Note**: solidity version is currently fixed to the `solc` package that comes with the shell. If there's interest we might change that to allow remote compiler versions.
30+
* **Note**: See what's been generated under the hood? call `.dump`.
31+
* **Note**: Settings are saved on exit (not safe when running concurrent shells). call `config set <key> <value>` to change settings like ganache port, ganache autostart, etc.
32+
* **Note**: Solidity version is currently fixed to the `solc` package that comes with the shell. If there's interest we might change that to allow remote compiler versions.
33+
* **Note**: `$_` is a placeholder for the last known result. Feel free to use that placeholder in your scripts :)
34+
* **Note**: Special commands are dot-prefixed. Everything else is evaluated as Solidity code.
3335

3436

3537
## Examples

bin/main.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ const { convert, multilineInput } = require('../src/utils');
1616
const CONFIG_HOME = path.join(os.homedir(), '.solidity-shell');
1717
const CONFIG_FILE = '.config';
1818

19+
const REX_PLACEHOLDER = /\s(\$_)(\s|$)/ig /* LAST_KNOWN_RESULT placeholder */
20+
21+
var LAST_KNOWN_RESULT = 'ss';
1922
var SESSION = 'previous.session';
2023

24+
2125
/** static funcs */
2226
function loadFile(name){
2327
let cfgFile = path.join(CONFIG_HOME, name);
@@ -57,11 +61,16 @@ vorpal
5761
.mode('repl', 'Enters Solidity Shell Mode')
5862
.delimiter(c.bold('» '))
5963
.init(function (args, cb) {
60-
this.log('🚀 Entering interactive Solidity shell. Type \'.help\' for help, \'.exit\' to exit.');
64+
this.log(`🚀 Entering interactive Solidity shell. ${c.bold('.help')} and ${c.bold('.exit')} are your friends.`);
65+
this.log()
6166
return cb();
6267
})
6368
.action(function (input, cb) {
6469
let command = multilineInput(input);
70+
71+
/* substitute placeholder: $_ */
72+
command = command.replace(REX_PLACEHOLDER, ' ' + LAST_KNOWN_RESULT + ' ');
73+
6574
if (command.startsWith('.')) {
6675
let commandParts = command.split(' ');
6776
let ret = undefined;
@@ -71,29 +80,34 @@ vorpal
7180
📚 Help:
7281
-----
7382
74-
General:
83+
${c.bold('$_')} is a placeholder holding the most recent evaluation result.
84+
85+
86+
${c.bold('General:')}
7587
.help ... this help :)
7688
.exit ... exit the shell
7789
78-
Settings:
90+
${c.bold('Settings:')}
7991
.config ... show settings
8092
set <key> <value> ... set setting
8193
unset <key> ... unset setting
82-
Session:
94+
${c.bold('Session:')}
8395
.session ... list sessions
8496
load <id> ... load session
8597
save <id> ... save session
8698
8799
.undo ... undo last command
88100
.reset ... reset cmd history. start from scratch.
89101
90-
Debug:
102+
${c.bold('Debug:')}:
91103
.dump ... (debug) show template contract
104+
.echo ... every shell needs an echo command
92105
93106
94107
cheers 🙌
95-
@tintinweb
96-
ConsenSys Diligence @ https://diligence.consensys.net/
108+
${c.bold('@tintinweb')}
109+
ConsenSys Diligence @ https://consensys.net/diligence/
110+
https://github.com/tintinweb/solidity-shell/
97111
`);
98112

99113
break; //show usage
@@ -110,7 +124,7 @@ cheers 🙌
110124
switch(commandParts[1]){
111125
default:
112126
let sessions = fs.readdirSync(CONFIG_HOME).filter(file => file.endsWith('.session'));
113-
return cb(' - ' + sessions.map(s => s.replace('.session','')).join('\n - '));
127+
return cb(' - ' + sessions.map(s => c.bold(s.replace('.session',''))).join('\n - '));
114128
case 'load':
115129
shell.loadSession(loadFile(`${commandParts[2]}.session`))
116130
break;
@@ -119,10 +133,11 @@ cheers 🙌
119133
saveFile(SESSION, shell.dumpSession())
120134
break;
121135
}; break;
122-
case '.dump': return cb(shell.template());
136+
case '.dump': return cb(c.yellow(shell.template()));
137+
case '.echo': return cb(c.bold(c.yellow(commandParts.slice(1).join(' '))))
123138

124139
default:
125-
console.error(`unknown command: ${command}. type '.help' for a list of commands.`);
140+
console.error(`Unknown Command: '${command}'. Type ${c.bold('.help')} for a list of commands.`);
126141
}
127142
// meta commands
128143
return cb(ret);
@@ -135,6 +150,7 @@ cheers 🙌
135150
if(typeof res === 'object'){
136151
return cb();
137152
}
153+
LAST_KNOWN_RESULT = res;
138154
cb(c.bold(c.yellow(res)));
139155
}).catch(errors => {
140156
console.error(errors)

0 commit comments

Comments
 (0)