Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IV Kitten Development - A Dynamically Recursive Image Grid Layout for Kitty Terminal #7674

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

PythonHacker24
Copy link
Contributor

Introduction to IV Kitten - Project by Team /dev/null

IV kitten is fully implemented in Golang which recursively searches for images in the given directory and prints them on the kitty terminal using Kitty Graphical Protocol as mentioned in the kovidgoyal/kitty-fosshack2024#4 for FOSSHack 2024 by Team /dev/null.

The IV kitten is a highly productive image-searching kitten for Kitty Terminal for Power Users. It harnesses the power of Golang with the speed and security of code. We have taken references from Game Development and knowledge of Computer Graphics because of the highly dynamic parameters that change in the background. We have made use of multi-threaded programming to keep keyboard input controls and terminal window size responsive in the background with Golang's powerful Concurrency and Unix's system calls to interrupt the main thread with handlers.

Concurrent Programming with Golang

We believe in multi-threaded code for faster performance in terminals like Kitty and made sure that we harness the goroutines. Since keyboard and window sizes are variable and have unexpected inputs at any time, having a handler to acknowledge these inputs and interrupt the main thread is necessary. So we did low-level interactions with kernel drivers for keyboard input as well as used system calls for interrupts related to resizing the window.

Globally defined Data-Structures

Since we have taken inspiration from computer graphics and game development, we have heavily defined data structures to be accessible globally by any function where it's required which helps in acknowledging variations in the program. We have made use of structs for keeping track of various parameters like Grid Parameters, Window Parameters, Configuration files, Navigation Parameters, Image Boundaries, etc.

Functional Programming Paradigm

Unix Philosophy is "Do one thing and do it right" and by adhering to the principle, we made all the functions to one task at a time. This allows almost all functionalities to have access to the globally declared data. Also, wherever we can (in future), can get these functions in goroutines.

Grid Implementation and Rendering

Rendering had a huge deal of mathematics and geometry in it. We have tried implementing them in the form of code, which in 2 days was not feasible even for 4 of us. A large amount of work has been accomplished in this term, but we would be continuing the make efforts to ensure we complete it till the end.

Future Development

This was a heavy project to complete in 2 days. So we have planned to dedicate time to further expand on and develop the current code base. Since it's MVP, we would be working on fixing bugs and issues, making sure that this kitten reaches the production environment.

Signed-off-Aditya adityapatil24680@gmail.com

PythonHacker24 and others added 15 commits July 27, 2024 19:33
Signed-off-by: swastik <swastkk@gmail.com>
- Add PlaceImageInGrid function to handle image positioning in grid
- Integrate with globalImageBound and globalWindowParameters
- Implement coordinate conversion from logical to actual grid positions
- Calculate grid cell dimensions based on window size and grid parameters
- Add image loading and decoding functionality
- Integrate ScaleAndCenterImage for proper image sizing and centering
- Calculate final image position within the grid
- Handle errors for file operations and image processing
- Return scaled image and its final position for rendering

This commit introduces the core functionality for placing images in a
grid layout. PlaceImageInGrid dynamically calculates image positions,
handles scaling and centering, and prepares images for display in the
terminal. It forms the foundation for the image viewing functionality
in our kitty-based image viewer.
Implement PlaceImageInGrid for dynamic image placement
@kovidgoyal
Copy link
Owner

Cool, congrats on getting to an MVP in the two days. Now if you want this to become mergeable into kitty, you will need to refactor various parts of it to use the kitty kittens infrastructure.

  1. Command line processing should be done using kitty's framework for it, see for example how the icat kitten does it. You define a main.py and specify your options there, then you make it a subcommand of the main kitten command by adding the entry point in tools/cmd/tool/main.go

When you run make kitty build system will automatically generate the code to parse the command line and provide you with a parsed options object.

  1. You should migrate to using the kitty kitten loop api, see any of the themes/diff/choose-fonts kittens for examples of writing full screen programs using it. Then you can drop all that code to parse keyboard events, mouse events etc.

  2. The config file should be in the same format as the rest of kitty's config files, for which there is existing tooling to parse, see the diff kitten or ssh kitten for an example

  3. There should be no new Go dependencies needed for anything in this project, all the required tool are already present. If you have a doubt about how to do something, just ask.

@kovidgoyal
Copy link
Owner

Here this commit shows you how to integrate a kitten into the kitty kittens CLI parsing framework.
5c1af0f

Run it with

kitten notify -h

@Legend101Zz
Copy link

Legend101Zz commented Jul 28, 2024

Great Thanks alot for the feedback Kovid :) ...
We'll start working on it , due you have any specific deadline in mind ?

@PythonHacker24
Copy link
Contributor Author

Thanks, Kovid for the feedback. It was awesome working on the MVP, will keep working on it. Also thanks for the detailed instructions.

@kovidgoyal
Copy link
Owner

Great Thanks alot for the feedback Kovid :) ... We'll start working on it , due you have any specific deadline in mind ?

No I dont have any deadline in mind. To me its far more important it be done well than done fast.

@PythonHacker24
Copy link
Contributor Author

@kovidgoyal Is there any documentation on how /kitty/cli works and how it's interfaced properly? I have seen the icat's source code and it's somewhat clearer but some resources to define it and explain it would help a lot. Also, let me know where are the same resources for others like keyboard and mouse interactions.

@kovidgoyal
Copy link
Owner

There is no documentation for internal kitty interfaces I'm afraid. If
you have some specific questions, just ask.

As my commit above shows, all you need to above is define the options in
simple text format in main.py. Add some boilerplate under if name ==
'main' and run make it will generate the options object and related
machinery for you.

@PythonHacker24
Copy link
Contributor Author

Okay @kovidgoyal, I will refer to the source code for it. Would you also like for me to create some docs once I understand this procedure into official docs for future reference to other developers?

@kovidgoyal
Copy link
Owner

kovidgoyal commented Aug 1, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants