GithubHelp home page GithubHelp logo

Comments (8)

jules2689 avatar jules2689 commented on June 10, 2024

Hey @emanzx, can you give some example code so we can reproduce? Thanks!

from cli-ui.

emanzx avatar emanzx commented on June 10, 2024

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.

T-TonyLiang avatar T-TonyLiang commented on June 10, 2024

Hi @emanzx!

I've run the code segment you've provided:
screen shot 2018-01-09 at 10 26 15 am

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.

emanzx avatar emanzx commented on June 10, 2024

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.

jules2689 avatar jules2689 commented on June 10, 2024

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:

image

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

2018-01-18 01_17_11

from cli-ui.

emanzx avatar emanzx commented on June 10, 2024

I test your code. but it seem to produce multiple progress bar.
image
is it because im using ssh? not console tty?

from cli-ui.

jules2689 avatar jules2689 commented on June 10, 2024

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.

lugray avatar lugray commented on June 10, 2024

Closing because this is stale. If this is still relevant, please re-open.

from cli-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.