-1
from colorama import Fore
import platform
import distro
import time
import os

# Functions
def get_uptime():
    return os.popen('uptime -p').read()[:-1]

def get_os():
    return platform.system() + " " + platform.release()

# Main Entry
def main():
    linux_distro = distro.name()
    os_string = f"OS: {get_os()}"
    uptime_str = f"Uptime: {get_uptime()}"
    if 'pop' in linux_distro.lower():
        print(Fore.CYAN + f"""


            ←←←←←←←←←←←              ╠═══════════════ ROGUE FETCH ═════════════════════════════╣
        ←←←←←←←←←←←←←←←←←←←          ╠  {os_string}                                            ╣
      ←←←←←←    ←←←←←←←←←←←←←        ╠                                                         ╣
    ←←←←←         ↖←←←←←←←←←←←←      ╠  {uptime_str}                                           ╣
   ←←←←     ←←      ←←←←←←←←←←←←     ╠                                                         ╣
 ↖←←←←←     ←←←     ←←←←←←←←←←←←←↖   ╠                                                         ╣
 ←←←←←←←     ←←←    ←←←    ↖←←←←←←   ╠                                                         ╣
←←←←←←←←←     ←↖   ↖←←↖    ←←←←←←←←  ╠═════════════════════════════════════════════════════════╣
←←←←←←←←←←        ←←←←    ↖←←←←←←←←
←←←←←←←←←←←    ↖←←←←←←   ↖←←←←←←←←←
←←←←←←←←←←←←    ←←←←←←  ←←←←←←←←←←←
←←←←←←←←←←←←←    ←←←←←↖←←←←←←←←←←←←
 ←←←←←←←←←←←←←   ↖←←←↖ ←←←←←←←←←←← 
 ↖←←←←←←←←←←←←←  ←←←←  ←←←←←←←←←←↖ 
   ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←   
    ←←←←                   ←←←←    
      ←←←←←←←←←←←←←←←←←←←←←←←      
        ←←←←←←←←←←←←←←←←←←←        
            ←←←←←←←←←←←            
  
        """)

I made the frame with the symbols, however on running, it looks like unaligned and looks wrong: link: https://media.discordapp.net/attachments/1164305090144915556/1170754515495030895/image.png?ex=655a311c&is=6547bc1c&hm=41877fdc735ae2b06a1c7588f7c7ba397c2dd69cf8229d2ef6df6348379263f9&=&width=1160&height=487

3 Answers 3

0

You can format the string within the f string variable definition. For example all of these print with a bar on each side with a 25 character fields between them. figure out how wide you need for the var string you are using and make it that big and add remaining spaces as needed.

print(f"|{variable:25}|")    # default formating, string left justified, numeric right
print(f"|{variable:>25}|")   # right justifed
print(f"|{variable:<25}|")   # left justifed
print(f"|{variable:^25}|")   # center justified

I reworked your code so it would work locally to give you idea what I mean:

import platform
import os

# Functions

def get_os():
    return platform.system() + " " + platform.release()

# Main Entry
def main():
    os_string = f"OS: {get_os()}"
    print( f"""


            ←←←←←←←←←←←              ╠═══════════════ ROGUE FETCH ═════════════════════════════╣
        ←←←←←←←←←←←←←←←←←←←          ╠  {os_string:<25}                              ╣
      ←←←←←←    ←←←←←←←←←←←←←        ╠                                                         ╣
    ←←←←←         ↖←←←←←←←←←←←←      ╠                                                         ╣
   ←←←←     ←←      ←←←←←←←←←←←←     ╠                                                         ╣
 ↖←←←←←     ←←←     ←←←←←←←←←←←←←↖   ╠                                                         ╣
 ←←←←←←←     ←←←    ←←←    ↖←←←←←←   ╠                                                         ╣
←←←←←←←←←     ←↖   ↖←←↖    ←←←←←←←←  ╠═════════════════════════════════════════════════════════╣
←←←←←←←←←←        ←←←←    ↖←←←←←←←←
←←←←←←←←←←←    ↖←←←←←←   ↖←←←←←←←←←
←←←←←←←←←←←←    ←←←←←←  ←←←←←←←←←←←
←←←←←←←←←←←←←    ←←←←←↖←←←←←←←←←←←←
 ←←←←←←←←←←←←←   ↖←←←↖ ←←←←←←←←←←← 
 ↖←←←←←←←←←←←←←  ←←←←  ←←←←←←←←←←↖ 
   ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←   
    ←←←←                   ←←←←    
      ←←←←←←←←←←←←←←←←←←←←←←←      
        ←←←←←←←←←←←←←←←←←←←        
            ←←←←←←←←←←←            
  
        """)
    

main()

i received the following as output:

            ←←←←←←←←←←←              ╠═══════════════ ROGUE FETCH ═════════════════════════════╣
        ←←←←←←←←←←←←←←←←←←←          ╠  OS: Windows 11                                         ╣
      ←←←←←←    ←←←←←←←←←←←←←        ╠                                                         ╣
    ←←←←←         ↖←←←←←←←←←←←←      ╠                                                         ╣
   ←←←←     ←←      ←←←←←←←←←←←←     ╠                                                         ╣
 ↖←←←←←     ←←←     ←←←←←←←←←←←←←↖   ╠                                                         ╣
 ←←←←←←←     ←←←    ←←←    ↖←←←←←←   ╠                                                         ╣
←←←←←←←←←     ←↖   ↖←←↖    ←←←←←←←←  ╠═════════════════════════════════════════════════════════╣
←←←←←←←←←←        ←←←←    ↖←←←←←←←←
←←←←←←←←←←←    ↖←←←←←←   ↖←←←←←←←←←
←←←←←←←←←←←←    ←←←←←←  ←←←←←←←←←←←
←←←←←←←←←←←←←    ←←←←←↖←←←←←←←←←←←←
 ←←←←←←←←←←←←←   ↖←←←↖ ←←←←←←←←←←←
 ↖←←←←←←←←←←←←←  ←←←←  ←←←←←←←←←←↖
   ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
    ←←←←                   ←←←←
      ←←←←←←←←←←←←←←←←←←←←←←←
        ←←←←←←←←←←←←←←←←←←←
            ←←←←←←←←←←←
Sign up to request clarification or add additional context in comments.

3 Comments

problem is the string is not always going to be the same size, for example different systems will have a shorter/longer os_string and i need to automatically align them
@storm what I gave you will give you 25 characters of space to fit the string it, if you need 50 characters of space then have the number be 50. in your case use the left justified form of a variable: {os_string:<25} in that case it will ALWAYS pad it to 25 characters even if the os string is 10. that should allow you to finish formating the output correctly. similar handling for uptime_str
@Storm taking it a little farther if your box were say 35 characters wide when you enter your code you would have 10 additional spaces between your vertical bars to pad out the formatted string to keep the bars aligned with the other lines.
0

You have aligned the text according to "{uptime_str}" length instead of the actual length of the string contained. There is mismatch between the alignment in your source code and the visual output.

Use len(uptime_str) and then some padding mechanism like:

"mystring".rjust(how_much_to_pad) or

"mystring".ljust(how_much_to_pad) or

" " * len(uptime_str)

The same problem applies to your os_string

10 Comments

Tried that already, did not work
Please elaborate
I've tried using ljust, however the alignment is still messed up even after
Please update your question with an example of those two lines how you would want to see them.
Like the other ones, properly aligned to the side
|
0

You just need to specify the minimum and maximum field width to be the same.

I have selected 50 chars here:

                    print(Fore.CYAN + f"""


            ←←←←←←←←←←←              ╠═══════════════ ROGUE FETCH ═════════════════════════════╣
        ←←←←←←←←←←←←←←←←←←←          ╠  {                                 os_string:50.50}     ╣
      ←←←←←←    ←←←←←←←←←←←←←        ╠                                                         ╣
    ←←←←←         ↖←←←←←←←←←←←←      ╠  {                                uptime_str:50.50}     ╣
   ←←←←     ←←      ←←←←←←←←←←←←     ╠                                                         ╣
 ↖←←←←←     ←←←     ←←←←←←←←←←←←←↖   ╠                                                         ╣
 ←←←←←←←     ←←←    ←←←    ↖←←←←←←   ╠                                                         ╣
←←←←←←←←←     ←↖   ↖←←↖    ←←←←←←←←  ╠═════════════════════════════════════════════════════════╣
←←←←←←←←←←        ←←←←    ↖←←←←←←←←
←←←←←←←←←←←    ↖←←←←←←   ↖←←←←←←←←←
←←←←←←←←←←←←    ←←←←←←  ←←←←←←←←←←←
←←←←←←←←←←←←←    ←←←←←↖←←←←←←←←←←←←
 ←←←←←←←←←←←←←   ↖←←←↖ ←←←←←←←←←←← 
 ↖←←←←←←←←←←←←←  ←←←←  ←←←←←←←←←←↖ 
   ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←   
    ←←←←                   ←←←←    
      ←←←←←←←←←←←←←←←←←←←←←←←      
        ←←←←←←←←←←←←←←←←←←←        
            ←←←←←←←←←←←            
  
        """)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.