Repository

bartender

Customizable bars for v term apps.

smooth

Getting started

Install via v cli

  • From source

    v install --git https://github.com/tobealive/bartender
    
    import bartender
    
  • As vpm module

    v install tobealive.bartender
    
    import tobealive.bartender
    

Usage examples

  • Simple bars

    // Defaul bar
    mut b := Bar{}
    for _ in 0 .. b.iters {
      b.progress()
    }
    
    // Customized bar
    mut b2 := Bar{
      width: 60
      runes: BarRunes{
          progress: `#`
          indicator: `❯`
          remaining: `-`
      }
      pre: '|'
      post: Affix{
          pending: '| Loading...'
          finished: '| Done!'
      }
    }
    for _ in 0 .. b2.iters {
      b2.progress()
    }
    
  • Smooth bar themes

    mut b := SmoothBar{
      theme: Theme.pull // Default = Theme.push
    }
    for _ in 0 .. b.iters {
      b.progress()
    }
    
    b2 = SmoothBar{
      theme: ThemeVariant{.pull, .drain}
    }
    for _ in 0 .. b2.iters {
      b2.progress()
    }
    
    // Customized smooth bar
    mut b3 := SmoothBar{
      theme: Theme.split
      width: 80
      pre: '│'
      post: fn (b SmoothBar) (string, string) {
          return '│ Saving... ${b.pct()}% ${term.blue(b.eta(20))}', '│ Saved!'
      }
    }
    b3.colorize(.cyan)
    for _ in 0 .. b3.iters {
      b3.progress()
    }
    
  • Bar Reader for io operations.

    // Returns an `io.BufferedReader` that displays a progressing bar when used in a reader operation.
    pub fn (b Bar) reader(reader io.Reader, size u64) &io.BufferedReader
    
    mut src_file := os.open(src_file_path)!
    mut dst_file := os.create(dst_file_path)!
    
    bar := bartender.Bar{}
    mut bar_reader := bar.reader(src_file, os.file_size(src_file_path))
    io.cp(mut bar_reader, mut dst_file)!
    

Run examples

Extended and executable examples can be found in the examples directory.

v run examples/<file>.v

Showcase

Simple bar   Toggle visibility...

simple

Color and style customizations.   Toggle visibility...

colors

Smooth bars.   Toggle visibility...

download

Disclaimer

Until a stable version 1.0 is available, new features will be introduced, existing ones may change, or breaking changes may occur in minor( 0.<minor>.* ) versions.

Outlook

Below are some of the things to look forward to.

  • Reader Interface
  • Multiline (Smooth Bar Split Themes are not supported yet)
  • Time Remaining
  • Dynamic adjustment on term resize for all variants (basic width detection works)
  • Extend visuals & customizability

Anowledgements

About

0
123
last May 7

Author

tobealive