swastkk/FOSS-HACK24

Implementation of Global Variables for Selected Index and Indexing the Grid for dynamic changes in Global State accessible to other functions.

Opened this issue · 0 comments

Currently, the code seems to follow procedural architecture which can be converted into a functional programming paradigm if global states of variables are declared. For the Navigation of the window from one cell to another in the grid, indexing must be done to make it easy to follow the selected image.

This screenshot shows the run function which is currently handling the whole thing:
Screenshot 2024-07-20 at 20 05 02

This is where the Navigation Occurs but gets into a never-ending for loop and causes issues in re-rendering with the previous code:
Screenshot 2024-07-20 at 20 05 41

Now the solution can be to create global variables for SelectedIndex which would hold the parameters of the which cell is selected.

The SelectedIndex adheres to the slice called GridIndex which holds the coordinates of the grid and assigns an index to it.

This makes the code allow the Navigation function to be asynchronous with goroutines and update the selected index to move as per the keyboard instructions.

On top of that, when the user resizes the window, an interrupt would be generated (since we are functionally programming and using goroutines). When a window resize is detected, the GridIndex and SelectedIndex would change due to fitting purposes in the window. Hence, it would be updated here and there, while the Navigation performs its own thing, that is to navigate as per the GridIndex and SelectedIndex is present.

This solved the overall issue of getting cluttering the code and since I believe in the Unix Philosophy, a function should do one thing and do it well.

P.S. The global variables would be stored in the main. go and it would even help to debug the issues with the state of variables declared into it.

I know I am too early to post this, but it must look something like this. They are some of the notes I added for referring.
Screenshot 2024-07-20 at 20 16 50