Comments (8)
Hey @emanzx, can you give some example code so we can reproduce? Thanks!
from cli-ui.
hi @jules2689 sorry. here the codes.. sorry for some lousy code.. just testing..
CLI::UI::Progress.progress do |bar|
CLI::UI::Frame.open('Frame 1') do
CLI::UI::Frame.open('Frame 2') do
#sleep(1)
a = CLI::UI.ask("what is your name?")
bar.tick(set_percent: 0.5)
a = CLI::UI.ask("what is your name3?")
if a == "hola"
bar.tick(set_percent: 0.8)
end
end
end
end
from cli-ui.
Hi @emanzx!
I've run the code segment you've provided:
Hmm, I would expect that this code would show a progress bar at the very top and updates its percentage as the prompts are being answered.
What are your expectations for the output of the code and is the screenshot consistent with what you're seeing?
from cli-ui.
Actually I try to present it on the bottom.. but I dont think it will work that way.. then I try it on top.. still cant make it work.. yup.. the screen shot you get is the same as I get..
from cli-ui.
hmm, yea. Because of the way the bar and prompts are drawn, they can't really coexist nicely like this. The bar expects to be in the same spot when it redraws. It's not impossible to add more logic here, but I'd be afraid it would be pretty complex.
Options
Bar each time
In this case, for now, I would suggest something like this:
CLI::UI::StdoutRouter.enable # Important to render the ask and progress within the frames
CLI::UI::Frame.open('Frame 1') do
CLI::UI::Frame.open('Frame 2') do
a = CLI::UI.ask("what is your name?")
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: 0.5) }
a = CLI::UI.ask("what is your name3?")
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: 0.8) } if a == "hola"
end
end
This would show a new bar each time, producing this:
Attempted bar at the top only
We could start playing around with cursor positioning like so:
def bar(percent)
puts CLI::UI::ANSI.cursor_restore
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: percent) }
end
CLI::UI::StdoutRouter.enable # Important to render the ask and progress within the frames
CLI::UI::Frame.open('Frame 1') do
CLI::UI::Frame.open('Frame 2') do
puts CLI::UI::ANSI.cursor_save # Setup for bar
bar(0.0)
a = CLI::UI.ask("what is your name?")
bar(0.5)
a = CLI::UI.ask("what is your name3?")
bar(0.8) if a == "hola"
sleep 1
bar(1.0)
end
end
This code overwrites the bar properly, but doesn't reset the position after the question. We could play around with more ansi coding there.
Clear the question entirely each time
This also could help (clears the question each time):
CLI::UI::StdoutRouter.enable # Important to render the ask and progress within the frames
def clear_lines(n)
n.times do
print(CLI::UI::ANSI.previous_line + CLI::UI::ANSI.end_of_line + ' ')
print(CLI::UI::ANSI.cursor_save)
print(' ' * CLI::UI::Terminal.width)
print(CLI::UI::ANSI.cursor_restore)
end
end
CLI::UI::Frame.open('Frame 1') do
CLI::UI::Frame.open('Frame 2') do
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: 0.0) }
a = CLI::UI.ask("what is your name?")
clear_lines(3)
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: 0.5) }
b = CLI::UI.ask("what is your name3?")
clear_lines(3)
if b == "hola"
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: 0.8) }
else
CLI::UI::Progress.progress { |bar| bar.tick(set_percent: 0.5) }
end
puts CLI::UI.fmt "{{bold:You answered:}}\n\ta: #{a}\n\tb: #{b}"
end
end
from cli-ui.
I test your code. but it seem to produce multiple progress bar.
is it because im using ssh? not console tty?
from cli-ui.
I'm sorry I never responded!
I think that SSH might be causing an issue, but I'm not sure how. sorry
from cli-ui.
Closing because this is stale. If this is still relevant, please re-open.
from cli-ui.
Related Issues (20)
- Should not `ask` when it is not interactive HOT 2
- in the terminal of vscode HOT 1
- Spinner does not reset terminal fast enough when there's a lot of output HOT 2
- ANSI color code escaping for "ask" broken in Debian HOT 2
- Add example showing how to run a shell command with stdout redirected HOT 2
- Questions get duplicated when the message is too long HOT 6
- The ask color change my frame color.
- Can't prompt in a spinner
- Cant use gray color option for frame HOT 2
- Links to documentation are broken HOT 2
- Circular dependency warnings
- [Feature Request] Allow to debrief successful SpinGroups
- Add option to allow configuration of ask prompt instructions colour HOT 2
- Error interactive_options.rb:337:in `wait_for_user_input': Interrupt (Interrupt) HOT 2
- Cannot load such file - cli-ui-2.2.0/vendor/reentrant_mutex HOT 2
- Progress bar broken in 2.2? HOT 3
- Weak guarantees for `IO#write` override
- Intermittent prompt_test failure
- Radio buttons / checkboxes HOT 4
- Ability to fail the whole process if spinner fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli-ui.