Skip to content

Commit

Permalink
Merge pull request #95 from omlins/dev
Browse files Browse the repository at this point in the history
 Open Enable hierarchical command dictionaries, improve recognizer transitions and add advanced keyboard commands
  • Loading branch information
omlins authored Jul 21, 2023
2 parents 6c5ec94 + 6130685 commit d063df0
Show file tree
Hide file tree
Showing 20 changed files with 1,323 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
#- windows-latest # There is some issue with the pre-test pywinctl installation
arch:
- x64
- x86
Expand Down
6 changes: 4 additions & 2 deletions docs/src/software.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ help?> JustSayIt
## Functions to configure and start JustSayIt
#### Index
* [`JustSayIt.start`](@ref)
* [`JustSayIt.@include_config`](@ref)
* [`JustSayIt.@include`](@ref)
* [`JustSayIt.@edit`](@ref)

#### Documentation
```@docs
start
@include_config
@include
@edit
```

## Submodules for command name to function mapping
Expand Down
2 changes: 1 addition & 1 deletion docs/src/usage.MD
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ Detailed information on [`@voiceargs`](@ref) is found in the [High-level API ref

While contributions to the JustSayIt command modules are very much encouraged, it is possible to quickly define and use custom [`@voiceargs`](@ref) functions thanks to the API of JustSayIt ([`JustSayIt.API`](@ref)). It is illustrated in [this example](@ref Quick-definition-and-usage-of-custom-function). More information on the JustSayIt API is given in the [High-level API reference](@ref).

Note that the JustSayIt application config folder (e.g., `~/.config/JustSayIt` on Unix systems) is an easily accessible storage for scripts to start JustSayIt and/or for custom command functions: [`@include_config`](@ref) permits to conveniently `include` files from this folder.
Note that the JustSayIt application config folder (e.g., `~/.config/JustSayIt` on Unix systems) is an easily accessible storage for scripts to start JustSayIt and/or for custom command functions: [`JustSayIt.@include`](@ref) and [`JustSayIt.@edit`](@ref) permit to conveniently `include` and `edit` files from this folder.
44 changes: 44 additions & 0 deletions src/Commands/Generic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Module Generic
Provides generic functions for any kind of operations.
# Functions
###### execute n times
- [`Generic.execute_n_times`](@ref)
To see a description of a function type `?<functionname>`.
"""
module Generic

using ..Exceptions
import ..JustSayIt: @voiceargs, default_language, next_token, execute, LANG, COUNTS, UNKNOWN_TOKEN


## CONSTANTS


## FUNCTIONS

interpret_count(input::AbstractString) = (return COUNTS[default_language()][input])

@doc """
execute_n_times `n` `(complement of) cmd`
Execute a command n times.
"""
execute_n_times
@voiceargs n=>(valid_input=(LANG.DE=>[keys(COUNTS[LANG.DE])...], LANG.EN_US=>[keys(COUNTS[LANG.EN_US])...], LANG.ES=>[keys(COUNTS[LANG.ES])...], LANG.FR=>[keys(COUNTS[LANG.FR])...]), interpret_function=interpret_count, use_max_speed=true) function execute_n_times(n::Int, commands::Dict{String,<:Any}; cmdname::String="do")
# count = parse(Int, token) # NOTE: this is safe as the count is always an integer.
cmd_complement = next_token([keys(commands)...]; ignore_unknown=false)
if (cmd_complement == UNKNOWN_TOKEN) @InsecureRecognitionException("unknown command.") end
@info "$cmdname $n $cmd_complement."
cmd = commands[cmd_complement]
for i in 1:n
execute(cmd, cmdname)
end
end


end # module Generic
13 changes: 10 additions & 3 deletions src/Commands/Help.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ const COMMANDS_KEYWORDS = Dict(LANG.DE => "kommandos",

"Show help for your commands or a spoken command or module."
function help()
commands_keyword = COMMANDS_KEYWORDS[default_language()]
valid_input = [commands_keyword, command_names()...]
valid_input = [COMMANDS_KEYWORDS[default_language()], command_names()...]
keyword = next_token(valid_input; ignore_unknown=false)
if keyword == commands_keyword
help(keyword)
end

function help(keyword)
if keyword == COMMANDS_KEYWORDS[default_language()]
cmd_length_max = maximum(length.(command_names()))
@info join(["", "Your commands:",
map(sort([command_names()...])) do x
Expand All @@ -36,6 +39,10 @@ function help()
@info "Command $keyword" ""=Base.Docs.doc(cmd)
elseif isa(cmd, PyKey)
@info "Command $keyword\n = Keyboard key $(pretty_cmd_string(cmd))"
elseif isa(cmd, String)
@info "Command $keyword\n = Type word $(pretty_cmd_string(cmd))"
elseif isa(cmd, Dict)
@info "Command $keyword\n = Activate additional commands for $keyword"
elseif isa(cmd, Array)
@info "Command $keyword\n = Command sequence $(pretty_cmd_string(cmd))"
else
Expand Down
Loading

0 comments on commit d063df0

Please sign in to comment.