Hi everyone, I made a program which allows you to search for colors. This was a very cool project for me to do as I used a webscraper to scrape all the color data into a
json and used
readchar instead of
input to enable the updating search feature.
Make sure your console view is large enough so you can see the search results properly.
How to use
Let's say you're creating a website and need the perfect color for your header. You'd like a color which is pretty medium, but are not sure which one to pick. Start by searching medium and you'll see a list of colors which contain 'medium' in their name.
How I made it
First of all, I needed to create a dictionary with the color name as the key and a dictionary with the hex and rgb values as the value. Since the data is correlated and jsons are cool, dictionaries were the perfect choice.
Now that the color dictionary was complete, I focused on the search functionality. I wanted the search results to update every time the user pressed a key so
input() wasn't going to cut it.
Instead, I used
readchar which is a library that handles single keypresses. Using this, I could update the search results at each keypress, clearing the screen in between.
Since I was using
readchar and not
input, I had to check if the user entered "Enter" or "Backspace" and respond accordingly. Quick trick: to figure out the codes for keys like enter and backspace, use this.
Turns out that splitting at the forward slash gives you the code. Note that there are 2 \'s because you need to escape it.
I also used the RGB ANSI escape code to color the unicode box.