New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix bug && add new feature #1
Conversation
@@ -1,11 +1,14 @@ | |||
var React = require('react'); | |||
var axios = require('axios'); | |||
|
|||
const Prompt = 'fc@aliyun $ '; | |||
const ShellApi = 'http://api.rockuw.com/shell'; | |||
var Prompt = 'fc@aliyun $ '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个为啥要改成var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为按你目前仓库里的配置, 我用的 node v8.1.2
加上 browserify v14.4.0
在进行转换的时候会报错(操作系统是Windows7 x64
).
ERROR: Unexpected token: keyword (const)
@@ -17,7 +20,9 @@ var App = React.createClass({ | |||
execShellCommand: function(cmd) { | |||
var that = this; | |||
that.setState({'prompt': ''}) | |||
axios.get(ShellApi+'?cmd='+cmd).then(function (res) { | |||
that.offset = 0 | |||
that.cmds.push(cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里让that.offset = that.cmds.length;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that.offset = 0
是为了重置偏移值为最后面, 因为往上的时候 是 this.cmds.length - ++this.offset
.
如果写成 that.offset = that.cmds.length
这样, 效果就不一对了.
this.clearInput(); | ||
break | ||
case 'ArrowUp': | ||
if (this.offset === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个逻辑可以简化一下:
this.offset = Math.max(this.offset-1, -1);
this.refs.term.getDOMNode().value = this.cmds[this.offset] || '';
return false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
详细的解释见 ArrowDown
处提出的疑问处的回答.
src/app.js
Outdated
this.refs.term.getDOMNode().value = this.cmds[this.cmds.length - ++this.offset] || this.cmds[(this.offset = this.cmds.length, 0)] || this.lastCmd | ||
return false | ||
case 'ArrowDown': | ||
var history = this.state.history.slice(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以变成:
this.offset = Math.min(this.offset+1, this.cmds.length);
this.refs.term.getDOMNode().value = this.cmds[this.offset] || '';
return false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据你上面提出的 offset
使用的修改, 我自己在我本地测试了一下, 修改之后, 有以下几个问题:
-
在输入命令执行之后, 在输入框中按
上
箭头(多按几次), 回到第一次输入的命令之后, 再按上
会变成空. 而正常的bash
中在达到 历史记录中的第一个的时候,再按上
是保持不变的(即显示的还是第一个命令). -
在有输入命令,但没有按回车的情况下, 按
上
再按下
, 之前输入的内容就没有了(因没有保存用户现有输入内容的逻辑). -
在有输入命令,但没按回车的情况下, 按
下
箭头, 之前输入的内容变成空了.
而我现在所提交的代码是没有上述问题的.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
@@ -91,7 +110,7 @@ var App = React.createClass({ | |||
{output} | |||
<p> | |||
<span className="prompt">{this.state.prompt}</span> | |||
<input type="text" onKeyPress={this.handleInput} ref="term" /> | |||
<input type="text" onKeyDown={this.handleInput} ref="term" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为啥改成onKeyDown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为用 onKeyPress
事件是接收不到 ArrowUp/ArrowDown
的, 需要改为 onKeyDown
才可以.
…ake ui more like application
POC: run this command `cat /var/fc/runtime/nodejs4.4/package.json` while get `[object Object]`, and it's wrong.
Thanks. |
rm
没有加-f
参数, 当build
目录下没有*.js
文件时会报错的问题.URL
的参数值增加encodeURIComponent
, 以修复当执行的合集有&
的字符时,&
被当成URL
参数分隔符的问题.上
/下
)的支持, 当触发按键时, 自动从history
中取对应的cmd
填充至当前的输入框中.clear
命令, 用于清除目前已展示的历史数据.addHistory
方法, 使其支持批量添加数据, 减少调用addHistory
的次数.json
格式时, 将res.data
直接+ ''
会导致结果变为[object Object]
, 而非真正的内容的问题. (比如执行这个命令:cat /var/fc/runtime/nodejs4.4/package.json
)