This is a simple terminal-based shopping list application written in Go. It allows users to manage a shopping list interactively, providing commands to add, remove, search, display items, view the total number of items, and exit the program. The application includes clear terminal functionality for a more user-friendly experience.
- Add Items: Add new items to your shopping list.
- Display List: View all items in your shopping list.
- Remove Items: Remove specific items from your list.
- Search Items: Search for specific items to check if they exist in the list.
- View Total: Display the total number of items in your shopping list.
- Help: View a list of available commands and their descriptions.
- Exit: Quit the application and display the final shopping list.
- Clear Screen: Automatically clears the terminal for a clean user interface.
quit
orq
: Exit the program and display the final shopping list.help
: Show a list of available commands and their descriptions.show
: Display the current shopping list.remove
: Remove a specified item from the shopping list.search
: Check if a specific item exists in the shopping list.total
: Display the total number of items in the shopping list.priority
: Change the priority of an item by moving it to a different position in the list.- Adding Items: Simply type the name of an item to add it to your list.
- Install Go: Ensure that Go is installed on your system.
- Download the Code:
git clone https://github.com/your-username/shopping-list-cli.git cd shopping-list-cli
- Run the Application:
go run main.go
Simply type the name of an item to add it to the list:
Enter an item (type 'quit' to exit, 'help' for commands): apple
Added 'apple' to the shopping list.
Type show
to view all items in your list:
Enter an item (type 'quit' to exit, 'help' for commands): show
Here's your shopping list so far:
--> apple
--> banana
Type total
to display the total number of items in the shopping list:
Enter an item (type 'quit' to exit, 'help' for commands): total
There are a total of 2 items in your shopping list.
Type remove
, then specify the item to remove:
Enter an item (type 'quit' to exit, 'help' for commands): remove
Enter the item you want to remove: banana
Item 'banana' has been removed from the shopping list.
Type search
, then enter the item to search for:
Enter an item (type 'quit' to exit, 'help' for commands): search
Enter the item you want to search: apple
Item 'apple' exists in the list.
Type help
to view the list of available commands:
Enter an item (type 'quit' to exit, 'help' for commands): help
Available commands:
quit - Exit the program
help - Show this help message
show - Display the shopping list
total - Display the total number of items in the shopping list
remove - Remove an item from the shopping list
search - Search for an item in the shopping list
Simply enter an item to add it to the shopping list.
Type quit
or q
to exit the application and display the final shopping list:
Enter an item (type 'quit' to exit, 'help' for commands): quit
Exiting... Here's your shopping list:
--> apple
--> orange
-
main
Function:- The main loop for handling user input and commands.
- Handles adding items, displaying help, showing the list, and other operations.
-
clearScreen
Function:- Clears the terminal for a clean user interface.
- Supports both Linux/macOS (
clear
) and Windows (cls
).
-
Command-Specific Functions:
displayHelp
: Displays a list of available commands.displayShoppingList
: Prints the current shopping list in a formatted style.removeItemFromList
: Removes an item from the list.search
: Checks if an item exists in the shopping list.displayTotal
: Displays the total number of items in the shopping list.
-
Utility Functions:
contains
: Checks if a slice contains a specific item.
Enter an item (type 'quit' to exit, 'help' for commands): apple
Added 'apple' to the shopping list.
Enter an item (type 'quit' to exit, 'help' for commands): banana
Added 'banana' to the shopping list.
Enter an item (type 'quit' to exit, 'help' for commands): show
Here's your shopping list so far:
--> apple
--> banana
Enter an item (type 'quit' to exit, 'help' for commands): total
There are a total of 2 items in your shopping list.
Enter an item (type 'quit' to exit, 'help' for commands): search
Enter the item you want to search: apple
Item 'apple' exists in the list.
Enter an item (type 'quit' to exit, 'help' for commands): remove
Enter the item you want to remove: banana
Item 'banana' has been removed from the shopping list.
Enter an item (type 'quit' to exit, 'help' for commands): quit
Exiting... Here's your shopping list:
--> apple
Feel free to open issues or submit pull requests to improve this application. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for details.