GiorgosXou / TUIFIManager

A cross-platform terminal-based termux-oriented file manager (and component), meant to be used with a Uni-Curses project or as is.
GNU General Public License v3.0
688 stars 13 forks source link

Extracting "ascii images" to files #36

Open Sigmanificient opened 1 year ago

Sigmanificient commented 1 year ago

It would be really nice to have a separation for the ASCII files icons into their own files outside the codebase.

This would make organization easier, adding new files type an easy manner and improve the possibility for customization. I would think of having metadata along the ascii art, such a the file extensions.

For later on it could be a way to add better / small icons too while keeping the code clean with a simple loader helper

GiorgosXou commented 1 year ago

It would be really nice to have a separation for the ASCII files icons into their own files outside the codebase.

Yes, this is something I was thinking about, too. It is a great idea to have a seperate file, where the user will be able to overide any icon\profile of any already existing-or-not extension, but...

... while keeping the code clean with a simple loader helper

It's nice to have, all the default icons\profiles preloaded into TUIFIProfile.py too (just like they are now), because that file is converted to .pyc aka bytecode. And such, tuifi launches way faster than trying to preload the icons\profiles from a file (and I can assure you that it already launches quite slowly)


My thoughts on how it should be implemented:

And such, if tuifi_profile_path-env-variable exists then overide the existing dictionary-values else continue with the default ones


Feel free to do so if you feel confident about it and have the necessary time for it. As of now I'll probably go to sleep in a while and when I wake up tomorrow, most likely I'll work on using custom commands inside tuifi

Sigmanificient commented 1 year ago

I And such, tuifi launches way faster than trying to preload the icons\profiles from a file

I'm not sure how you are bench marking your code, but it's seems to me that even loading thousand of files wouldn't impact at all the speed of the preload:

generating 1k "icons" containing 500 random characters

from random import randint

for i in range(1000):
    data = ''.join(chr(randint(0, 255)) for _ in range(500))

    with open(f'icons/test_file_{i}.txt', 'w') as f:
        content = f.write(data)

Reading everything


import pathlib
from time import perf_counter

marker = perf_counter()

store = {}

def chunk(line, size): return '\n'.join(line[i:i+size] for i in range(0, len(line), size))

for i in range(1000): filename = f'icons/testfile{i}.txt' content = pathlib.Path(filename).read_text() store[filename] = chunk(content, 10)

print(store) elapsed = perf_counter() - marker print(f"> {elapsed * 1000:,.5f} ms")



> `61.30778 ms` 

I took about 60 millisecond with a pretty much beyond worse case scenario
Even accounting for file parsing and string chunking, this wouldn't barely reach the 100ms
So i don't think it could cause any kind of bottleneck
GiorgosXou commented 1 year ago

I'm not sure how you are bench marking your code

it already takes about 3 seconds to startup on my 2016 debloated phone :P

There are going to be more features and that 10ms will be 20 and 30 and go on with each release. Having to construct and alocate memory for each TUIFIProfile on the go for every each icon while reading a file line by line, doesn't sound a good idea by default. Don't you think that it's better to have the icons in TUIFIProfile.py and then overiding the dictionary with the new ones if tuifi_profile_path-env exists? what's you thoughts about it?

Sigmanificient commented 1 year ago

Well, i'm not sure that trying to squeeze every bit of performance when writing python code is a good practice. To me it seems that trying to run it on a pretty much 7 year old smartphone is an impossible endeavor. Python is not really designed for running on smartphones as an user-app, performances in like pydroid and other are disastrous, without even mentioning the age of your device.

I think you should prioritize a cleaner codebase here and maybe create some kind of light mode if you really wanna run it on your phone. I don't think you'll be able to easily reduce that startup time for your device, without scarifying features and getting into the ugly parts of python.

Btw, i don't think that making a lot of memory allocation is a huge problem in python. The language as a ton of abstraction and talking about memory allocation often just don't makes a lot of sense. Every objects will allocate more memory than your average C code, but python has it own memory management system called pymalloc to optimize small allocations.

Moreover, It would be terrible to drop possible improvements as i think this as a lot of potential. I believe this app could replace my gui file manager at some point, but i'm waiting for more feature before throwing away nautilus.

Your are the owner of the repo, so the decision is up to you

GiorgosXou commented 1 year ago

It would be terrible to drop possible improvements

I won't, this feature will definitely be implemeted. I just can't see why it would be better to have all the default icons removed from the TUIFIProfile.py to an external file by default. I don't think that it adds any complexity to it having them there *(and if tuifi_profile_path-env exists load them from a file)

GiorgosXou commented 1 year ago

(Btw thank you for helping me out <3 on this project, I do really appreciate it)

GiorgosXou commented 1 year ago

Maybe I'm missing something, idk