-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,713 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${fileDirname}", | ||
"console": "externalTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package interpreter | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/elgopher/pi/devtools/internal/interpreter/internal/lib" | ||
) | ||
|
||
func printHelp(topic string) { | ||
switch topic { | ||
case "": | ||
println("This is interactive terminal. " + | ||
"You can write Go code here, which will run immediately in the paused game. " + | ||
"You can use all Pi packages: pi, key, state, snap, font, image and " + | ||
"selection of standard packages: " + strings.Join(stdPackages(), ", ") + ". " + | ||
"\n\n" + | ||
"Type help topic for more information. For example: help pi or help pi.Spr") | ||
default: | ||
goDoc(topic) | ||
} | ||
} | ||
|
||
func stdPackages() []string { | ||
var packages []string | ||
for _, p := range lib.AllPackages() { | ||
if p.IsStdPackage() { | ||
packages = append(packages, p.Alias) | ||
} | ||
} | ||
sort.Strings(packages) | ||
return packages | ||
} | ||
|
||
func goDoc(symbol string) { | ||
fmt.Println("###############################################################################") | ||
|
||
symbol = completeSymbol(symbol) | ||
if symbolNotSupported(symbol) { | ||
fmt.Println("no help found") | ||
return | ||
} | ||
|
||
var args []string | ||
args = append(args, "doc") | ||
if shouldShowDetailedDescriptionForSymbol(symbol) { | ||
args = append(args, "-all") | ||
} | ||
args = append(args, symbol) | ||
command := exec.Command("go", args...) | ||
command.Stdout = bufio.NewWriter(os.Stdout) | ||
if err := command.Run(); err != nil { | ||
var exitErr *exec.ExitError | ||
if isExitErr := errors.As(err, &exitErr); isExitErr && exitErr.ExitCode() == 1 { | ||
fmt.Println("no help found") | ||
return | ||
} | ||
fmt.Println("problem getting help:", err) | ||
} | ||
return | ||
} | ||
|
||
func completeSymbol(symbol string) string { | ||
packages := lib.AllPackages() | ||
|
||
for _, p := range packages { | ||
if p.Alias == symbol { | ||
return p.Name | ||
} | ||
} | ||
|
||
for _, p := range packages { | ||
prefix := p.Alias + "." | ||
if strings.HasPrefix(symbol, prefix) { | ||
return p.Name + "." + symbol[len(prefix):] | ||
} | ||
} | ||
|
||
return symbol | ||
} | ||
|
||
func symbolNotSupported(symbol string) bool { | ||
packages := lib.AllPackages() | ||
|
||
for _, p := range packages { | ||
prefix := p.Name + "." | ||
if strings.HasPrefix(symbol, prefix) || symbol == p.Name { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
var symbolsWithDetailedDescription = []string{ | ||
"github.com/elgopher/pi.Button", | ||
"github.com/elgopher/pi.MouseButton", | ||
"github.com/elgopher/pi/key.Button", | ||
} | ||
|
||
func shouldShowDetailedDescriptionForSymbol(symbol string) bool { | ||
for _, s := range symbolsWithDetailedDescription { | ||
if symbol == s { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
16 changes: 16 additions & 0 deletions
16
devtools/internal/interpreter/internal/lib/github_com-elgopher-pi-font.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
devtools/internal/interpreter/internal/lib/github_com-elgopher-pi-image.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
devtools/internal/interpreter/internal/lib/github_com-elgopher-pi-key.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.