How to change the gap length of char in println!

 use std::io;
 use std::io::Write;
 io::stdout().flush();
 let mut data = dark.iter().collect::<Vec<(&u64, &u32)>>();
 data.sort_by(|a, b| a.0.cmp(&b.0));
 for (i, v) in dark {
      println!("{}: {:|<1$}", i, *v as usize);
  }

and got a long stdout

44390000: 282|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

it takes too much room to show the ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

i want to reduce the gap length of |

how can i apply it in println! ?

Gap? For monospace fonts (which is what is shown in the code block and you most probably use in your terminal), the gap is fixed and is same for all characters. It has nothing to do with println.

2 Likes

pip install cpython will show

PS C:\Users\somewheve> pip install cpython
Collecting cpython
  Downloading cPython-0.0.6.tar.gz (4.7 kB)
Collecting pymongo
  Downloading pymongo-4.0.1-cp39-cp39-win_amd64.whl (354 kB)
     |████████████████████████████████| 354 kB 386 kB/s

how to get the |████████████████████████████████| ?
thanks

got it , just use █ and calculate the ratio

See also.

2 Likes

This is called a progress bar.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.