作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] HW2....上下方向键的功能好像有点问题喔?
时间Fri Oct 27 23:22:56 2006
The "history" will never be "removed". So in your experiment (see comments
below) ---
※ 引述《karate362 (最近腰不痛的卡拉特)》之铭言:
: 这部分是老师写好的函式
: 按理说是不用改
: 不过我写的时候是发现啦
: 如果你照这样做会发生奇妙的事情
: (1)
: cmd>rec1 //输入
: cmd>rec2
: cmd>rec3
: 照这样输入之後,假使我按方向键上
: 按理来说会出现
: cmd>rec3
: 再按一次会出现
: cmd>rec2
: 不过呢
: 如果我在按一次上之後
: 连续按delete或backspace
: 把
: cmd>rec3删成cmd> 再按enter的话
Please note that you are modifying the "copy" of the 3rd history entry, not
the 3rd history itself.
: 在下一个cmd> 我再按上
: 会跑出来的不是
: cmd>rec3
: 而是
: cmd>rec2
So after you type in "up" arrow, you goes to second history and that's why you
see "rec2". Actually if you type "down" arrow afterwards, you will see "rec3".
It is not removed.
: 我想这并非我们想要的结果
: 我看了一下addHistory()函式里的写法
: 发现老师本来是写一段这样
: // add to _history
: if (*tmp != 0) {
: _history[_historySize++] = tmp;
: _history[_historySize].clear();
: _historyIdx = _historySize;
: }
: 总之 意思应该是说如果我们输入空字串的话
: 那麽history就不会被更新
: 不过因为把 _historyIdx = _historySize;
: 这一句放在if区块里,就造成查询history的
: index都不会被更新 就造成上面的错误了
I made the "history" behavior the same as in cshrc (maybe the same as bash?).
You can go to your Linux command prompt and try it. It should be consistent
with my code.
: 我把那一句拿到if区块外是就OK了啦...
: 话说回来 我觉得这篇文章讲的东西
: 如果不是我自己打的 我一定看不懂...囧
I understand what you mean, and hopefully you know what I am talking about.
I think the reference code is fine.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.121.134.57