我正在寻找一种在命令行上面编写代码的方法。 就像聊天一样,你输入的东西显示在输入行的上方。
例如:
<GenerateManifests>false</GenerateManifests>
我想要显示的内容,如果我输入“我的名字是蒂姆”是:
def output(arg1, arg2)
puts arg1 + ":" + arg2
end
puts "-" *30
print "What do you want to say? > "
written_line = gets.chomp
output(username, written_line)
除了这样做之外,还有一个想法吗? 谢谢
答案 0 :(得分:0)
也许你正在寻找这样的东西?
def clear_line
print "\e[2K" # Clear entire line
end
def move_up(n)
print "\e[#{n}F" # Move to the beginning of n lines up
end
def positioning_to_output
move_up(2)
clear_line
end
def output(arg1, arg2)
positioning_to_output
puts arg1 + " :" + arg2
clear_line
puts "-" *30
end
username = "Jim Kirk"
4.times do
print "What do you want to say? > "
written_line = gets.chomp
output(username, written_line)
end
在macOS上测试,感谢找到here
的转义序列