Closed Olipro closed 1 year ago
I've been reliably informed that user_input
does this weird behaviour when it has an empty prompt.
However, here's a much simpler scenario that also doesn't work in Greybel (and does in GreyHack)
Gsh = {}
Gsh.buf = ""
LF = char(10)
__print = @print
globals.print = function(s, cs = false)
if not cs then Gsh.buf = Gsh.buf + s + LF
if cs then Gsh.buf = s + LF
__print(Gsh.buf, cs)
end function
__user_input = @user_input
globals.user_input = function(s, pwd = false, oneChar = false)
cmd = ""
while true
clear_screen
chr = __user_input(Gsh.buf + s + cmd, false, true)
if chr.len == 0 then
Gsh.buf = Gsh.buf + s + cmd + LF
break
end if
cmd = cmd + chr
end while
return cmd
end function
while true
cmd = user_input("root@foo /home % ", false, true)
print("running: " + cmd + "\n")
end while
Yeah seems like the first example doesn't work in Greybel even though I am not sure I really want to support that behaviour as it's already pretty finicky to support every scenario.
Regarding your second example I am not exactly sure I am following. For me it seems to work fine and the characters actual concatenate just fine.
But there is one bug for sure where print with replaceText does not actually remove all the text.
print("abc1")
print("abc1")
print("abc1")
print("abc1")
print("abc1")
print("abc2", 1)
I was always under the impression that it only replaces the last print but it seems like I was wrong about that.
Sorry that I forgot the globals, fixed my example for posterity. Anyhow, Bearing in mind that I am still on 1.9.3
- Greybel seems to be failing to detect that we should loop and redisplay the prompt.
In Greybel:
root@foo /home % fsafafgdsg
gdgdf
df
df
dfdf
in GreyHack:
root@foo /home % kshdasf asfh saf
running: kshdasf asfh saf
root@foo /home % adfkdsf
running: adfkdsf
root@foo /home % dsaf
running: dsaf
root@foo /home %
Yeah it seems in Greybel if you press enter on a user_input the returned char length won't be 0 unlike GreyHack. Have to take a look why that is the reason.
With 1.9.5 - https://github.com/ayecue/greybel-vs/pull/118 enter is now an empty string just like in GreyHack.
I went looking for this myself yesterday and was extremely confused when I saw that KeyCode.Enter
returned ''
- then I checked the commit log and realised you'd already fixed it 😂
Anyhow, all good now, thanks!
I don't know what to say here because frankly, it took me a painstaking amount of effort to properly determine WTF the interaction between
print
anduser_input
is (in GreyHack, not Greybel)But, I figured it out and the code below gives you a skeleton of what basically behaves like an interactive terminal (albeit with a chunk of functionality left to be implemented)
If you run this same code in Greybel, it dumps out one char per line.