Giter VIP home page Giter VIP logo

termifind-rust's Introduction

TermiFind

TermiFind is heavily inspired by the MacOS Finder. The goal of it is to create a cross-compatible tool that behaves like Finder within Terminal. TermiFind is in its infancy; in its current state, it simply takes the current working directory and prints out a structure like this:

main example

It does not accept input, but the ultimate goal would be for TermiFind to be interactive, allowing you to navigate through the directories, open files in native applications, or launch applications, but a lot of groundwork needs to be done first before that task can even begin.

TermiFind will print as many directory containers as it can to the shell window, but will wrap down to a new line if needed:

wrap example

TermiFind has user-customizable settings that are placed in a JSON file. Currently, the path to the settings file has to be set via the code in settings.rs, but if the file does not exist or can't be deserialized properly, a default set of settings can be used; these default settings are also located in settings.rs.

Settings:

File Truncation:

  1. No truncation of file names
  2. Truncation of file names by a constant value
  3. Truncation of file names by level (link to another area to explain this)
  4. Truncation of file names by average file name length
  5. Truncation of file names by outlier (truncate outliers)
  6. Truncation of file names in order to fit as many directory containers horizontally (not implemented)

Note that the string to denote that a file name has been truncated can be changed. The truncation options also allow you to choose if you want to include this string in with the desired length of the truncated file name or not. For example:

Here are two examples of truncation of file name by average file name length.
We are using ...to denote file name truncation.

When printing, the length of the final string, including ... will be that of the average file length. truncation average include truncation string

When printing, the actual text of the file name will be the length of the average file name and then the ... is added on after. truncation average exclude truncation string

Currently, the directory container's name will overrule the truncation settings; file names can be truncated to any length, but the container will always be at least wide enough to print the full container name.

Look:

  • Color coding for directory item types: directories, files, and symlinks
  • Color coding for miscellaneous items: directories in current path and currently selected folder
  • Item type symbols: (D), (F), (S)

Work to be done

There is a lot of work to be done in order to make TermiFind a usable tool. Check the GitHub Issues for some things that could be worked on if you are interested in helping

This README.md file is not comprehensive; more needs to be discussed here.

Note

  • I use Clippy and try to silence all warnings emitted by Clippy
  • I run rustfmt on all Rust files

termifind-rust's People

Contributors

ali-wells avatar josephtlyons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ali-wells

termifind-rust's Issues

Refactor Long Functions

  • Many of the new() functions can be broken up into smaller functions, these can be cleaned up by calling non-self functions and these new functions should be directly below the new() function.
  • Some of the sub-functions of print_path(), such as update_start_and_end_iteration_tuple() are too long and need to be broken up

Look for the // REFACTOR comments

Fix Bad Variable and Function Names

Some function names and variable names currently are not that descriptive, such as print_path(), these should be fixed up and made to be more descriptive.

Should all `enum`s go in Their Own File?

In some places, there are enums that are being used by methods in different impl blocks in different files, despite being defined directly next to only one of the impl blocks, which is a bit misleading. It may make sense to move them all to their own file that can be included wherever they are needed.

File Name Truncation Options

This is my most unorganized item. Here are my notes that I had for this item, but it should be cleaned up at some point.

Truncation options for DirectoryContainer

  • 1. None
    • No truncation of file names
  • 2. Constant
    • Truncates all file names to the same length
  • 3. Level
    • Level 0 -> does not truncate file names, Level 1 -> truncate longest file name to be length of second longest name, Level 1, truncate longest and second longest file name to be length of third longest name, etc.
  • 4. AverageFileNameLength
    • Get the average file name length and truncate all files to it
  • 5. Outliers
    • Using some sort of statistical measurement, identify outliers by some definition and truncate them using Level
  • 6. HorizontalFit
    • Perform some sort of calculation on all DirectoryContainers and find the appropriate file length so that all DirectoryContainers can be printing in one line. This will use the Constant mechanism. This should also probably set the horizontal_spacing_between_directory_containers to 0

It should be noted that we can choose whether or not the string that is used to denote a file name has been truncated can be customized and it can be included in the overall truncation length or it can be excluded from the overall truncation length.

  • If the directory container name is longer than the truncation value, then use container name as the truncation value

Things to consider, but that have not been decided on:

  • Option to allow truncation of directory name too? Not sure, but leaning towards not allowing it, as the directory name is rather important.

  • Should truncation string be placed at the end of the string or in the middle? If it is decided to put it in the middle, changes need to be made to the underlying utility function and unit tests need to be updated. Maybe there could be an option to switch between placing truncation string at the middle or end of the file name.

Numbered Items?

Should directory items be number? If so, should it be optional (a user configurable setting)?

Implement Some Sort of Condensed Path Print

Instead of printing the full path, under this option, the path would just print the last x amount of DirectoryContainers (configurable), the current one, and if the current item selected is a directory, the next DirectoryContainer (see item 2 here). This setting could be used by those who don't care to see too many previous directories and want to reduce the chances of the print wrapping to a new line.

Don't Print Last Vertical Spacing After Final Row of DirectoryContainers

Similarly to how we no longer print the final horizontal spacing at the end of a row, we should skip the vertical spacing at the last row.

When working on this, set:

  • spacing_between_directory_containers_char
  • spacing_between_directory_container_rows_char
  • filler_char

All to symbols other than that space. It makes it easier to debug with.

Arrows Between Directories

A cool thing to maybe implement is an option that, when turned on, would show arrows coming from a selected directory and pointing to the DirectoryContainer name that it relates to. Directories in the current path are already highlighted a specific color, so this isn't necessary, it is just a neat idea.

 -------------      ---------------  
|      /      |   >|     Users     |
|=============|  | |===============|
| (F) .DS_... |  | | (F) .local... |
| (D) .PKI... |  | | (D) Shared    |
| (S) .Vol... |  | | (D) joseph... |
| (F) .file   |  |  --------------- 
| (D) .fse... |  |                
| (D) .vol    |  |                
| (D) Appl... |  |                
| (D) Library |  |                
| (D) System  |  |                
| (D) Users   | -                 
| (D) Volumes |                  
| (D) bin     |                  
| (D) cores   |                                   
| (D) dev     |                                   
| (S) etc     |                                   
| (S) home    |                                   
| (D) opt     |                                   
| (D) private |                                   
| (D) sbin    |                                   
| (S) tmp     |                                   
| (D) usr     |                                   
| (S) var     |                                   
-------------   

Investigate Extra Space Printed After Last DirectoryContainer

More information: The amount of extra space being generated at the end of the path print is equal to the number of DirectoryContainters * the length of the horizontal_spacing_between_directory_containers value.

Note: There will always be one extra line on the right side of the printed path, this is accounted for by the invisible newline characters there.

Handle Empty Folders

TermiFind will most likely blow up when a folder is empty. Test it out and fix any errors that prevent TermiFind working with an empty folder.

Make an empty folder and run it with:

  • Truncation mode set to None
  • Truncation mode set to Outliers (fixed)
  • Truncation mode set to Level (needs fixed)
  • Others

Reduce `clone()` Occurrences Where Possible

In some places where there are Strings being used and clones of those strings are occurring, it would be nice to investigate if it would be possible to replace them with &strs, but #LifetimesAren'tEasyForMe.

Show Directory Metadata Somehow

Find a place to display:

  • number of items in the directory
  • size of the space being used by all files
  • the breakdown of file types (etc. 15 .doc, 3 .rs)
  • any other items

This might be best at the bottom of the directory or the top under the name.

Establish a Convention For Ordering of `pub` and non-`pub` Items

Make a decision on whether pub (functions, struct members, etc.) should be listed at the top or the bottom of the area they are in and use that convention.

The order within the groups of pub versus non-pub items can either be by order of when they are called or alphabetical.

The char `spacing_between_directory_container_rows_char` isn't actually used for what the name implies

If you set spacing_between_directory_container_rows_char to any other char, you'd expect to see one more more (depending on spacing_between_directory_container_rows) horizontal line of that character below each row of DirectoryContainers, but the algorithm that uses this char doesn't quite use it this way and you see a very different result. Either rework the algorithm for this to work the way you'd expect, or remove the setting to be able to use any char and for them to use ' '.

Is it Possible to Rework `print_styled_file_name()` to be `get_styled_file_name()`?

It would be nice to have this function return a printable object versus having it do the printing. This function calls a function in the utils that would need to change as well.

If it could be converted into a function that returns the styled object, then it would not need to be called separately from the get_file_name() function. After changing print_styled_file_name() to get_styled_file_name(), it could be made private and called directly by get_file_name(). get_file_name() would need a new boolean parameter for "should_style_file_name`.

Is There a Way to Fix `print_directory_container_by_row()` to use `match` Entirely?

Currently, there is an if statement wrapping the match block. The if statement is there to avoid the match when printing the last row of the DirectoryContainer. Ideally, match would cover it all:

    match row_number {
        0 => print top row
        ),
        1 => print directory name row
        2 => print separator between directory name and directory items
        range from 3 to the second to the last => print items
        _ => print last row
        }
    }
} 

I attempted this before, but was unsuccessful; an error relating to using a range in the match wouldn't allow me, but maybe there's a way around it.

Linux and Windows Testing

I don't have a good way to test these platforms. I'd appreciate any feedback on these platforms that I can get, such as things breaking or not.

Add a User Setting to Hide or Display Hidden Files

I'm not sure what all this might affect. Do we still include the files in the the file counts and any statistical measurements that require file counts when hidden files are not shown? I'm leaning towards not using hidden files in calculation if they are not displayed.

Use Type Annotations or Not

Make a decision to either:

  1. Use type annotations across the board
  2. Only use them where the compiler complains

And stick with that convention

All Configurable Items Need to be Reached in a Central Place Where They can be Set and Read from a Settings File

Currently, the system supports some customization:

  • Truncation Options
  • Whether the length of the string that denotes truncation should be included in the overall truncation length
  • Vertical and horizontal spacing of DirectoryContainers (amount and character used)
  • chars that are used to build the DirectoryContainers (vertical lines, horizontal lines, dividing line)
  • sort_directory_items() takes in a boolean representing if it should sort the file names by file type or by file name alone

But all of these settings are just sprinkled throughout the system and are only configurable through the code. At some point, these will need to be accessible in a way that they can be saved to a file and loaded.

  • Should provide default settings if any of the operations for getting the settings file fail.

Rename `a` and `b`

Inside update_start_and_end_iteration_tuple(), there are two variables a and b, these suck and are there only because I had no idea what to name them. Fix them at some point.

Be Able to Implement a Fixed DirectoryContainer Height

This will require another issue of implementing some sort of scrolling mechanism, which relates to #2. The point of this would be to limit the height of DirectoryContainers so that rows that wrap around aren't forced down much further because of one long DirectoryContainer. The same sort of statistical measurements that are used on truncating file names (Constant, Level, Average, Outlier) could be used to limit the height of a DirectoryContainer.

Make TermiFind Interactive

TermiFind's ultimate goal is to be interactive, like the macOS Finder. It needs to be fitted with a mechanism to allow for moving through directories and selecting files. This could require some Terminal manipulation libraries, such as:

ncurses-rs
crossterm

These can be used to wipe the screen entirely and reprint the whole structure with any changes based on the interaction or certain parts of the screen can be updated. The second option will probably require a rewrite of the system. I'm more in favor of leaning towards any options that avoid using crates with unsafe Rust code.

Some actions that should be possible are:

  1. Left and right arrow keys to navigate directories, popping off or adding DirectoryContainers on the right side.
  2. Up and down arrow keys to browse files
    • Highlighting a new directory should show a preview of its contents, as either a new DirectoryContainer to the right of the current one.
    • Highlighting a file should show a container with the file's metadata in it.
  3. Pressing enter to open a system application for that file type or to open a terminal editor
  4. Maybe an action to return the currently selected path to the shell and close TermiFind.

Binary insert for `get_file_name_lengths_and_positions_vec()` Should Be Converted To Insert In Reverse Order

Currently, there are a few functions that call get_file_name_lengths_and_positions_vec(). One of them requires the vector returned be in reverse order and one that doesn't care about the order. Currently, the vector is generated in ascending order and then reversed later, but it might be better just to binary insert into it in reverse order to begin with. Once this is done, the reverse() in get_truncation_value_by_level() can be removed.

Use Bold/Italic Styling For Important Items?

The console crate that is used can style text to be bold or italic. It might be worth it to consider styling important things such as directory names, directories in the current path the, currently selected item, etc, in addition to how they are currently color coded.

Fix Infinite Print

If there terminal window is too narrow to display any of the DirectoryContainers, TermiFind will infinitely print in a loop. The Terminal needs to be at least as wide as the widest DirectoryContainer. An error message should show if not and the application should exit.

The fix can be: "If the terminal width is smaller than the current DirectoryContainer, then exit the application with an error. The error could have useful information as to why it crashed, but also maybe at what DirectoryContainer it crashed at.

Fix README.md Screenshots

The screenshots show the error in the wrapping (TermiFind would wrap down to a new column of DirectoryContainers when it still had room to print in the previous row). Take some new ones.

Should Directory Names Include Their File Separate Symbol?

Should a directory container have just the name of the folder or should the dividing symbol (e.g. Uni / Linux =/) be included before it? It makes sense in that if you look at all of the DirectoryContainer names, they would form a valid path if the separator was included, but maybe its prettier to not show it.

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.