Embed runtime files in the go binary

This commit is contained in:
Zachary Yedidia
2016-04-18 09:35:53 -04:00
parent 9d4c6a8b43
commit 8656335da4
7 changed files with 2271 additions and 40 deletions

View File

@@ -1,13 +1,15 @@
build: syn-files build:
go get -d ./cmd/micro go get -d ./cmd/micro
go build -o micro ./cmd/micro go build -o micro ./cmd/micro
install: syn-files build install:
mv micro $(GOBIN) go get -d ./cmd/micro
go install -o micro ./cmd/micro
syn-files: runtime:
mkdir -p ~/.micro go get -u github.com/jteeuwen/go-bindata/...
cp -r runtime/* ~/.micro go-bindata -o runtime.go data/
mv runtime.go cmd/micro
test: test:
go get -d ./cmd/micro go get -d ./cmd/micro

View File

@@ -53,21 +53,16 @@ Micro is devel-only for now because there is no released version.
| [32 bit Linux](http://zbyedidia.webfactional.com/micro/binaries/micro-linux32.tar.gz) | | [32 bit Linux](http://zbyedidia.webfactional.com/micro/binaries/micro-linux32.tar.gz) |
| [Arm Linux](http://zbyedidia.webfactional.com/micro/binaries/micro-linux-arm.tar.gz) | | [Arm Linux](http://zbyedidia.webfactional.com/micro/binaries/micro-linux-arm.tar.gz) |
Once you have downloaded the file, you can install the runtime files by running `./install.sh`
in the directory you downloaded. This will place all the runtime files in `~/.micro`.
To run the micro binary just run `./bin/micro` (you may want to place the binary on your path for ease of use). To run the micro binary just run `./bin/micro` (you may want to place the binary on your path for ease of use).
### Building from source ### Building from source
Micro is made in Go so you must have Go installed on your system to build it. Micro is made in Go so you must have Go installed on your system to build it.
You can simply `go get` it, although if you want syntax highlighting and colors, you need to also install the runtime You can simply `go get` it.
files to `~/.micro`.
``` ```
go get -v -u github.com/zyedidia/micro/cmd/micro go get -u github.com/zyedidia/micro/cmd/micro
mkdir $HOME/.micro && cp -r $GOPATH/src/github.com/zyedidia/micro/runtime/* $HOME/.micro/
``` ```
### Clipboard support ### Clipboard support
@@ -129,10 +124,12 @@ The syntax option can simply be on or off, so for example to turn syntax highlig
The colorscheme can be selected from all the files in the `~/.micro/colorschemes/` directory. Micro comes by default with three colorschemes: The colorscheme can be selected from all the files in the `~/.micro/colorschemes/` directory. Micro comes by default with three colorschemes:
* default: this is the default colorscheme * default: this is the default colorscheme.
* solarized: this is the solarized colorscheme (used in the screenshot). You should have the solarized color palette in your terminal to use it * solarized: this is the solarized colorscheme (used in the screenshot). You should have the solarized color palette in your terminal to use it.
* solarized-tc: this is the solarized colorscheme for true color, just make sure your terminal supports true color before using it and that the `MICRO_TRUECOLOR` environment variable is set to 1 before starting micro. * solarized-tc: this is the solarized colorscheme for true color, just make sure your terminal supports true color before using it and that the `MICRO_TRUECOLOR` environment variable is set to 1 before starting micro.
These are embedded in the Go binary, but to see their source code, look [here](./runtime/colorschemes)
Any option you set in the editor will be saved to the file `~/.micro/settings.json` so, in effect, your configuration file will be created Any option you set in the editor will be saved to the file `~/.micro/settings.json` so, in effect, your configuration file will be created
for you. If you'd like to take your configuration with you to another machine, simply copy the `settings.json` to the other machine. for you. If you'd like to take your configuration with you to another machine, simply copy the `settings.json` to the other machine.

View File

@@ -16,6 +16,8 @@ type Colorscheme map[string]tcell.Style
// The current colorscheme // The current colorscheme
var colorscheme Colorscheme var colorscheme Colorscheme
var preInstalledColors = [3]string{"default", "solarized", "solarized-tc"}
// InitColorscheme picks and initializes the colorscheme when micro starts // InitColorscheme picks and initializes the colorscheme when micro starts
func InitColorscheme() { func InitColorscheme() {
LoadDefaultColorscheme() LoadDefaultColorscheme()
@@ -44,6 +46,16 @@ func LoadColorscheme(colorschemeName, dir string) {
colorscheme = ParseColorscheme(string(text)) colorscheme = ParseColorscheme(string(text))
} }
} }
for _, name := range preInstalledColors {
if name == colorschemeName {
data, err := Asset("runtime/colorschemes/" + name + ".micro")
if err != nil {
TermMessage("Unable to load pre-installed colorscheme " + name)
}
colorscheme = ParseColorscheme(string(data))
}
}
} }
// ParseColorscheme parses the text definition for a colorscheme and returns the corresponding object // ParseColorscheme parses the text definition for a colorscheme and returns the corresponding object

View File

@@ -29,6 +29,86 @@ type SyntaxRule struct {
var syntaxFiles map[[2]*regexp.Regexp]FileTypeRules var syntaxFiles map[[2]*regexp.Regexp]FileTypeRules
var preInstalledSynFiles = []string{
"Dockerfile",
"apacheconf",
"arduino",
"asciidoc",
"asm",
"awk",
"c",
"cmake",
"coffeescript",
"colortest",
"conf",
"conky",
"csharp",
"css",
"cython",
"d",
"dot",
"erb",
"fish",
"fortran",
"gentoo",
"git",
"glsl",
"go",
"groff",
"haml",
"haskell",
"html",
"ini",
"inputrc",
"java",
"javascript",
"json",
"keymap",
"kickstart",
"ledger",
"lisp",
"lua",
"makefile",
"man",
"markdown",
"mpdconf",
"nanorc",
"nginx",
"ocaml",
"patch",
"peg",
"perl",
"perl6",
"php",
"pkg-config",
"pkgbuild",
"po",
"pov",
"privoxy",
"puppet",
"python",
"reST",
"rpmspec",
"ruby",
"rust",
"scala",
"sed",
"sh",
"sls",
"sql",
"swift",
"systemd",
"tcl",
"tex",
"vala",
"vi",
"xml",
"xresources",
"yaml",
"yum",
"zsh",
}
// LoadSyntaxFiles loads the syntax files from the default directory ~/.micro // LoadSyntaxFiles loads the syntax files from the default directory ~/.micro
func LoadSyntaxFiles() { func LoadSyntaxFiles() {
home, err := homedir.Dir() home, err := homedir.Dir()
@@ -37,6 +117,39 @@ func LoadSyntaxFiles() {
return return
} }
LoadSyntaxFilesFromDir(home + "/.micro/syntax") LoadSyntaxFilesFromDir(home + "/.micro/syntax")
for _, filetype := range preInstalledSynFiles {
data, err := Asset("runtime/syntax/" + filetype + ".micro")
if err != nil {
TermMessage("Unable to load pre-installed syntax file " + filetype)
continue
}
LoadSyntaxFile(string(data), filetype+".micro")
}
}
// LoadSyntaxFilesFromDir loads the syntax files from a specified directory
// To load the syntax files, we must fill the `syntaxFiles` map
// This involves finding the regex for syntax and if it exists, the regex
// for the header. Then we must get the text for the file and the filetype.
func LoadSyntaxFilesFromDir(dir string) {
InitColorscheme()
syntaxFiles = make(map[[2]*regexp.Regexp]FileTypeRules)
files, _ := ioutil.ReadDir(dir)
for _, f := range files {
if filepath.Ext(f.Name()) == ".micro" {
filename := dir + "/" + f.Name()
text, err := ioutil.ReadFile(filename)
if err != nil {
TermMessage("Error loading syntax file " + filename + ": " + err.Error())
return
}
LoadSyntaxFile(string(text), filename)
}
}
} }
// JoinRule takes a syntax rule (which can be multiple regular expressions) // JoinRule takes a syntax rule (which can be multiple regular expressions)
@@ -54,13 +167,8 @@ func JoinRule(rule string) string {
// Example: color comment "//.*" // Example: color comment "//.*"
// This would color all strings that match the regex "//.*" in the comment color defined // This would color all strings that match the regex "//.*" in the comment color defined
// by the colorscheme // by the colorscheme
func LoadSyntaxFile(filename string) { func LoadSyntaxFile(text, filename string) {
text, err := ioutil.ReadFile(filename) var err error
if err != nil {
TermMessage("Error loading syntax file " + filename + ": " + err.Error())
return
}
lines := strings.Split(string(text), "\n") lines := strings.Split(string(text), "\n")
// Regex for parsing syntax statements // Regex for parsing syntax statements
@@ -220,22 +328,6 @@ func LoadSyntaxFile(filename string) {
} }
} }
// LoadSyntaxFilesFromDir loads the syntax files from a specified directory
// To load the syntax files, we must fill the `syntaxFiles` map
// This involves finding the regex for syntax and if it exists, the regex
// for the header. Then we must get the text for the file and the filetype.
func LoadSyntaxFilesFromDir(dir string) {
InitColorscheme()
syntaxFiles = make(map[[2]*regexp.Regexp]FileTypeRules)
files, _ := ioutil.ReadDir(dir)
for _, f := range files {
if filepath.Ext(f.Name()) == ".micro" {
LoadSyntaxFile(dir + "/" + f.Name())
}
}
}
// GetRules finds the syntax rules that should be used for the buffer // GetRules finds the syntax rules that should be used for the buffer
// and returns them. It also returns the filetype of the file // and returns them. It also returns the filetype of the file
func GetRules(buf *Buffer) ([]SyntaxRule, string) { func GetRules(buf *Buffer) ([]SyntaxRule, string) {

2127
cmd/micro/runtime.go Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,4 @@
# Runtime files for Micro # Runtime files for Micro
The contents of this directory should be put in `~/.micro`. This directory will be embedded in the Go binary for portability, but it may just as well be put in `~/.micro`. If you would like to make your own colorschemes
and syntax files, you can put in in `~/.micro/colorschemes` and `~/.micro/syntax` respectively.

View File

@@ -4,7 +4,7 @@ mkdir -p binaries
mkdir -p micro/bin mkdir -p micro/bin
cp -r runtime micro/ cp -r runtime micro/
echo 'mkdir -p ~/.micro && cp -r runtime/* ~/.micro' >> micro/install.sh echo 'mkdir -p ~/.micro' >> micro/install.sh
chmod +x micro/install.sh chmod +x micro/install.sh
# Mac # Mac