mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 22:37:10 +09:00
Embed runtime files in the go binary
This commit is contained in:
14
Makefile
14
Makefile
@@ -1,13 +1,15 @@
|
||||
build: syn-files
|
||||
build:
|
||||
go get -d ./cmd/micro
|
||||
go build -o micro ./cmd/micro
|
||||
|
||||
install: syn-files build
|
||||
mv micro $(GOBIN)
|
||||
install:
|
||||
go get -d ./cmd/micro
|
||||
go install -o micro ./cmd/micro
|
||||
|
||||
syn-files:
|
||||
mkdir -p ~/.micro
|
||||
cp -r runtime/* ~/.micro
|
||||
runtime:
|
||||
go get -u github.com/jteeuwen/go-bindata/...
|
||||
go-bindata -o runtime.go data/
|
||||
mv runtime.go cmd/micro
|
||||
|
||||
test:
|
||||
go get -d ./cmd/micro
|
||||
|
||||
15
README.md
15
README.md
@@ -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) |
|
||||
| [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).
|
||||
|
||||
### Building from source
|
||||
|
||||
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
|
||||
files to `~/.micro`.
|
||||
You can simply `go get` it.
|
||||
|
||||
```
|
||||
go get -v -u github.com/zyedidia/micro/cmd/micro
|
||||
mkdir $HOME/.micro && cp -r $GOPATH/src/github.com/zyedidia/micro/runtime/* $HOME/.micro/
|
||||
go get -u github.com/zyedidia/micro/cmd/micro
|
||||
```
|
||||
|
||||
### 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:
|
||||
|
||||
* 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
|
||||
* 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-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
|
||||
for you. If you'd like to take your configuration with you to another machine, simply copy the `settings.json` to the other machine.
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ type Colorscheme map[string]tcell.Style
|
||||
// The current colorscheme
|
||||
var colorscheme Colorscheme
|
||||
|
||||
var preInstalledColors = [3]string{"default", "solarized", "solarized-tc"}
|
||||
|
||||
// InitColorscheme picks and initializes the colorscheme when micro starts
|
||||
func InitColorscheme() {
|
||||
LoadDefaultColorscheme()
|
||||
@@ -44,6 +46,16 @@ func LoadColorscheme(colorschemeName, dir string) {
|
||||
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
|
||||
|
||||
@@ -29,6 +29,86 @@ type SyntaxRule struct {
|
||||
|
||||
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
|
||||
func LoadSyntaxFiles() {
|
||||
home, err := homedir.Dir()
|
||||
@@ -37,6 +117,39 @@ func LoadSyntaxFiles() {
|
||||
return
|
||||
}
|
||||
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)
|
||||
@@ -54,13 +167,8 @@ func JoinRule(rule string) string {
|
||||
// Example: color comment "//.*"
|
||||
// This would color all strings that match the regex "//.*" in the comment color defined
|
||||
// by the colorscheme
|
||||
func LoadSyntaxFile(filename string) {
|
||||
text, err := ioutil.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
TermMessage("Error loading syntax file " + filename + ": " + err.Error())
|
||||
return
|
||||
}
|
||||
func LoadSyntaxFile(text, filename string) {
|
||||
var err error
|
||||
lines := strings.Split(string(text), "\n")
|
||||
|
||||
// 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
|
||||
// and returns them. It also returns the filetype of the file
|
||||
func GetRules(buf *Buffer) ([]SyntaxRule, string) {
|
||||
|
||||
2127
cmd/micro/runtime.go
Normal file
2127
cmd/micro/runtime.go
Normal file
File diff suppressed because one or more lines are too long
@@ -1,3 +1,4 @@
|
||||
# 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.
|
||||
|
||||
@@ -4,7 +4,7 @@ mkdir -p binaries
|
||||
mkdir -p micro/bin
|
||||
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
|
||||
|
||||
# Mac
|
||||
|
||||
Reference in New Issue
Block a user