Skip to content

Commit

Permalink
Merges the new command engine
Browse files Browse the repository at this point in the history
Command engine rework into master!
  • Loading branch information
samuelhnrq authored Oct 7, 2017
2 parents 8085a41 + 8445e18 commit 978b221
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 468 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,7 @@ fabric.properties
# .idea/misc.xml
# *.ipr

# VSCode
.vscode/

# End of https://www.gitignore.io/api/osx,python,pycharm
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: false
dist: trusty
language: python
python:
- 3.5 # currently Travis trusty default Python3 is 3.5.2
- 3.6 # currently Travis trusty default Python3 is 3.5.2
#- 3.6.1
#- "nightly" # currently points to 3.7-dev (3.7.0a0)
install:
Expand Down
92 changes: 47 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Sample Set #1 | Sample Set #2

# How to Install

Type `python3 -V` in your terminal to verify that you have [Python 3.5](https://www.python.org/downloads/) or later installed.
Type `python3 -V` in your terminal to verify that you have [Python 3.6](https://www.python.org/downloads/) or later installed.

## npm

Expand All @@ -36,7 +36,7 @@ You can install in any (npm-supported) OS using `npm install --global pokemon-te
## Mac OS

1. Make sure you have [Python 3.5](https://www.python.org/downloads/mac-osx/) or higher.
1. Make sure you have [Python 3.6](https://www.python.org/downloads/mac-osx/) or higher.
2. Make sure you have [iTerm2](http://www.iterm2.com/downloads.html).
3. Copy and paste the following for the installation:
```
Expand All @@ -55,7 +55,7 @@ You can install in any (npm-supported) OS using `npm install --global pokemon-te

## Linux

1. Make sure you have Python 3.5+ installed, check the instructions of your distribution.
1. Make sure you have Python 3.6+ installed, check the instructions of your distribution.
2. Make sure you have Terminology or Tilix, again check the package manager of your distribution.
3. Install
- If you are a Arch Linux User, you can install it from the AUR package [pokemon-terminal-git](https://aur.archlinux.org/packages/pokemon-terminal-git/).
Expand All @@ -71,44 +71,45 @@ You can install in any (npm-supported) OS using `npm install --global pokemon-te
## Usage

```

Usage:
pokemon [parameter]
ichooseyou [parameter]

Parameters:
[name] - Change the terminal background to the specified Pokemon.
[index] - Change the terminal background to a Pokemon by its index.
[region] - List all the Pokemon of the specified region.
[one letter] - List all Pokemon who's names begin with a particular letter.
[two letters] - List all Pokemon who's names begin with those two letters.

Other Parameters:
all - List all the Pokemon supported.
regions - List all the available regions.
extra - List all the Pokemon from the 'Extra' folder.
random - Change the terminal background to a random Pokemon.
random-<region> - Change the terminal background to a random Pokemon from the specified region.
slideshow [time] - Iterate through each Pokemon. Optional time (in seconds) between Pokemon.
slideshow-<region> [time] - Iterate through each Pokemon in the specified region. Optional time (in seconds) between Pokemon.
rnd-slideshow [time] - Iterate through each Pokemon in a random order. Optional time (in seconds) between Pokemon.
rnd-slideshow-<region> [time] - Iterate through each Pokemon in the specified region in a random order. Optional time (in seconds) between Pokemon.
light - Change the terminal background to a random light-colored Pokemon.
dark - Change the terminal background to a random dark-colored Pokemon.
type [type] - Change to a random pokemon of said type.
clear | disable | off - Clear the Pokemon in the terminal.
help - Display this menu.

Wallpaper Parameters:
pokemon _pikachu - Change the wallpaper to the specified Pokemon.
pokemon _random - Change the wallpaper to a random Pokemon.
pokemon _random-kanto - Change the wallpaper to a random Pokemon from the specified region.

Search System Information:
Any input containing 3 or more characters triggers the internal search system. Examples:
"pokemon pika" changes the terminal background to Pikachu.
"pokemon dos" changes the terminal background to Gyarados.

usage: pokemon [-h] [-n NAME] [-r {kanto,johto,hoenn,sinnoh}] [-l [0.xx]]
[-d [0.xx]]
[-t {normal,fire,fighting,water,flying,grass,poison,electric,
ground,psychic,rock,ice,bug,dragon,ghost,dark,steel,fairy}]
[-ne] [-e] [-w] [-v] [-dr] [-c] [id]

Set a pokemon to the current terminal background or wallpaper

positional arguments:
id Specify the desired pokemon ID

optional arguments:
-h, --help show this help message and exit
-c, --clear Clears the current pokemon from terminal background
and quits.

Filters:
Arguments used to filter the list of pokemons with various conditions

-n/--name NAME Filter by pokemon which name contains NAME
-r/--region {kanto,johto,hoenn,sinnoh}
Filter the pokemons by region
-l/--light [0.xx] Filter out the pokemons darker then 0.xx
-d/--dark [0.xx]
Filter out the pokemons lighter then 0.xx
-t/--type {normal,fire,fighting,water,flying,grass,poison,electric,ground,
psychic,rock,ice,bug,dragon,ghost,dark,steel,fairy}
Filter the pokemons by type.
-ne/--no-extras Excludes extra pokemons
-e/--extras Excludes all non-extra pokemons

Misc:
-w, --wallpaper Changes the desktop wallpapper instead of the terminal
background
-v, --verbose Enables verbose output
-dr, --dry-run Implies -v and doesn't actually changes the wallpapper
or background after the pokemon has been chosen

Not setting any filters will get a completly random pokemon
```
Example:
Expand All @@ -135,7 +136,7 @@ The result should look like this:
The folder *Images/Extra* is for adding custom images. You can manually add backgrounds to this folder and they will be visible to the program. Only JPG format is supported. To see a list of all the custom backgrounds type:
```
$ pokemon extra
$ pokemon -e -dr
```
Alternatively, you can delete images from this folder and it will not break the program. These are some custom backgrounds:
Expand All @@ -161,8 +162,8 @@ Alternatively, you can delete images from this folder and it will not break the
I have not yet implemented a way to save the terminal background to a profile. To save a background you will need to setup a startup command in the profile.
1. Navigate to iTerm2 > Preferences > General
2. Locate the field where it says *Send text at start* under *Command*.
3. In that field type "pokemon [pokemon name]". You can see an example in the image down below.
- Alternatively you can also type "pokemon random" for a random theme each time you open up a new terminal.
3. In that field type "pokemon -n [pokemon name]". You can see an example in the image down below.
- Alternatively you can also type "pokemon" for a random theme each time you open up a new terminal.
4. You can leave out "; clear" if you don't care about the line showing up at the top of the terminal.
![alt-tag](Samples/saving.png)
Expand All @@ -182,9 +183,10 @@ fi
3. You may also want to check if terminology is actually running before trying to set the background, so that leads us to
```bash
if [[ "$TERMINOLOGY" -eq "1" ]]; then
pokemon random
pokemon
fi
```
That will simply pick a completly random pokemon each session, but the `pokemon` line is simply calling the app, so you can still filter with regions, darkness, and etc. like you normally would, or you can also reset to a preset pokemon everytime you start.

# Notes & Credits

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pokemon-terminal",
"version": "1.0.7",
"version": "1.1.0",
"description": "Pokemon terminal themes",
"bin": {
"pokemon": "pokemon",
Expand All @@ -23,4 +23,4 @@
"url": "https://github.com/LazoCoder/Pokemon-Terminal/issues"
},
"homepage": "https://github.com/LazoCoder/Pokemon-Terminal#readme"
}
}
2 changes: 1 addition & 1 deletion pokemon
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import sys
from pokemonterminal.main import main


main(sys.argv)
main(sys.argv[1:])
3 changes: 2 additions & 1 deletion pokemonterminal/adapter/implementations/ITerm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def is_available():
return os.environ.get("ITERM_PROFILE")

def __run_osascript(self, stream):
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
p.stdin.write(stream)
p.communicate()
p.stdin.close()
Expand Down
27 changes: 10 additions & 17 deletions pokemonterminal/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ def __str__(self):

class Database:
"""The Database object is a container for all the supported Pokemon."""
__POKEMON_TYPES = ('normal', 'fire', 'fighting', 'water', 'flying',
'grass', 'poison', 'electric', 'ground', 'psychic',
'rock', 'ice', 'bug', 'dragon', 'ghost', 'dark',
'steel', 'fairy')
POKEMON_TYPES = ('normal', 'fire', 'fighting', 'water', 'flying',
'grass', 'poison', 'electric', 'ground', 'psychic',
'rock', 'ice', 'bug', 'dragon', 'ghost', 'dark',
'steel', 'fairy')
__directory = "" # The global location of the code.
__MAX_ID = 719 # Highest possible Pokemon ID.
__regions = ('kanto', 'johto', 'hoenn', 'sinnoh', 'unova', 'kalos')
MAX_ID = 719 # Highest possible Pokemon ID.
REGIONS = ('kanto', 'johto', 'hoenn', 'sinnoh', 'unova', 'kalos')

def __init__(self):
self.__pokemon_list = []
self.__pokemon_dictionary = {}
self.__pokemon_type_dictionary = {}
self.directory = os.path.dirname(os.path.realpath(__file__))
for pkmn_t in self.__POKEMON_TYPES:
for pkmn_t in self.POKEMON_TYPES:
self.__pokemon_type_dictionary[pkmn_t] = []
self.__load_data()
self.__load_extra()
Expand All @@ -90,9 +90,6 @@ def __contains__(self, pokemon):
def __len__(self):
return len(self.__pokemon_list)

def get_pokemon_types(self):
return [t for t in self.__POKEMON_TYPES]

def get_pokemon_of_type(self, pkmn_type: str, single: bool = True):
pkmns = self.__pokemon_type_dictionary.get(pkmn_type)
if pkmns is None:
Expand All @@ -105,10 +102,6 @@ def get_all(self):
# or... return self.__pokemon_list[:]
# return a copy of self.__pokemon_list

def get_regions(self):
# Get all the supported regions.
return self.__regions

def get_kanto(self):
# Get all the Pokemon from the Kanto region.
return self.__get_region("kanto")
Expand Down Expand Up @@ -163,7 +156,7 @@ def get_random_from_region(self, region):
def pokemon_id_exists(self, identifier):
# Check for Pokemon by ID.
identifier = int(identifier)
return 0 < identifier <= self.__MAX_ID
return 0 < identifier <= self.MAX_ID

def pokemon_name_exists(self, name):
# Check for Pokemon by Name.
Expand Down Expand Up @@ -200,7 +193,7 @@ def get_pokemon_by_id(self, identifier):
identifier = int(identifier)
if not self.pokemon_id_exists(identifier):
raise Exception("The Pokemon ID must be between 1 and " +
str(self.__MAX_ID) + " inclusive.")
str(self.MAX_ID) + " inclusive.")
# Subtract 1 to convert to 0 base indexing.
return self.__pokemon_list[identifier - 1]

Expand Down Expand Up @@ -234,7 +227,7 @@ def __load_data(self):
self.__pokemon_type_dictionary[pkmn_type].append(pokemon)
if pkmn_type_snd != '':
self.__pokemon_type_dictionary[pkmn_type_snd]\
.append(pokemon)
.append(pokemon)
self.__pokemon_list.append(pokemon)
self.__pokemon_dictionary[pokemon.get_name()] = pokemon

Expand Down
66 changes: 66 additions & 0 deletions pokemonterminal/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from argparse import Action
from pokemonterminal.database import Database, Pokemon


class Filter(Action):
POKEMON_LIST = Database().get_all()
filtered_list = [p for p in POKEMON_LIST]
FILTERS = []
EXAMPLE_VAL = None

def matches(self, pokemon, value):
raise NotImplementedError

def __init_subclass__(cls, **kwargs):
Filter.FILTERS.append(cls)

def __call__(self, parser, namespace, value, option_string=None):
Filter.filtered_list = [pkmn for pkmn in Filter.filtered_list
if self.matches(pkmn, value)]


class NameFilter(Filter):
EXAMPLE_VAL = 'bulb'

def matches(self, pokemon: Pokemon, value: str):
return value in pokemon.get_name()


class RegionFilter(Filter):
EXAMPLE_VAL = 'kanto'

def matches(self, pokemon: Pokemon, value: str):
return pokemon.get_region() == value


class LightFilter(Filter):
EXAMPLE_VAL = 0.7

def matches(self, pokemon: Pokemon, value: float):
return pokemon.get_dark_threshold() > value


class DarkFilter(Filter):
EXAMPLE_VAL = 0.4

def matches(self, pokemon: Pokemon, value: float):
return pokemon.get_dark_threshold() < value


class TypeFilter(Filter):
EXAMPLE_VAL = 'water'

def matches(self, pokemon: Pokemon, value: str):
value = value.lower()
return value in (pokemon.get_pkmn_type(),
pokemon.get_pkmn_type_secondary())


class NonExtrasFilter(Filter):
def matches(self, pokemon: Pokemon, value):
return not pokemon.is_extra()


class ExtrasFilter(Filter):
def matches(self, pokemon: Pokemon, value):
return pokemon.is_extra()
Loading

0 comments on commit 978b221

Please sign in to comment.