repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
nsf/gocode | _gccgo/package.go | expect_special | func (this *import_data_parser) expect_special(special string) {
i := 0
for i < len(special) {
if this.toktype != rune(special[i]) {
break
}
this.next()
i++
}
if i < len(special) {
this.errorf("expected: \"%s\", got something else", special)
}
} | go | func (this *import_data_parser) expect_special(special string) {
i := 0
for i < len(special) {
if this.toktype != rune(special[i]) {
break
}
this.next()
i++
}
if i < len(special) {
this.errorf("expected: \"%s\", got something else", special)
}
} | [
"func",
"(",
"this",
"*",
"import_data_parser",
")",
"expect_special",
"(",
"special",
"string",
")",
"{",
"i",
":=",
"0",
"\n",
"for",
"i",
"<",
"len",
"(",
"special",
")",
"{",
"if",
"this",
".",
"toktype",
"!=",
"rune",
"(",
"special",
"[",
"i",
... | // makes sure that the following set of tokens matches 'special', reads the next one | [
"makes",
"sure",
"that",
"the",
"following",
"set",
"of",
"tokens",
"matches",
"special",
"reads",
"the",
"next",
"one"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/_gccgo/package.go#L236-L250 | train |
nsf/gocode | _gccgo/package.go | expect_ident | func (this *import_data_parser) expect_ident(ident string) {
tok := this.expect(scanner.Ident)
if tok != ident {
this.errorf("expected identifier: \"%s\", got: \"%s\"", ident, tok)
}
} | go | func (this *import_data_parser) expect_ident(ident string) {
tok := this.expect(scanner.Ident)
if tok != ident {
this.errorf("expected identifier: \"%s\", got: \"%s\"", ident, tok)
}
} | [
"func",
"(",
"this",
"*",
"import_data_parser",
")",
"expect_ident",
"(",
"ident",
"string",
")",
"{",
"tok",
":=",
"this",
".",
"expect",
"(",
"scanner",
".",
"Ident",
")",
"\n",
"if",
"tok",
"!=",
"ident",
"{",
"this",
".",
"errorf",
"(",
"\"",
"\\... | // makes sure that the current token is scanner.Ident and is equals to 'ident', reads the next one | [
"makes",
"sure",
"that",
"the",
"current",
"token",
"is",
"scanner",
".",
"Ident",
"and",
"is",
"equals",
"to",
"ident",
"reads",
"the",
"next",
"one"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/_gccgo/package.go#L253-L258 | train |
nsf/gocode | autocompletefile.go | process_data | func (f *auto_complete_file) process_data(data []byte) {
cur, filedata, block := rip_off_decl(data, f.cursor)
file, err := parser.ParseFile(f.fset, "", filedata, parser.AllErrors)
if err != nil && *g_debug {
log_parse_error("Error parsing input file (outer block)", err)
}
f.package_name = package_name(file)
f.decls = make(map[string]*decl)
f.packages = collect_package_imports(f.name, file.Decls, f.context)
f.filescope = new_scope(nil)
f.scope = f.filescope
for _, d := range file.Decls {
anonymify_ast(d, 0, f.filescope)
}
// process all top-level declarations
for _, decl := range file.Decls {
append_to_top_decls(f.decls, decl, f.scope)
}
if block != nil {
// process local function as top-level declaration
decls, err := parse_decl_list(f.fset, block)
if err != nil && *g_debug {
log_parse_error("Error parsing input file (inner block)", err)
}
for _, d := range decls {
anonymify_ast(d, 0, f.filescope)
}
for _, decl := range decls {
append_to_top_decls(f.decls, decl, f.scope)
}
// process function internals
f.cursor = cur
for _, decl := range decls {
f.process_decl_locals(decl)
}
}
} | go | func (f *auto_complete_file) process_data(data []byte) {
cur, filedata, block := rip_off_decl(data, f.cursor)
file, err := parser.ParseFile(f.fset, "", filedata, parser.AllErrors)
if err != nil && *g_debug {
log_parse_error("Error parsing input file (outer block)", err)
}
f.package_name = package_name(file)
f.decls = make(map[string]*decl)
f.packages = collect_package_imports(f.name, file.Decls, f.context)
f.filescope = new_scope(nil)
f.scope = f.filescope
for _, d := range file.Decls {
anonymify_ast(d, 0, f.filescope)
}
// process all top-level declarations
for _, decl := range file.Decls {
append_to_top_decls(f.decls, decl, f.scope)
}
if block != nil {
// process local function as top-level declaration
decls, err := parse_decl_list(f.fset, block)
if err != nil && *g_debug {
log_parse_error("Error parsing input file (inner block)", err)
}
for _, d := range decls {
anonymify_ast(d, 0, f.filescope)
}
for _, decl := range decls {
append_to_top_decls(f.decls, decl, f.scope)
}
// process function internals
f.cursor = cur
for _, decl := range decls {
f.process_decl_locals(decl)
}
}
} | [
"func",
"(",
"f",
"*",
"auto_complete_file",
")",
"process_data",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"cur",
",",
"filedata",
",",
"block",
":=",
"rip_off_decl",
"(",
"data",
",",
"f",
".",
"cursor",
")",
"\n",
"file",
",",
"err",
":=",
"parser"... | // this one is used for current file buffer exclusively | [
"this",
"one",
"is",
"used",
"for",
"current",
"file",
"buffer",
"exclusively"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/autocompletefile.go#L67-L110 | train |
nsf/gocode | package_ibin.go | pos | func (r *importReader) pos() {
if r.int64() != deltaNewFile {
} else if l := r.int64(); l == -1 {
} else {
r.string()
}
} | go | func (r *importReader) pos() {
if r.int64() != deltaNewFile {
} else if l := r.int64(); l == -1 {
} else {
r.string()
}
} | [
"func",
"(",
"r",
"*",
"importReader",
")",
"pos",
"(",
")",
"{",
"if",
"r",
".",
"int64",
"(",
")",
"!=",
"deltaNewFile",
"{",
"}",
"else",
"if",
"l",
":=",
"r",
".",
"int64",
"(",
")",
";",
"l",
"==",
"-",
"1",
"{",
"}",
"else",
"{",
"r",... | // we don't care about that, let's just skip it | [
"we",
"don",
"t",
"care",
"about",
"that",
"let",
"s",
"just",
"skip",
"it"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_ibin.go#L340-L346 | train |
nsf/gocode | utils.go | readdir_lstat | func readdir_lstat(name string) ([]os.FileInfo, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
names, err := f.Readdirnames(-1)
if err != nil {
return nil, err
}
out := make([]os.FileInfo, 0, len(names))
for _, lname := range names {
s, err := os.Lstat(filepath.Join(name, lname))
if err != nil {
continue
}
out = append(out, s)
}
return out, nil
} | go | func readdir_lstat(name string) ([]os.FileInfo, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
names, err := f.Readdirnames(-1)
if err != nil {
return nil, err
}
out := make([]os.FileInfo, 0, len(names))
for _, lname := range names {
s, err := os.Lstat(filepath.Join(name, lname))
if err != nil {
continue
}
out = append(out, s)
}
return out, nil
} | [
"func",
"readdir_lstat",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n... | // our own readdir, which skips the files it cannot lstat | [
"our",
"own",
"readdir",
"which",
"skips",
"the",
"files",
"it",
"cannot",
"lstat"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/utils.go#L17-L38 | train |
nsf/gocode | utils.go | readdir | func readdir(dirname string) []os.FileInfo {
f, err := os.Open(dirname)
if err != nil {
return nil
}
fi, err := f.Readdir(-1)
f.Close()
if err != nil {
panic(err)
}
return fi
} | go | func readdir(dirname string) []os.FileInfo {
f, err := os.Open(dirname)
if err != nil {
return nil
}
fi, err := f.Readdir(-1)
f.Close()
if err != nil {
panic(err)
}
return fi
} | [
"func",
"readdir",
"(",
"dirname",
"string",
")",
"[",
"]",
"os",
".",
"FileInfo",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"dirname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"fi",
",",
"err",
":="... | // our other readdir function, only opens and reads | [
"our",
"other",
"readdir",
"function",
"only",
"opens",
"and",
"reads"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/utils.go#L41-L52 | train |
nsf/gocode | utils.go | find_gb_project_root | func find_gb_project_root(path string) (string, error) {
path = filepath.Dir(path)
if path == "" {
return "", fmt.Errorf("project root is blank")
}
start := path
for path != "/" {
root := filepath.Join(path, "src")
if _, err := os.Stat(root); err != nil {
if os.IsNotExist(err) {
path = filepath.Dir(path)
continue
}
return "", err
}
path, err := filepath.EvalSymlinks(path)
if err != nil {
return "", err
}
return path, nil
}
return "", fmt.Errorf("could not find project root in %q or its parents", start)
} | go | func find_gb_project_root(path string) (string, error) {
path = filepath.Dir(path)
if path == "" {
return "", fmt.Errorf("project root is blank")
}
start := path
for path != "/" {
root := filepath.Join(path, "src")
if _, err := os.Stat(root); err != nil {
if os.IsNotExist(err) {
path = filepath.Dir(path)
continue
}
return "", err
}
path, err := filepath.EvalSymlinks(path)
if err != nil {
return "", err
}
return path, nil
}
return "", fmt.Errorf("could not find project root in %q or its parents", start)
} | [
"func",
"find_gb_project_root",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"path",
"=",
"filepath",
".",
"Dir",
"(",
"path",
")",
"\n",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(... | // Code taken directly from `gb`, I hope author doesn't mind. | [
"Code",
"taken",
"directly",
"from",
"gb",
"I",
"hope",
"author",
"doesn",
"t",
"mind",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/utils.go#L130-L152 | train |
nsf/gocode | autocompletecontext.go | check_type_expr | func check_type_expr(e ast.Expr) bool {
switch t := e.(type) {
case *ast.StarExpr:
return check_type_expr(t.X)
case *ast.ArrayType:
return check_type_expr(t.Elt)
case *ast.SelectorExpr:
return check_type_expr(t.X)
case *ast.FuncType:
a := check_func_field_list(t.Params)
b := check_func_field_list(t.Results)
return a && b
case *ast.MapType:
a := check_type_expr(t.Key)
b := check_type_expr(t.Value)
return a && b
case *ast.Ellipsis:
return check_type_expr(t.Elt)
case *ast.ChanType:
return check_type_expr(t.Value)
case *ast.BadExpr:
return false
default:
return true
}
} | go | func check_type_expr(e ast.Expr) bool {
switch t := e.(type) {
case *ast.StarExpr:
return check_type_expr(t.X)
case *ast.ArrayType:
return check_type_expr(t.Elt)
case *ast.SelectorExpr:
return check_type_expr(t.X)
case *ast.FuncType:
a := check_func_field_list(t.Params)
b := check_func_field_list(t.Results)
return a && b
case *ast.MapType:
a := check_type_expr(t.Key)
b := check_type_expr(t.Value)
return a && b
case *ast.Ellipsis:
return check_type_expr(t.Elt)
case *ast.ChanType:
return check_type_expr(t.Value)
case *ast.BadExpr:
return false
default:
return true
}
} | [
"func",
"check_type_expr",
"(",
"e",
"ast",
".",
"Expr",
")",
"bool",
"{",
"switch",
"t",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"StarExpr",
":",
"return",
"check_type_expr",
"(",
"t",
".",
"X",
")",
"\n",
"case",
"*",
"a... | // checks for a type expression correctness, it the type expression has
// ast.BadExpr somewhere, returns false, otherwise true | [
"checks",
"for",
"a",
"type",
"expression",
"correctness",
"it",
"the",
"type",
"expression",
"has",
"ast",
".",
"BadExpr",
"somewhere",
"returns",
"false",
"otherwise",
"true"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/autocompletecontext.go#L653-L678 | train |
nsf/gocode | package_bin.go | rawInt64 | func (p *gc_bin_parser) rawInt64() int64 {
i, err := binary.ReadVarint(p)
if err != nil {
panic(fmt.Sprintf("read error: %v", err))
}
return i
} | go | func (p *gc_bin_parser) rawInt64() int64 {
i, err := binary.ReadVarint(p)
if err != nil {
panic(fmt.Sprintf("read error: %v", err))
}
return i
} | [
"func",
"(",
"p",
"*",
"gc_bin_parser",
")",
"rawInt64",
"(",
")",
"int64",
"{",
"i",
",",
"err",
":=",
"binary",
".",
"ReadVarint",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
... | // rawInt64 should only be used by low-level decoders. | [
"rawInt64",
"should",
"only",
"be",
"used",
"by",
"low",
"-",
"level",
"decoders",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_bin.go#L696-L702 | train |
nsf/gocode | package_bin.go | rawStringln | func (p *gc_bin_parser) rawStringln(b byte) string {
p.buf = p.buf[:0]
for b != '\n' {
p.buf = append(p.buf, b)
b = p.rawByte()
}
return string(p.buf)
} | go | func (p *gc_bin_parser) rawStringln(b byte) string {
p.buf = p.buf[:0]
for b != '\n' {
p.buf = append(p.buf, b)
b = p.rawByte()
}
return string(p.buf)
} | [
"func",
"(",
"p",
"*",
"gc_bin_parser",
")",
"rawStringln",
"(",
"b",
"byte",
")",
"string",
"{",
"p",
".",
"buf",
"=",
"p",
".",
"buf",
"[",
":",
"0",
"]",
"\n",
"for",
"b",
"!=",
"'\\n'",
"{",
"p",
".",
"buf",
"=",
"append",
"(",
"p",
".",
... | // rawStringln should only be used to read the initial version string. | [
"rawStringln",
"should",
"only",
"be",
"used",
"to",
"read",
"the",
"initial",
"version",
"string",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_bin.go#L705-L712 | train |
nsf/gocode | declcache.go | collect_package_imports | func collect_package_imports(filename string, decls []ast.Decl, context *package_lookup_context) []package_import {
pi := make([]package_import, 0, 16)
for _, decl := range decls {
if gd, ok := decl.(*ast.GenDecl); ok && gd.Tok == token.IMPORT {
for _, spec := range gd.Specs {
imp := spec.(*ast.ImportSpec)
path, alias := path_and_alias(imp)
abspath, ok := abs_path_for_package(filename, path, context)
if ok && alias != "_" {
pi = append(pi, package_import{alias, abspath, path})
}
}
} else {
break
}
}
return pi
} | go | func collect_package_imports(filename string, decls []ast.Decl, context *package_lookup_context) []package_import {
pi := make([]package_import, 0, 16)
for _, decl := range decls {
if gd, ok := decl.(*ast.GenDecl); ok && gd.Tok == token.IMPORT {
for _, spec := range gd.Specs {
imp := spec.(*ast.ImportSpec)
path, alias := path_and_alias(imp)
abspath, ok := abs_path_for_package(filename, path, context)
if ok && alias != "_" {
pi = append(pi, package_import{alias, abspath, path})
}
}
} else {
break
}
}
return pi
} | [
"func",
"collect_package_imports",
"(",
"filename",
"string",
",",
"decls",
"[",
"]",
"ast",
".",
"Decl",
",",
"context",
"*",
"package_lookup_context",
")",
"[",
"]",
"package_import",
"{",
"pi",
":=",
"make",
"(",
"[",
"]",
"package_import",
",",
"0",
",... | // Parses import declarations until the first non-import declaration and fills
// `packages` array with import information. | [
"Parses",
"import",
"declarations",
"until",
"the",
"first",
"non",
"-",
"import",
"declaration",
"and",
"fills",
"packages",
"array",
"with",
"import",
"information",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L29-L46 | train |
nsf/gocode | declcache.go | autobuild | func autobuild(p *build.Package) error {
if p.Dir == "" {
return fmt.Errorf("no files to build")
}
ps, err := os.Stat(p.PkgObj)
if err != nil {
// Assume package file does not exist and build for the first time.
return build_package(p)
}
pt := ps.ModTime()
fs, err := readdir_lstat(p.Dir)
if err != nil {
return err
}
for _, f := range fs {
if f.IsDir() {
continue
}
if f.ModTime().After(pt) {
// Source file is newer than package file; rebuild.
return build_package(p)
}
}
return nil
} | go | func autobuild(p *build.Package) error {
if p.Dir == "" {
return fmt.Errorf("no files to build")
}
ps, err := os.Stat(p.PkgObj)
if err != nil {
// Assume package file does not exist and build for the first time.
return build_package(p)
}
pt := ps.ModTime()
fs, err := readdir_lstat(p.Dir)
if err != nil {
return err
}
for _, f := range fs {
if f.IsDir() {
continue
}
if f.ModTime().After(pt) {
// Source file is newer than package file; rebuild.
return build_package(p)
}
}
return nil
} | [
"func",
"autobuild",
"(",
"p",
"*",
"build",
".",
"Package",
")",
"error",
"{",
"if",
"p",
".",
"Dir",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ps",
",",
"err",
":=",
"os",
".",
"Stat",
"(... | // autobuild compares the mod time of the source files of the package, and if any of them is newer
// than the package object file will rebuild it. | [
"autobuild",
"compares",
"the",
"mod",
"time",
"of",
"the",
"source",
"files",
"of",
"the",
"package",
"and",
"if",
"any",
"of",
"them",
"is",
"newer",
"than",
"the",
"package",
"object",
"file",
"will",
"rebuild",
"it",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L192-L216 | train |
nsf/gocode | declcache.go | try_autobuild | func try_autobuild(p *build.Package) {
if g_config.Autobuild {
err := autobuild(p)
if err != nil && *g_debug {
log.Printf("Autobuild error: %s\n", err)
}
}
} | go | func try_autobuild(p *build.Package) {
if g_config.Autobuild {
err := autobuild(p)
if err != nil && *g_debug {
log.Printf("Autobuild error: %s\n", err)
}
}
} | [
"func",
"try_autobuild",
"(",
"p",
"*",
"build",
".",
"Package",
")",
"{",
"if",
"g_config",
".",
"Autobuild",
"{",
"err",
":=",
"autobuild",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"*",
"g_debug",
"{",
"log",
".",
"Printf",
"(",
"\"",... | // executes autobuild function if autobuild option is enabled, logs error and
// ignores it | [
"executes",
"autobuild",
"function",
"if",
"autobuild",
"option",
"is",
"enabled",
"logs",
"error",
"and",
"ignores",
"it"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L257-L264 | train |
nsf/gocode | declcache.go | gopath | func (ctxt *package_lookup_context) gopath() []string {
var all []string
for _, p := range filepath.SplitList(ctxt.GOPATH) {
if p == "" || p == ctxt.GOROOT {
// Empty paths are uninteresting.
// If the path is the GOROOT, ignore it.
// People sometimes set GOPATH=$GOROOT.
// Do not get confused by this common mistake.
continue
}
if strings.HasPrefix(p, "~") {
// Path segments starting with ~ on Unix are almost always
// users who have incorrectly quoted ~ while setting GOPATH,
// preventing it from expanding to $HOME.
// The situation is made more confusing by the fact that
// bash allows quoted ~ in $PATH (most shells do not).
// Do not get confused by this, and do not try to use the path.
// It does not exist, and printing errors about it confuses
// those users even more, because they think "sure ~ exists!".
// The go command diagnoses this situation and prints a
// useful error.
// On Windows, ~ is used in short names, such as c:\progra~1
// for c:\program files.
continue
}
all = append(all, p)
}
return all
} | go | func (ctxt *package_lookup_context) gopath() []string {
var all []string
for _, p := range filepath.SplitList(ctxt.GOPATH) {
if p == "" || p == ctxt.GOROOT {
// Empty paths are uninteresting.
// If the path is the GOROOT, ignore it.
// People sometimes set GOPATH=$GOROOT.
// Do not get confused by this common mistake.
continue
}
if strings.HasPrefix(p, "~") {
// Path segments starting with ~ on Unix are almost always
// users who have incorrectly quoted ~ while setting GOPATH,
// preventing it from expanding to $HOME.
// The situation is made more confusing by the fact that
// bash allows quoted ~ in $PATH (most shells do not).
// Do not get confused by this, and do not try to use the path.
// It does not exist, and printing errors about it confuses
// those users even more, because they think "sure ~ exists!".
// The go command diagnoses this situation and prints a
// useful error.
// On Windows, ~ is used in short names, such as c:\progra~1
// for c:\program files.
continue
}
all = append(all, p)
}
return all
} | [
"func",
"(",
"ctxt",
"*",
"package_lookup_context",
")",
"gopath",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"all",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"filepath",
".",
"SplitList",
"(",
"ctxt",
".",
"GOPATH",
")",
"{",
"... | // gopath returns the list of Go path directories. | [
"gopath",
"returns",
"the",
"list",
"of",
"Go",
"path",
"directories",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/declcache.go#L431-L459 | train |
nsf/gocode | decl.go | infer_type | func (d *decl) infer_type() (ast.Expr, *scope) {
// special case for range vars
if d.is_rangevar() {
var scope *scope
d.typ, scope = infer_range_type(d.value, d.scope, d.value_index)
return d.typ, scope
}
switch d.class {
case decl_package:
// package is handled specially in inferType
return nil, nil
case decl_type:
return ast.NewIdent(d.name), d.scope
}
// shortcut
if d.typ != nil && d.value == nil {
return d.typ, d.scope
}
// prevent loops
if d.is_visited() {
return nil, nil
}
d.set_visited()
defer d.clear_visited()
var scope *scope
d.typ, scope, _ = infer_type(d.value, d.scope, d.value_index)
return d.typ, scope
} | go | func (d *decl) infer_type() (ast.Expr, *scope) {
// special case for range vars
if d.is_rangevar() {
var scope *scope
d.typ, scope = infer_range_type(d.value, d.scope, d.value_index)
return d.typ, scope
}
switch d.class {
case decl_package:
// package is handled specially in inferType
return nil, nil
case decl_type:
return ast.NewIdent(d.name), d.scope
}
// shortcut
if d.typ != nil && d.value == nil {
return d.typ, d.scope
}
// prevent loops
if d.is_visited() {
return nil, nil
}
d.set_visited()
defer d.clear_visited()
var scope *scope
d.typ, scope, _ = infer_type(d.value, d.scope, d.value_index)
return d.typ, scope
} | [
"func",
"(",
"d",
"*",
"decl",
")",
"infer_type",
"(",
")",
"(",
"ast",
".",
"Expr",
",",
"*",
"scope",
")",
"{",
"// special case for range vars",
"if",
"d",
".",
"is_rangevar",
"(",
")",
"{",
"var",
"scope",
"*",
"scope",
"\n",
"d",
".",
"typ",
"... | // Uses Value, ValueIndex and Scope to infer the type of this
// declaration. Returns the type itself and the scope where this type
// makes sense. | [
"Uses",
"Value",
"ValueIndex",
"and",
"Scope",
"to",
"infer",
"the",
"type",
"of",
"this",
"declaration",
".",
"Returns",
"the",
"type",
"itself",
"and",
"the",
"scope",
"where",
"this",
"type",
"makes",
"sense",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/decl.go#L954-L985 | train |
nsf/gocode | scope.go | add_named_decl | func (s *scope) add_named_decl(d *decl) *decl {
return s.add_decl(d.name, d)
} | go | func (s *scope) add_named_decl(d *decl) *decl {
return s.add_decl(d.name, d)
} | [
"func",
"(",
"s",
"*",
"scope",
")",
"add_named_decl",
"(",
"d",
"*",
"decl",
")",
"*",
"decl",
"{",
"return",
"s",
".",
"add_decl",
"(",
"d",
".",
"name",
",",
"d",
")",
"\n",
"}"
] | // adds declaration or returns an existing one | [
"adds",
"declaration",
"or",
"returns",
"an",
"existing",
"one"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/scope.go#L39-L41 | train |
nsf/gocode | cursorcontext.go | deduce_cursor_decl | func (c *auto_complete_context) deduce_cursor_decl(iter *token_iterator) (*decl, ast.Expr) {
expr, err := parser.ParseExpr(iter.extract_go_expr())
if err != nil {
return nil, nil
}
return expr_to_decl(expr, c.current.scope), expr
} | go | func (c *auto_complete_context) deduce_cursor_decl(iter *token_iterator) (*decl, ast.Expr) {
expr, err := parser.ParseExpr(iter.extract_go_expr())
if err != nil {
return nil, nil
}
return expr_to_decl(expr, c.current.scope), expr
} | [
"func",
"(",
"c",
"*",
"auto_complete_context",
")",
"deduce_cursor_decl",
"(",
"iter",
"*",
"token_iterator",
")",
"(",
"*",
"decl",
",",
"ast",
".",
"Expr",
")",
"{",
"expr",
",",
"err",
":=",
"parser",
".",
"ParseExpr",
"(",
"iter",
".",
"extract_go_e... | // this function is called when the cursor is at the '.' and you need to get the
// declaration before that dot | [
"this",
"function",
"is",
"called",
"when",
"the",
"cursor",
"is",
"at",
"the",
".",
"and",
"you",
"need",
"to",
"get",
"the",
"declaration",
"before",
"that",
"dot"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/cursorcontext.go#L264-L270 | train |
nsf/gocode | cursorcontext.go | deduce_struct_type_decl | func (c *auto_complete_context) deduce_struct_type_decl(iter *token_iterator) *decl {
typ := iter.extract_struct_type()
if typ == "" {
return nil
}
expr, err := parser.ParseExpr(typ)
if err != nil {
return nil
}
decl := type_to_decl(expr, c.current.scope)
if decl == nil {
return nil
}
// we allow only struct types here, but also support type aliases
if decl.is_alias() {
dd := decl.type_dealias()
if _, ok := dd.typ.(*ast.StructType); !ok {
return nil
}
} else if _, ok := decl.typ.(*ast.StructType); !ok {
return nil
}
return decl
} | go | func (c *auto_complete_context) deduce_struct_type_decl(iter *token_iterator) *decl {
typ := iter.extract_struct_type()
if typ == "" {
return nil
}
expr, err := parser.ParseExpr(typ)
if err != nil {
return nil
}
decl := type_to_decl(expr, c.current.scope)
if decl == nil {
return nil
}
// we allow only struct types here, but also support type aliases
if decl.is_alias() {
dd := decl.type_dealias()
if _, ok := dd.typ.(*ast.StructType); !ok {
return nil
}
} else if _, ok := decl.typ.(*ast.StructType); !ok {
return nil
}
return decl
} | [
"func",
"(",
"c",
"*",
"auto_complete_context",
")",
"deduce_struct_type_decl",
"(",
"iter",
"*",
"token_iterator",
")",
"*",
"decl",
"{",
"typ",
":=",
"iter",
".",
"extract_struct_type",
"(",
")",
"\n",
"if",
"typ",
"==",
"\"",
"\"",
"{",
"return",
"nil",... | // try to find and extract the surrounding struct literal type | [
"try",
"to",
"find",
"and",
"extract",
"the",
"surrounding",
"struct",
"literal",
"type"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/cursorcontext.go#L273-L298 | train |
nsf/gocode | package.go | new_package_file_cache_forever | func new_package_file_cache_forever(name, defalias string) *package_file_cache {
m := new(package_file_cache)
m.name = name
m.mtime = -1
m.defalias = defalias
return m
} | go | func new_package_file_cache_forever(name, defalias string) *package_file_cache {
m := new(package_file_cache)
m.name = name
m.mtime = -1
m.defalias = defalias
return m
} | [
"func",
"new_package_file_cache_forever",
"(",
"name",
",",
"defalias",
"string",
")",
"*",
"package_file_cache",
"{",
"m",
":=",
"new",
"(",
"package_file_cache",
")",
"\n",
"m",
".",
"name",
"=",
"name",
"\n",
"m",
".",
"mtime",
"=",
"-",
"1",
"\n",
"m... | // Creates a cache that stays in cache forever. Useful for built-in packages. | [
"Creates",
"a",
"cache",
"that",
"stays",
"in",
"cache",
"forever",
".",
"Useful",
"for",
"built",
"-",
"in",
"packages",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package.go#L43-L49 | train |
nsf/gocode | package.go | append_packages | func (c package_cache) append_packages(ps map[string]*package_file_cache, pkgs []package_import) {
for _, m := range pkgs {
if _, ok := ps[m.abspath]; ok {
continue
}
if mod, ok := c[m.abspath]; ok {
ps[m.abspath] = mod
} else {
mod = new_package_file_cache(m.abspath, m.path)
ps[m.abspath] = mod
c[m.abspath] = mod
}
}
} | go | func (c package_cache) append_packages(ps map[string]*package_file_cache, pkgs []package_import) {
for _, m := range pkgs {
if _, ok := ps[m.abspath]; ok {
continue
}
if mod, ok := c[m.abspath]; ok {
ps[m.abspath] = mod
} else {
mod = new_package_file_cache(m.abspath, m.path)
ps[m.abspath] = mod
c[m.abspath] = mod
}
}
} | [
"func",
"(",
"c",
"package_cache",
")",
"append_packages",
"(",
"ps",
"map",
"[",
"string",
"]",
"*",
"package_file_cache",
",",
"pkgs",
"[",
"]",
"package_import",
")",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"pkgs",
"{",
"if",
"_",
",",
"ok",
":=... | // Function fills 'ps' set with packages from 'packages' import information.
// In case if package is not in the cache, it creates one and adds one to the cache. | [
"Function",
"fills",
"ps",
"set",
"with",
"packages",
"from",
"packages",
"import",
"information",
".",
"In",
"case",
"if",
"package",
"is",
"not",
"in",
"the",
"cache",
"it",
"creates",
"one",
"and",
"adds",
"one",
"to",
"the",
"cache",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package.go#L228-L242 | train |
nsf/gocode | package_text.go | parse_package | func (p *gc_parser) parse_package() *ast.Ident {
path, err := strconv.Unquote(p.expect(scanner.String))
if err != nil {
panic(err)
}
return ast.NewIdent(path)
} | go | func (p *gc_parser) parse_package() *ast.Ident {
path, err := strconv.Unquote(p.expect(scanner.String))
if err != nil {
panic(err)
}
return ast.NewIdent(path)
} | [
"func",
"(",
"p",
"*",
"gc_parser",
")",
"parse_package",
"(",
")",
"*",
"ast",
".",
"Ident",
"{",
"path",
",",
"err",
":=",
"strconv",
".",
"Unquote",
"(",
"p",
".",
"expect",
"(",
"scanner",
".",
"String",
")",
")",
"\n",
"if",
"err",
"!=",
"ni... | // ImportPath = string_lit .
// quoted name of the path, but we return it as an identifier, taking an alias
// from 'pathToAlias' map, it is filled by import statements | [
"ImportPath",
"=",
"string_lit",
".",
"quoted",
"name",
"of",
"the",
"path",
"but",
"we",
"return",
"it",
"as",
"an",
"identifier",
"taking",
"an",
"alias",
"from",
"pathToAlias",
"map",
"it",
"is",
"filled",
"by",
"import",
"statements"
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L161-L168 | train |
nsf/gocode | package_text.go | parse_name | func (p *gc_parser) parse_name() (string, ast.Expr) {
switch p.tok {
case scanner.Ident:
name := p.lit
p.next()
return name, ast.NewIdent(name)
case '?':
p.next()
return "?", ast.NewIdent("?")
case '@':
en := p.parse_exported_name()
return en.Sel.Name, en
}
p.error("name expected")
return "", nil
} | go | func (p *gc_parser) parse_name() (string, ast.Expr) {
switch p.tok {
case scanner.Ident:
name := p.lit
p.next()
return name, ast.NewIdent(name)
case '?':
p.next()
return "?", ast.NewIdent("?")
case '@':
en := p.parse_exported_name()
return en.Sel.Name, en
}
p.error("name expected")
return "", nil
} | [
"func",
"(",
"p",
"*",
"gc_parser",
")",
"parse_name",
"(",
")",
"(",
"string",
",",
"ast",
".",
"Expr",
")",
"{",
"switch",
"p",
".",
"tok",
"{",
"case",
"scanner",
".",
"Ident",
":",
"name",
":=",
"p",
".",
"lit",
"\n",
"p",
".",
"next",
"(",... | // Name = identifier | "?" | ExportedName . | [
"Name",
"=",
"identifier",
"|",
"?",
"|",
"ExportedName",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L185-L200 | train |
nsf/gocode | package_text.go | parse_type_decl | func (p *gc_parser) parse_type_decl() (string, *ast.GenDecl) {
p.expect_keyword("type")
name := p.parse_exported_name()
typ := p.parse_type()
return name.X.(*ast.Ident).Name, &ast.GenDecl{
Tok: token.TYPE,
Specs: []ast.Spec{
&ast.TypeSpec{
Name: name.Sel,
Type: typ,
},
},
}
} | go | func (p *gc_parser) parse_type_decl() (string, *ast.GenDecl) {
p.expect_keyword("type")
name := p.parse_exported_name()
typ := p.parse_type()
return name.X.(*ast.Ident).Name, &ast.GenDecl{
Tok: token.TYPE,
Specs: []ast.Spec{
&ast.TypeSpec{
Name: name.Sel,
Type: typ,
},
},
}
} | [
"func",
"(",
"p",
"*",
"gc_parser",
")",
"parse_type_decl",
"(",
")",
"(",
"string",
",",
"*",
"ast",
".",
"GenDecl",
")",
"{",
"p",
".",
"expect_keyword",
"(",
"\"",
"\"",
")",
"\n",
"name",
":=",
"p",
".",
"parse_exported_name",
"(",
")",
"\n",
"... | // TypeDecl = "type" ExportedName Type . | [
"TypeDecl",
"=",
"type",
"ExportedName",
"Type",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L538-L551 | train |
nsf/gocode | package_text.go | parse_var_decl | func (p *gc_parser) parse_var_decl() (string, *ast.GenDecl) {
p.expect_keyword("var")
name := p.parse_exported_name()
typ := p.parse_type()
return name.X.(*ast.Ident).Name, &ast.GenDecl{
Tok: token.VAR,
Specs: []ast.Spec{
&ast.ValueSpec{
Names: []*ast.Ident{name.Sel},
Type: typ,
},
},
}
} | go | func (p *gc_parser) parse_var_decl() (string, *ast.GenDecl) {
p.expect_keyword("var")
name := p.parse_exported_name()
typ := p.parse_type()
return name.X.(*ast.Ident).Name, &ast.GenDecl{
Tok: token.VAR,
Specs: []ast.Spec{
&ast.ValueSpec{
Names: []*ast.Ident{name.Sel},
Type: typ,
},
},
}
} | [
"func",
"(",
"p",
"*",
"gc_parser",
")",
"parse_var_decl",
"(",
")",
"(",
"string",
",",
"*",
"ast",
".",
"GenDecl",
")",
"{",
"p",
".",
"expect_keyword",
"(",
"\"",
"\"",
")",
"\n",
"name",
":=",
"p",
".",
"parse_exported_name",
"(",
")",
"\n",
"t... | // VarDecl = "var" ExportedName Type . | [
"VarDecl",
"=",
"var",
"ExportedName",
"Type",
"."
] | 5bee97b488366fd20b054d0861b89834ff5bbfb2 | https://github.com/nsf/gocode/blob/5bee97b488366fd20b054d0861b89834ff5bbfb2/package_text.go#L554-L567 | train |
veandco/go-sdl2 | ttf/sdl_ttf.go | RenderUTF8BlendedWrapped | func (f *Font) RenderUTF8BlendedWrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error) {
_text := C.CString(text)
defer C.free(unsafe.Pointer(_text))
_c := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)}
surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended_Wrapped(f.f, _text, _c, C.Uint32(wrapLength))))
if surface == nil {
return nil, GetError()
}
return surface, nil
} | go | func (f *Font) RenderUTF8BlendedWrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error) {
_text := C.CString(text)
defer C.free(unsafe.Pointer(_text))
_c := C.SDL_Color{C.Uint8(fg.R), C.Uint8(fg.G), C.Uint8(fg.B), C.Uint8(fg.A)}
surface := (*sdl.Surface)(unsafe.Pointer(C.TTF_RenderUTF8_Blended_Wrapped(f.f, _text, _c, C.Uint32(wrapLength))))
if surface == nil {
return nil, GetError()
}
return surface, nil
} | [
"func",
"(",
"f",
"*",
"Font",
")",
"RenderUTF8BlendedWrapped",
"(",
"text",
"string",
",",
"fg",
"sdl",
".",
"Color",
",",
"wrapLength",
"int",
")",
"(",
"*",
"sdl",
".",
"Surface",
",",
"error",
")",
"{",
"_text",
":=",
"C",
".",
"CString",
"(",
... | // RenderUTF8BlendedWrapped creates a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color. Text is wrapped to multiple lines on line endings and on word boundaries if it extends beyond wrapLength in pixels. | [
"RenderUTF8BlendedWrapped",
"creates",
"a",
"32",
"-",
"bit",
"ARGB",
"surface",
"and",
"render",
"the",
"given",
"text",
"at",
"high",
"quality",
"using",
"alpha",
"blending",
"to",
"dither",
"the",
"font",
"with",
"the",
"given",
"color",
".",
"Text",
"is"... | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/ttf/sdl_ttf.go#L176-L185 | train |
veandco/go-sdl2 | raster/painter.go | Paint | func (p *ImagePainter) Paint(ss []raster.Span, done bool) {
// Convert color to RGBA
dr, dg, db, da := p.c.RGBA() // 16 bit values
// Alpha mask
const m = 1<<16 - 1
// Draw spans
b := p.Image.Bounds()
for _, s := range ss {
if s.Y < b.Min.Y || s.Y >= b.Max.Y {
continue
}
if s.X0 < b.Min.X {
s.X0 = b.Min.X
}
if s.X1 > b.Max.X {
s.X1 = b.Max.X
}
if s.X0 >= s.X1 {
continue
}
for x := s.X0; x < s.X1; x++ {
y := s.Y - b.Min.Y
var ma uint32 = s.Alpha // 16 bit value
// Get destination pixel color in RGBA64
sr, sg, sb, sa := p.Image.At(x, y).RGBA() // 16 bit values
// Compute destination color in RGBA64
var a = (m - (da * ma / m))
rr := uint16((dr*ma + sr*a) / m)
gg := uint16((dg*ma + sg*a) / m)
bb := uint16((db*ma + sb*a) / m)
aa := uint16((da*ma + sa*a) / m)
// Use image model to convert
p.Image.Set(x, y, color.RGBA64{rr, gg, bb, aa})
}
}
} | go | func (p *ImagePainter) Paint(ss []raster.Span, done bool) {
// Convert color to RGBA
dr, dg, db, da := p.c.RGBA() // 16 bit values
// Alpha mask
const m = 1<<16 - 1
// Draw spans
b := p.Image.Bounds()
for _, s := range ss {
if s.Y < b.Min.Y || s.Y >= b.Max.Y {
continue
}
if s.X0 < b.Min.X {
s.X0 = b.Min.X
}
if s.X1 > b.Max.X {
s.X1 = b.Max.X
}
if s.X0 >= s.X1 {
continue
}
for x := s.X0; x < s.X1; x++ {
y := s.Y - b.Min.Y
var ma uint32 = s.Alpha // 16 bit value
// Get destination pixel color in RGBA64
sr, sg, sb, sa := p.Image.At(x, y).RGBA() // 16 bit values
// Compute destination color in RGBA64
var a = (m - (da * ma / m))
rr := uint16((dr*ma + sr*a) / m)
gg := uint16((dg*ma + sg*a) / m)
bb := uint16((db*ma + sb*a) / m)
aa := uint16((da*ma + sa*a) / m)
// Use image model to convert
p.Image.Set(x, y, color.RGBA64{rr, gg, bb, aa})
}
}
} | [
"func",
"(",
"p",
"*",
"ImagePainter",
")",
"Paint",
"(",
"ss",
"[",
"]",
"raster",
".",
"Span",
",",
"done",
"bool",
")",
"{",
"// Convert color to RGBA",
"dr",
",",
"dg",
",",
"db",
",",
"da",
":=",
"p",
".",
"c",
".",
"RGBA",
"(",
")",
"// 16 ... | // Paint a batch of Spans using the current ImagePainter image and color.
// Image's Color model will be used to convert the color. | [
"Paint",
"a",
"batch",
"of",
"Spans",
"using",
"the",
"current",
"ImagePainter",
"image",
"and",
"color",
".",
"Image",
"s",
"Color",
"model",
"will",
"be",
"used",
"to",
"convert",
"the",
"color",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/raster/painter.go#L23-L58 | train |
veandco/go-sdl2 | mix/sdl_mixer.go | LoadMUSTypeRW | func LoadMUSTypeRW(src *sdl.RWops, type_ MusicType, freesrc int) (mus *Music, err error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_type := (C.Mix_MusicType)(type_)
_freesrc := (C.int)(freesrc)
mus = (*Music)(unsafe.Pointer(C.Mix_LoadMUSType_RW(_src, _type,
_freesrc)))
if mus == nil {
err = sdl.GetError()
}
return
} | go | func LoadMUSTypeRW(src *sdl.RWops, type_ MusicType, freesrc int) (mus *Music, err error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_type := (C.Mix_MusicType)(type_)
_freesrc := (C.int)(freesrc)
mus = (*Music)(unsafe.Pointer(C.Mix_LoadMUSType_RW(_src, _type,
_freesrc)))
if mus == nil {
err = sdl.GetError()
}
return
} | [
"func",
"LoadMUSTypeRW",
"(",
"src",
"*",
"sdl",
".",
"RWops",
",",
"type_",
"MusicType",
",",
"freesrc",
"int",
")",
"(",
"mus",
"*",
"Music",
",",
"err",
"error",
")",
"{",
"_src",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
... | // LoadMUSTypeRW loads a music file from an sdl.RWop object assuming a specific format. | [
"LoadMUSTypeRW",
"loads",
"a",
"music",
"file",
"from",
"an",
"sdl",
".",
"RWop",
"object",
"assuming",
"a",
"specific",
"format",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/sdl_mixer.go#L209-L219 | train |
veandco/go-sdl2 | mix/sdl_mixer.go | LengthInMs | func (chunk *Chunk) LengthInMs() int {
_chunk := (*C.Mix_Chunk)(unsafe.Pointer(chunk))
return int(C.getChunkTimeMilliseconds(_chunk))
} | go | func (chunk *Chunk) LengthInMs() int {
_chunk := (*C.Mix_Chunk)(unsafe.Pointer(chunk))
return int(C.getChunkTimeMilliseconds(_chunk))
} | [
"func",
"(",
"chunk",
"*",
"Chunk",
")",
"LengthInMs",
"(",
")",
"int",
"{",
"_chunk",
":=",
"(",
"*",
"C",
".",
"Mix_Chunk",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"chunk",
")",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"getChunkTimeMilliseconds"... | // LengthInMs returns the playing time of the chunk in milliseconds. | [
"LengthInMs",
"returns",
"the",
"playing",
"time",
"of",
"the",
"chunk",
"in",
"milliseconds",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/sdl_mixer.go#L378-L381 | train |
veandco/go-sdl2 | mix/sdl_mixer.go | SetSynchroValue | func SetSynchroValue(value int) bool {
_value := (C.int)(value)
return int(C.Mix_SetSynchroValue(_value)) == 0
} | go | func SetSynchroValue(value int) bool {
_value := (C.int)(value)
return int(C.Mix_SetSynchroValue(_value)) == 0
} | [
"func",
"SetSynchroValue",
"(",
"value",
"int",
")",
"bool",
"{",
"_value",
":=",
"(",
"C",
".",
"int",
")",
"(",
"value",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"Mix_SetSynchroValue",
"(",
"_value",
")",
")",
"==",
"0",
"\n",
"}"
] | // SetSynchroValue sets the synchro value. | [
"SetSynchroValue",
"sets",
"the",
"synchro",
"value",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/sdl_mixer.go#L620-L623 | train |
veandco/go-sdl2 | sdl/audio.go | AllocBuf | func (cvt *AudioCVT) AllocBuf(size uintptr) {
cvt.Buf = C.malloc(C.size_t(size))
} | go | func (cvt *AudioCVT) AllocBuf(size uintptr) {
cvt.Buf = C.malloc(C.size_t(size))
} | [
"func",
"(",
"cvt",
"*",
"AudioCVT",
")",
"AllocBuf",
"(",
"size",
"uintptr",
")",
"{",
"cvt",
".",
"Buf",
"=",
"C",
".",
"malloc",
"(",
"C",
".",
"size_t",
"(",
"size",
")",
")",
"\n",
"}"
] | // AllocBuf allocates the requested memory for AudioCVT buffer. | [
"AllocBuf",
"allocates",
"the",
"requested",
"memory",
"for",
"AudioCVT",
"buffer",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/audio.go#L295-L297 | train |
veandco/go-sdl2 | sdl/render.go | SetDrawColorArray | func (renderer *Renderer) SetDrawColorArray(bs ...uint8) error {
_bs := []C.Uint8{0, 0, 0, 255}
for i := 0; i < len(_bs) && i < len(bs); i++ {
_bs[i] = C.Uint8(bs[i])
}
return errorFromInt(int(
C.SDL_SetRenderDrawColor(
renderer.cptr(),
_bs[0],
_bs[1],
_bs[2],
_bs[3])))
} | go | func (renderer *Renderer) SetDrawColorArray(bs ...uint8) error {
_bs := []C.Uint8{0, 0, 0, 255}
for i := 0; i < len(_bs) && i < len(bs); i++ {
_bs[i] = C.Uint8(bs[i])
}
return errorFromInt(int(
C.SDL_SetRenderDrawColor(
renderer.cptr(),
_bs[0],
_bs[1],
_bs[2],
_bs[3])))
} | [
"func",
"(",
"renderer",
"*",
"Renderer",
")",
"SetDrawColorArray",
"(",
"bs",
"...",
"uint8",
")",
"error",
"{",
"_bs",
":=",
"[",
"]",
"C",
".",
"Uint8",
"{",
"0",
",",
"0",
",",
"0",
",",
"255",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
... | // SetDrawColorArray is a custom variant of SetDrawColor. | [
"SetDrawColorArray",
"is",
"a",
"custom",
"variant",
"of",
"SetDrawColor",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/render.go#L539-L551 | train |
veandco/go-sdl2 | sdl/gamecontroller.go | GameControllerMappingForIndex | func GameControllerMappingForIndex(index int) string {
mappingString := C.SDL_GameControllerMappingForIndex(C.int(index))
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
} | go | func GameControllerMappingForIndex(index int) string {
mappingString := C.SDL_GameControllerMappingForIndex(C.int(index))
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
} | [
"func",
"GameControllerMappingForIndex",
"(",
"index",
"int",
")",
"string",
"{",
"mappingString",
":=",
"C",
".",
"SDL_GameControllerMappingForIndex",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointe... | // GameControllerMappingForIndex returns the game controller mapping string at a particular index. | [
"GameControllerMappingForIndex",
"returns",
"the",
"game",
"controller",
"mapping",
"string",
"at",
"a",
"particular",
"index",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/gamecontroller.go#L160-L164 | train |
veandco/go-sdl2 | sdl/gamecontroller.go | Axis | func (bind *GameControllerButtonBind) Axis() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
} | go | func (bind *GameControllerButtonBind) Axis() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
} | [
"func",
"(",
"bind",
"*",
"GameControllerButtonBind",
")",
"Axis",
"(",
")",
"int",
"{",
"val",
",",
"_",
":=",
"binary",
".",
"Varint",
"(",
"bind",
".",
"value",
"[",
":",
"4",
"]",
")",
"\n",
"return",
"int",
"(",
"val",
")",
"\n",
"}"
] | // Axis returns axis mapped for this SDL joystick layer binding. | [
"Axis",
"returns",
"axis",
"mapped",
"for",
"this",
"SDL",
"joystick",
"layer",
"binding",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/gamecontroller.go#L321-L324 | train |
veandco/go-sdl2 | img/sdl_image.go | LoadTexture | func LoadTexture(renderer *sdl.Renderer, file string) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_surface := C.IMG_LoadTexture(_renderer, _file)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | go | func LoadTexture(renderer *sdl.Renderer, file string) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_surface := C.IMG_LoadTexture(_renderer, _file)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | [
"func",
"LoadTexture",
"(",
"renderer",
"*",
"sdl",
".",
"Renderer",
",",
"file",
"string",
")",
"(",
"*",
"sdl",
".",
"Texture",
",",
"error",
")",
"{",
"_renderer",
":=",
"(",
"*",
"C",
".",
"SDL_Renderer",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
... | // LoadTexture loads an image directly into a render texture. | [
"LoadTexture",
"loads",
"an",
"image",
"directly",
"into",
"a",
"render",
"texture",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L87-L96 | train |
veandco/go-sdl2 | img/sdl_image.go | LoadTextureRW | func LoadTextureRW(renderer *sdl.Renderer, src *sdl.RWops, freesrc bool) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_freesrc := (C.int)(sdl.Btoi(freesrc))
_surface := C.IMG_LoadTexture_RW(_renderer, _src, _freesrc)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | go | func LoadTextureRW(renderer *sdl.Renderer, src *sdl.RWops, freesrc bool) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_freesrc := (C.int)(sdl.Btoi(freesrc))
_surface := C.IMG_LoadTexture_RW(_renderer, _src, _freesrc)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | [
"func",
"LoadTextureRW",
"(",
"renderer",
"*",
"sdl",
".",
"Renderer",
",",
"src",
"*",
"sdl",
".",
"RWops",
",",
"freesrc",
"bool",
")",
"(",
"*",
"sdl",
".",
"Texture",
",",
"error",
")",
"{",
"_renderer",
":=",
"(",
"*",
"C",
".",
"SDL_Renderer",
... | // LoadTextureRW loads an image from an SDL data source directly into a render texture. | [
"LoadTextureRW",
"loads",
"an",
"image",
"from",
"an",
"SDL",
"data",
"source",
"directly",
"into",
"a",
"render",
"texture",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L99-L108 | train |
veandco/go-sdl2 | img/sdl_image.go | IsWEBP | func IsWEBP(src *sdl.RWops) bool {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
return int(C.IMG_isWEBP(_src)) > 0
} | go | func IsWEBP(src *sdl.RWops) bool {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
return int(C.IMG_isWEBP(_src)) > 0
} | [
"func",
"IsWEBP",
"(",
"src",
"*",
"sdl",
".",
"RWops",
")",
"bool",
"{",
"_src",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"src",
")",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"IMG_isWEBP",
"(",
"_src",
... | // IsWEBP reports whether WEBP format is supported and image data is readable as a WEBP. | [
"IsWEBP",
"reports",
"whether",
"WEBP",
"format",
"is",
"supported",
"and",
"image",
"data",
"is",
"readable",
"as",
"a",
"WEBP",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L202-L205 | train |
veandco/go-sdl2 | img/sdl_image.go | LoadWEBPRW | func LoadWEBPRW(src *sdl.RWops) (*sdl.Surface, error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_surface := C.IMG_LoadWEBP_RW(_src)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
} | go | func LoadWEBPRW(src *sdl.RWops) (*sdl.Surface, error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_surface := C.IMG_LoadWEBP_RW(_src)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
} | [
"func",
"LoadWEBPRW",
"(",
"src",
"*",
"sdl",
".",
"RWops",
")",
"(",
"*",
"sdl",
".",
"Surface",
",",
"error",
")",
"{",
"_src",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"src",
")",
")",
"\n",
"_surface",
... | // LoadWEBPRW loads a WEBP image from an SDL data source for use as a surface. | [
"LoadWEBPRW",
"loads",
"a",
"WEBP",
"image",
"from",
"an",
"SDL",
"data",
"source",
"for",
"use",
"as",
"a",
"surface",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L362-L369 | train |
veandco/go-sdl2 | img/sdl_image.go | SavePNG | func SavePNG(surface *sdl.Surface, file string) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_ret := C.IMG_SavePNG(_surface, _file)
if _ret < 0 {
return GetError()
}
return nil
} | go | func SavePNG(surface *sdl.Surface, file string) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_ret := C.IMG_SavePNG(_surface, _file)
if _ret < 0 {
return GetError()
}
return nil
} | [
"func",
"SavePNG",
"(",
"surface",
"*",
"sdl",
".",
"Surface",
",",
"file",
"string",
")",
"error",
"{",
"_surface",
":=",
"(",
"*",
"C",
".",
"SDL_Surface",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"surface",
")",
")",
"\n",
"_file",
":=",
"C",
".... | // SavePNG saves a surface as PNG file. | [
"SavePNG",
"saves",
"a",
"surface",
"as",
"PNG",
"file",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L384-L393 | train |
veandco/go-sdl2 | img/sdl_image.go | SavePNGRW | func SavePNGRW(surface *sdl.Surface, dst *sdl.RWops, freedst int) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_dst := (*C.SDL_RWops)(unsafe.Pointer(dst))
_freedst := (C.int)(freedst)
_ret := C.IMG_SavePNG_RW(_surface, _dst, _freedst)
if _ret < 0 {
return GetError()
}
return nil
} | go | func SavePNGRW(surface *sdl.Surface, dst *sdl.RWops, freedst int) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_dst := (*C.SDL_RWops)(unsafe.Pointer(dst))
_freedst := (C.int)(freedst)
_ret := C.IMG_SavePNG_RW(_surface, _dst, _freedst)
if _ret < 0 {
return GetError()
}
return nil
} | [
"func",
"SavePNGRW",
"(",
"surface",
"*",
"sdl",
".",
"Surface",
",",
"dst",
"*",
"sdl",
".",
"RWops",
",",
"freedst",
"int",
")",
"error",
"{",
"_surface",
":=",
"(",
"*",
"C",
".",
"SDL_Surface",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"surface",
... | // SavePNGRW saves a surface to an SDL data source. | [
"SavePNGRW",
"saves",
"a",
"surface",
"to",
"an",
"SDL",
"data",
"source",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L396-L405 | train |
veandco/go-sdl2 | sdl/events.go | GetText | func (e *TextEditingEvent) GetText() string {
length := func(buf []byte) int {
for i := range buf {
if buf[i] == 0 {
return i
}
}
return 0
}(e.Text[:])
text := e.Text[:length]
return string(text)
} | go | func (e *TextEditingEvent) GetText() string {
length := func(buf []byte) int {
for i := range buf {
if buf[i] == 0 {
return i
}
}
return 0
}(e.Text[:])
text := e.Text[:length]
return string(text)
} | [
"func",
"(",
"e",
"*",
"TextEditingEvent",
")",
"GetText",
"(",
")",
"string",
"{",
"length",
":=",
"func",
"(",
"buf",
"[",
"]",
"byte",
")",
"int",
"{",
"for",
"i",
":=",
"range",
"buf",
"{",
"if",
"buf",
"[",
"i",
"]",
"==",
"0",
"{",
"retur... | // GetText returns the text as string | [
"GetText",
"returns",
"the",
"text",
"as",
"string"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/events.go#L303-L316 | train |
veandco/go-sdl2 | sdl/surface.go | Pixels | func (surface *Surface) Pixels() []byte {
var b []byte
length := int(surface.W*surface.H) * int(surface.Format.BytesPerPixel)
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sliceHeader.Cap = int(length)
sliceHeader.Len = int(length)
sliceHeader.Data = uintptr(surface.pixels)
return b
} | go | func (surface *Surface) Pixels() []byte {
var b []byte
length := int(surface.W*surface.H) * int(surface.Format.BytesPerPixel)
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sliceHeader.Cap = int(length)
sliceHeader.Len = int(length)
sliceHeader.Data = uintptr(surface.pixels)
return b
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"Pixels",
"(",
")",
"[",
"]",
"byte",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"length",
":=",
"int",
"(",
"surface",
".",
"W",
"*",
"surface",
".",
"H",
")",
"*",
"int",
"(",
"surface",
".",
"Format... | // Pixels returns the actual pixel data of the surface. | [
"Pixels",
"returns",
"the",
"actual",
"pixel",
"data",
"of",
"the",
"surface",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/surface.go#L500-L508 | train |
veandco/go-sdl2 | sdl/surface.go | Duplicate | func (surface *Surface) Duplicate() (newSurface *Surface, err error) {
_newSurface := C.SDL_DuplicateSurface(surface.cptr())
if _newSurface == nil {
err = GetError()
return
}
newSurface = (*Surface)(unsafe.Pointer(_newSurface))
return
} | go | func (surface *Surface) Duplicate() (newSurface *Surface, err error) {
_newSurface := C.SDL_DuplicateSurface(surface.cptr())
if _newSurface == nil {
err = GetError()
return
}
newSurface = (*Surface)(unsafe.Pointer(_newSurface))
return
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"Duplicate",
"(",
")",
"(",
"newSurface",
"*",
"Surface",
",",
"err",
"error",
")",
"{",
"_newSurface",
":=",
"C",
".",
"SDL_DuplicateSurface",
"(",
"surface",
".",
"cptr",
"(",
")",
")",
"\n",
"if",
"_newSu... | // Duplicate creates a new surface identical to the existing surface | [
"Duplicate",
"creates",
"a",
"new",
"surface",
"identical",
"to",
"the",
"existing",
"surface"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/surface.go#L516-L525 | train |
veandco/go-sdl2 | sdl/surface.go | ColorModel | func (surface *Surface) ColorModel() color.Model {
switch surface.Format.Format {
case PIXELFORMAT_ARGB8888, PIXELFORMAT_ABGR8888:
return color.RGBAModel
case PIXELFORMAT_RGB888:
return color.RGBAModel
default:
panic("Not implemented yet")
}
} | go | func (surface *Surface) ColorModel() color.Model {
switch surface.Format.Format {
case PIXELFORMAT_ARGB8888, PIXELFORMAT_ABGR8888:
return color.RGBAModel
case PIXELFORMAT_RGB888:
return color.RGBAModel
default:
panic("Not implemented yet")
}
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"ColorModel",
"(",
")",
"color",
".",
"Model",
"{",
"switch",
"surface",
".",
"Format",
".",
"Format",
"{",
"case",
"PIXELFORMAT_ARGB8888",
",",
"PIXELFORMAT_ABGR8888",
":",
"return",
"color",
".",
"RGBAModel",
"\... | // ColorModel returns the color model used by this Surface. | [
"ColorModel",
"returns",
"the",
"color",
"model",
"used",
"by",
"this",
"Surface",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/surface.go#L528-L537 | train |
veandco/go-sdl2 | sdl/pixels.go | Uint32 | func (c Color) Uint32() uint32 {
var v uint32
v |= uint32(c.R) << 24
v |= uint32(c.G) << 16
v |= uint32(c.B) << 8
v |= uint32(c.A)
return v
} | go | func (c Color) Uint32() uint32 {
var v uint32
v |= uint32(c.R) << 24
v |= uint32(c.G) << 16
v |= uint32(c.B) << 8
v |= uint32(c.A)
return v
} | [
"func",
"(",
"c",
"Color",
")",
"Uint32",
"(",
")",
"uint32",
"{",
"var",
"v",
"uint32",
"\n",
"v",
"|=",
"uint32",
"(",
"c",
".",
"R",
")",
"<<",
"24",
"\n",
"v",
"|=",
"uint32",
"(",
"c",
".",
"G",
")",
"<<",
"16",
"\n",
"v",
"|=",
"uint3... | // Uint32 return uint32 representation of RGBA color. | [
"Uint32",
"return",
"uint32",
"representation",
"of",
"RGBA",
"color",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/pixels.go#L75-L82 | train |
veandco/go-sdl2 | sdl/pixels.go | BytesPerPixel | func BytesPerPixel(format uint32) int {
return int(C.bytesPerPixel(C.Uint32(format)))
} | go | func BytesPerPixel(format uint32) int {
return int(C.bytesPerPixel(C.Uint32(format)))
} | [
"func",
"BytesPerPixel",
"(",
"format",
"uint32",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"bytesPerPixel",
"(",
"C",
".",
"Uint32",
"(",
"format",
")",
")",
")",
"\n",
"}"
] | // BytesPerPixel returns the number of bytes per pixel for the given format | [
"BytesPerPixel",
"returns",
"the",
"number",
"of",
"bytes",
"per",
"pixel",
"for",
"the",
"given",
"format"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/pixels.go#L334-L336 | train |
veandco/go-sdl2 | sdl/pixels.go | BitsPerPixel | func BitsPerPixel(format uint32) int {
return int(C.bitsPerPixel(C.Uint32(format)))
} | go | func BitsPerPixel(format uint32) int {
return int(C.bitsPerPixel(C.Uint32(format)))
} | [
"func",
"BitsPerPixel",
"(",
"format",
"uint32",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"bitsPerPixel",
"(",
"C",
".",
"Uint32",
"(",
"format",
")",
")",
")",
"\n",
"}"
] | // BitsPerPixel returns the number of bits per pixel for the given format | [
"BitsPerPixel",
"returns",
"the",
"number",
"of",
"bits",
"per",
"pixel",
"for",
"the",
"given",
"format"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/pixels.go#L339-L341 | train |
veandco/go-sdl2 | mix/midi.go | EachSoundFont | func EachSoundFont(function func(string) int) int {
eachSoundFontFunc = function
return int(C.Mix_EachSoundFont((*[0]byte)(C.callEachSoundFont), nil))
} | go | func EachSoundFont(function func(string) int) int {
eachSoundFontFunc = function
return int(C.Mix_EachSoundFont((*[0]byte)(C.callEachSoundFont), nil))
} | [
"func",
"EachSoundFont",
"(",
"function",
"func",
"(",
"string",
")",
"int",
")",
"int",
"{",
"eachSoundFontFunc",
"=",
"function",
"\n",
"return",
"int",
"(",
"C",
".",
"Mix_EachSoundFont",
"(",
"(",
"*",
"[",
"0",
"]",
"byte",
")",
"(",
"C",
".",
"... | // EachSoundFont iterates over SoundFonts paths to use by supported MIDI backends. | [
"EachSoundFont",
"iterates",
"over",
"SoundFonts",
"paths",
"to",
"use",
"by",
"supported",
"MIDI",
"backends",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/midi.go#L19-L22 | train |
veandco/go-sdl2 | mix/midi.go | SetSoundFonts | func SetSoundFonts(paths string) bool {
_paths := C.CString(paths)
defer C.free(unsafe.Pointer(_paths))
return int(C.Mix_SetSoundFonts(_paths)) == 0
} | go | func SetSoundFonts(paths string) bool {
_paths := C.CString(paths)
defer C.free(unsafe.Pointer(_paths))
return int(C.Mix_SetSoundFonts(_paths)) == 0
} | [
"func",
"SetSoundFonts",
"(",
"paths",
"string",
")",
"bool",
"{",
"_paths",
":=",
"C",
".",
"CString",
"(",
"paths",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"_paths",
")",
")",
"\n",
"return",
"int",
"(",
"C",
"."... | // SetSoundFonts sets SoundFonts paths to use by supported MIDI backends. | [
"SetSoundFonts",
"sets",
"SoundFonts",
"paths",
"to",
"use",
"by",
"supported",
"MIDI",
"backends",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/midi.go#L25-L29 | train |
veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceVendor | func JoystickGetDeviceVendor(index int) int {
return int(C.SDL_JoystickGetDeviceVendor(C.int(index)))
} | go | func JoystickGetDeviceVendor(index int) int {
return int(C.SDL_JoystickGetDeviceVendor(C.int(index)))
} | [
"func",
"JoystickGetDeviceVendor",
"(",
"index",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"SDL_JoystickGetDeviceVendor",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceVendor returns the USB vendor ID of a joystick, if available, 0 otherwise. | [
"JoystickGetDeviceVendor",
"returns",
"the",
"USB",
"vendor",
"ID",
"of",
"a",
"joystick",
"if",
"available",
"0",
"otherwise",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L276-L278 | train |
veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceProduct | func JoystickGetDeviceProduct(index int) int {
return int(C.SDL_JoystickGetDeviceProduct(C.int(index)))
} | go | func JoystickGetDeviceProduct(index int) int {
return int(C.SDL_JoystickGetDeviceProduct(C.int(index)))
} | [
"func",
"JoystickGetDeviceProduct",
"(",
"index",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"SDL_JoystickGetDeviceProduct",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceProduct returns the USB product ID of a joystick, if available, 0 otherwise. | [
"JoystickGetDeviceProduct",
"returns",
"the",
"USB",
"product",
"ID",
"of",
"a",
"joystick",
"if",
"available",
"0",
"otherwise",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L281-L283 | train |
veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceProductVersion | func JoystickGetDeviceProductVersion(index int) int {
return int(C.SDL_JoystickGetDeviceProductVersion(C.int(index)))
} | go | func JoystickGetDeviceProductVersion(index int) int {
return int(C.SDL_JoystickGetDeviceProductVersion(C.int(index)))
} | [
"func",
"JoystickGetDeviceProductVersion",
"(",
"index",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"SDL_JoystickGetDeviceProductVersion",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceProductVersion returns the product version of a joystick, if available, 0 otherwise. | [
"JoystickGetDeviceProductVersion",
"returns",
"the",
"product",
"version",
"of",
"a",
"joystick",
"if",
"available",
"0",
"otherwise",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L286-L288 | train |
veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceType | func JoystickGetDeviceType(index int) JoystickType {
return JoystickType(C.SDL_JoystickGetDeviceType(C.int(index)))
} | go | func JoystickGetDeviceType(index int) JoystickType {
return JoystickType(C.SDL_JoystickGetDeviceType(C.int(index)))
} | [
"func",
"JoystickGetDeviceType",
"(",
"index",
"int",
")",
"JoystickType",
"{",
"return",
"JoystickType",
"(",
"C",
".",
"SDL_JoystickGetDeviceType",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceType returns the type of a joystick. | [
"JoystickGetDeviceType",
"returns",
"the",
"type",
"of",
"a",
"joystick",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L291-L293 | train |
veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceInstanceID | func JoystickGetDeviceInstanceID(index int) JoystickID {
return JoystickID(C.SDL_JoystickGetDeviceInstanceID(C.int(index)))
} | go | func JoystickGetDeviceInstanceID(index int) JoystickID {
return JoystickID(C.SDL_JoystickGetDeviceInstanceID(C.int(index)))
} | [
"func",
"JoystickGetDeviceInstanceID",
"(",
"index",
"int",
")",
"JoystickID",
"{",
"return",
"JoystickID",
"(",
"C",
".",
"SDL_JoystickGetDeviceInstanceID",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceInstanceID returns the instance ID of a joystick. | [
"JoystickGetDeviceInstanceID",
"returns",
"the",
"instance",
"ID",
"of",
"a",
"joystick",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L296-L298 | train |
veandco/go-sdl2 | sdl/joystick.go | AxisInitialState | func (joy *Joystick) AxisInitialState(axis int) (state int16, ok bool) {
ok = C.SDL_JoystickGetAxisInitialState(joy.cptr(), C.int(axis), (*C.Sint16)(&state)) == C.SDL_TRUE
return
} | go | func (joy *Joystick) AxisInitialState(axis int) (state int16, ok bool) {
ok = C.SDL_JoystickGetAxisInitialState(joy.cptr(), C.int(axis), (*C.Sint16)(&state)) == C.SDL_TRUE
return
} | [
"func",
"(",
"joy",
"*",
"Joystick",
")",
"AxisInitialState",
"(",
"axis",
"int",
")",
"(",
"state",
"int16",
",",
"ok",
"bool",
")",
"{",
"ok",
"=",
"C",
".",
"SDL_JoystickGetAxisInitialState",
"(",
"joy",
".",
"cptr",
"(",
")",
",",
"C",
".",
"int"... | // AxisInitialState returns the initial state of an axis control on a joystick, ok is true if this axis has any initial value. | [
"AxisInitialState",
"returns",
"the",
"initial",
"state",
"of",
"an",
"axis",
"control",
"on",
"a",
"joystick",
"ok",
"is",
"true",
"if",
"this",
"axis",
"has",
"any",
"initial",
"value",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L429-L432 | train |
oxequa/realize | realize/settings.go | Set | func (l *Legacy) Set(status bool, interval int) {
l.Force = true
l.Interval = time.Duration(interval) * time.Second
} | go | func (l *Legacy) Set(status bool, interval int) {
l.Force = true
l.Interval = time.Duration(interval) * time.Second
} | [
"func",
"(",
"l",
"*",
"Legacy",
")",
"Set",
"(",
"status",
"bool",
",",
"interval",
"int",
")",
"{",
"l",
".",
"Force",
"=",
"true",
"\n",
"l",
".",
"Interval",
"=",
"time",
".",
"Duration",
"(",
"interval",
")",
"*",
"time",
".",
"Second",
"\n"... | // Set legacy watcher with an interval | [
"Set",
"legacy",
"watcher",
"with",
"an",
"interval"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L65-L68 | train |
oxequa/realize | realize/settings.go | Remove | func (s *Settings) Remove(d string) error {
_, err := os.Stat(d)
if !os.IsNotExist(err) {
return os.RemoveAll(d)
}
return err
} | go | func (s *Settings) Remove(d string) error {
_, err := os.Stat(d)
if !os.IsNotExist(err) {
return os.RemoveAll(d)
}
return err
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Remove",
"(",
"d",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"d",
")",
"\n",
"if",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"os",
".",
"RemoveAll",
... | // Remove realize folder | [
"Remove",
"realize",
"folder"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L71-L77 | train |
oxequa/realize | realize/settings.go | Read | func (s *Settings) Read(out interface{}) error {
// backward compatibility
if _, err := os.Stat(RFile); err != nil {
return err
}
content, err := s.Stream(RFile)
if err == nil {
err = yaml.Unmarshal(content, out)
return err
}
return err
} | go | func (s *Settings) Read(out interface{}) error {
// backward compatibility
if _, err := os.Stat(RFile); err != nil {
return err
}
content, err := s.Stream(RFile)
if err == nil {
err = yaml.Unmarshal(content, out)
return err
}
return err
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Read",
"(",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"// backward compatibility",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"RFile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n... | // Read config file | [
"Read",
"config",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L80-L91 | train |
oxequa/realize | realize/settings.go | Write | func (s *Settings) Write(out interface{}) error {
y, err := yaml.Marshal(out)
if err != nil {
return err
}
s.Fatal(ioutil.WriteFile(RFile, y, Permission))
return nil
} | go | func (s *Settings) Write(out interface{}) error {
y, err := yaml.Marshal(out)
if err != nil {
return err
}
s.Fatal(ioutil.WriteFile(RFile, y, Permission))
return nil
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Write",
"(",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"y",
",",
"err",
":=",
"yaml",
".",
"Marshal",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
... | // Write config file | [
"Write",
"config",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L94-L101 | train |
oxequa/realize | realize/settings.go | Stream | func (s Settings) Stream(file string) ([]byte, error) {
_, err := os.Stat(file)
if err != nil {
return nil, err
}
content, err := ioutil.ReadFile(file)
s.Fatal(err)
return content, err
} | go | func (s Settings) Stream(file string) ([]byte, error) {
_, err := os.Stat(file)
if err != nil {
return nil, err
}
content, err := ioutil.ReadFile(file)
s.Fatal(err)
return content, err
} | [
"func",
"(",
"s",
"Settings",
")",
"Stream",
"(",
"file",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"er... | // Stream return a byte stream of a given file | [
"Stream",
"return",
"a",
"byte",
"stream",
"of",
"a",
"given",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L104-L112 | train |
oxequa/realize | realize/settings.go | Fatal | func (s Settings) Fatal(err error, msg ...interface{}) {
if err != nil {
if len(msg) > 0 {
log.Fatalln(Red.Regular(msg...), err.Error())
} else {
log.Fatalln(err.Error())
}
}
} | go | func (s Settings) Fatal(err error, msg ...interface{}) {
if err != nil {
if len(msg) > 0 {
log.Fatalln(Red.Regular(msg...), err.Error())
} else {
log.Fatalln(err.Error())
}
}
} | [
"func",
"(",
"s",
"Settings",
")",
"Fatal",
"(",
"err",
"error",
",",
"msg",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"msg",
")",
">",
"0",
"{",
"log",
".",
"Fatalln",
"(",
"Red",
".",
"Regular",
... | // Fatal prints a fatal error with its additional messages | [
"Fatal",
"prints",
"a",
"fatal",
"error",
"with",
"its",
"additional",
"messages"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L115-L123 | train |
oxequa/realize | realize/settings.go | Create | func (s Settings) Create(path string, name string) *os.File {
file := filepath.Join(path, name)
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, Permission)
s.Fatal(err)
return out
} | go | func (s Settings) Create(path string, name string) *os.File {
file := filepath.Join(path, name)
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, Permission)
s.Fatal(err)
return out
} | [
"func",
"(",
"s",
"Settings",
")",
"Create",
"(",
"path",
"string",
",",
"name",
"string",
")",
"*",
"os",
".",
"File",
"{",
"file",
":=",
"filepath",
".",
"Join",
"(",
"path",
",",
"name",
")",
"\n",
"out",
",",
"err",
":=",
"os",
".",
"OpenFile... | // Create a new file and return its pointer | [
"Create",
"a",
"new",
"file",
"and",
"return",
"its",
"pointer"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L126-L131 | train |
oxequa/realize | realize/server.go | render | func (s *Server) render(c echo.Context, path string, mime int) error {
data, err := Asset(path)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound)
}
rs := c.Response()
// check content type by extensions
switch mime {
case 1:
rs.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
break
case 2:
rs.Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScriptCharsetUTF8)
break
case 3:
rs.Header().Set(echo.HeaderContentType, "text/css")
break
case 4:
rs.Header().Set(echo.HeaderContentType, "image/svg+xml")
break
case 5:
rs.Header().Set(echo.HeaderContentType, "image/png")
break
}
rs.WriteHeader(http.StatusOK)
rs.Write(data)
return nil
} | go | func (s *Server) render(c echo.Context, path string, mime int) error {
data, err := Asset(path)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound)
}
rs := c.Response()
// check content type by extensions
switch mime {
case 1:
rs.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
break
case 2:
rs.Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScriptCharsetUTF8)
break
case 3:
rs.Header().Set(echo.HeaderContentType, "text/css")
break
case 4:
rs.Header().Set(echo.HeaderContentType, "image/svg+xml")
break
case 5:
rs.Header().Set(echo.HeaderContentType, "image/png")
break
}
rs.WriteHeader(http.StatusOK)
rs.Write(data)
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"render",
"(",
"c",
"echo",
".",
"Context",
",",
"path",
"string",
",",
"mime",
"int",
")",
"error",
"{",
"data",
",",
"err",
":=",
"Asset",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // Render return a web pages defined in bindata | [
"Render",
"return",
"a",
"web",
"pages",
"defined",
"in",
"bindata"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L72-L99 | train |
oxequa/realize | realize/server.go | Start | func (s *Server) Start() (err error) {
if s.Status {
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 2,
}))
e.Use(middleware.Recover())
// web panel
e.GET("/", func(c echo.Context) error {
return s.render(c, "assets/index.html", 1)
})
e.GET("/assets/js/all.min.js", func(c echo.Context) error {
return s.render(c, "assets/assets/js/all.min.js", 2)
})
e.GET("/assets/css/app.css", func(c echo.Context) error {
return s.render(c, "assets/assets/css/app.css", 3)
})
e.GET("/app/components/settings/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/settings/index.html", 1)
})
e.GET("/app/components/project/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/project/index.html", 1)
})
e.GET("/app/components/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/index.html", 1)
})
e.GET("/assets/img/logo.png", func(c echo.Context) error {
return s.render(c, "assets/assets/img/logo.png", 5)
})
e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/github-logo.svg", 4)
})
e.GET("/assets/img/svg/ic_arrow_back_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_arrow_back_black_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_clear_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_clear_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_menu_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_menu_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_settings_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_settings_black_48px.svg", 4)
})
//websocket
e.GET("/ws", s.projects)
e.HideBanner = true
e.Debug = false
go func() {
log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port)))
e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port))
}()
}
return nil
} | go | func (s *Server) Start() (err error) {
if s.Status {
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 2,
}))
e.Use(middleware.Recover())
// web panel
e.GET("/", func(c echo.Context) error {
return s.render(c, "assets/index.html", 1)
})
e.GET("/assets/js/all.min.js", func(c echo.Context) error {
return s.render(c, "assets/assets/js/all.min.js", 2)
})
e.GET("/assets/css/app.css", func(c echo.Context) error {
return s.render(c, "assets/assets/css/app.css", 3)
})
e.GET("/app/components/settings/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/settings/index.html", 1)
})
e.GET("/app/components/project/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/project/index.html", 1)
})
e.GET("/app/components/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/index.html", 1)
})
e.GET("/assets/img/logo.png", func(c echo.Context) error {
return s.render(c, "assets/assets/img/logo.png", 5)
})
e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/github-logo.svg", 4)
})
e.GET("/assets/img/svg/ic_arrow_back_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_arrow_back_black_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_clear_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_clear_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_menu_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_menu_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_settings_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_settings_black_48px.svg", 4)
})
//websocket
e.GET("/ws", s.projects)
e.HideBanner = true
e.Debug = false
go func() {
log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port)))
e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port))
}()
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
".",
"Status",
"{",
"e",
":=",
"echo",
".",
"New",
"(",
")",
"\n",
"e",
".",
"Use",
"(",
"middleware",
".",
"GzipWithConfig",
"(",
"middleware",
... | // Start the web server | [
"Start",
"the",
"web",
"server"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L109-L165 | train |
oxequa/realize | realize/server.go | OpenURL | func (s *Server) OpenURL() error {
url := "http://" + string(s.Parent.Server.Host) + ":" + strconv.Itoa(s.Parent.Server.Port)
stderr := bytes.Buffer{}
cmd := map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
}
if s.Open {
open, err := cmd[runtime.GOOS]
if !err {
return fmt.Errorf("operating system %q is not supported", runtime.GOOS)
}
cmd := exec.Command(open, url)
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return errors.New(stderr.String())
}
}
return nil
} | go | func (s *Server) OpenURL() error {
url := "http://" + string(s.Parent.Server.Host) + ":" + strconv.Itoa(s.Parent.Server.Port)
stderr := bytes.Buffer{}
cmd := map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
}
if s.Open {
open, err := cmd[runtime.GOOS]
if !err {
return fmt.Errorf("operating system %q is not supported", runtime.GOOS)
}
cmd := exec.Command(open, url)
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return errors.New(stderr.String())
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"OpenURL",
"(",
")",
"error",
"{",
"url",
":=",
"\"",
"\"",
"+",
"string",
"(",
"s",
".",
"Parent",
".",
"Server",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Parent",
... | // OpenURL in a new tab of default browser | [
"OpenURL",
"in",
"a",
"new",
"tab",
"of",
"default",
"browser"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L168-L188 | train |
oxequa/realize | realize/settings_unix.go | Flimit | func (s *Settings) Flimit() error {
var rLimit syscall.Rlimit
rLimit.Max = uint64(s.FileLimit)
rLimit.Cur = uint64(s.FileLimit)
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
} | go | func (s *Settings) Flimit() error {
var rLimit syscall.Rlimit
rLimit.Max = uint64(s.FileLimit)
rLimit.Cur = uint64(s.FileLimit)
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Flimit",
"(",
")",
"error",
"{",
"var",
"rLimit",
"syscall",
".",
"Rlimit",
"\n",
"rLimit",
".",
"Max",
"=",
"uint64",
"(",
"s",
".",
"FileLimit",
")",
"\n",
"rLimit",
".",
"Cur",
"=",
"uint64",
"(",
"s",
... | // Flimit defines the max number of watched files | [
"Flimit",
"defines",
"the",
"max",
"number",
"of",
"watched",
"files"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings_unix.go#L8-L14 | train |
oxequa/realize | realize/cli.go | Stop | func (r *Realize) Stop() error {
for k := range r.Schema.Projects {
if r.Schema.Projects[k].exit != nil {
close(r.Schema.Projects[k].exit)
}
}
return nil
} | go | func (r *Realize) Stop() error {
for k := range r.Schema.Projects {
if r.Schema.Projects[k].exit != nil {
close(r.Schema.Projects[k].exit)
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Realize",
")",
"Stop",
"(",
")",
"error",
"{",
"for",
"k",
":=",
"range",
"r",
".",
"Schema",
".",
"Projects",
"{",
"if",
"r",
".",
"Schema",
".",
"Projects",
"[",
"k",
"]",
".",
"exit",
"!=",
"nil",
"{",
"close",
"(",
... | // Stop realize workflow | [
"Stop",
"realize",
"workflow"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L76-L83 | train |
oxequa/realize | realize/cli.go | Prefix | func (r *Realize) Prefix(input string) string {
if len(input) > 0 {
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(RPrefix), Yellow.Bold("]"), " : ", input)
}
return input
} | go | func (r *Realize) Prefix(input string) string {
if len(input) > 0 {
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(RPrefix), Yellow.Bold("]"), " : ", input)
}
return input
} | [
"func",
"(",
"r",
"*",
"Realize",
")",
"Prefix",
"(",
"input",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"input",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Sprint",
"(",
"Yellow",
".",
"Bold",
"(",
"\"",
"\"",
")",
",",
"strings",
".",
"... | // Prefix a given string with tool name | [
"Prefix",
"a",
"given",
"string",
"with",
"tool",
"name"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L104-L109 | train |
oxequa/realize | realize/cli.go | Write | func (w LogWriter) Write(bytes []byte) (int, error) {
if len(bytes) > 0 {
return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes))
}
return 0, nil
} | go | func (w LogWriter) Write(bytes []byte) (int, error) {
if len(bytes) > 0 {
return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes))
}
return 0, nil
} | [
"func",
"(",
"w",
"LogWriter",
")",
"Write",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"bytes",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Fprint",
"(",
"Output",
",",
"Yellow",
".",
"Regular",
"... | // Rewrite the layout of the log timestamp | [
"Rewrite",
"the",
"layout",
"of",
"the",
"log",
"timestamp"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L112-L117 | train |
oxequa/realize | realize/projects.go | After | func (p *Project) After() {
if p.parent.After != nil {
p.parent.After(Context{Project: p})
return
}
p.cmd(nil, "after", true)
} | go | func (p *Project) After() {
if p.parent.After != nil {
p.parent.After(Context{Project: p})
return
}
p.cmd(nil, "after", true)
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"After",
"(",
")",
"{",
"if",
"p",
".",
"parent",
".",
"After",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"After",
"(",
"Context",
"{",
"Project",
":",
"p",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n",
"p... | // After stop watcher | [
"After",
"stop",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L103-L109 | train |
oxequa/realize | realize/projects.go | Before | func (p *Project) Before() {
if p.parent.Before != nil {
p.parent.Before(Context{Project: p})
return
}
if hasGoMod(Wdir()) {
p.Tools.vgo = true
}
// setup go tools
p.Tools.Setup()
// global commands before
p.cmd(p.stop, "before", true)
// indexing files and dirs
for _, dir := range p.Watcher.Paths {
base, _ := filepath.Abs(p.Path)
base = filepath.Join(base, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, p.walk); err != nil {
p.Err(err)
}
}
}
// start message
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Blue.Bold("Watching"), Magenta.Bold(p.files), "file/s", Magenta.Bold(p.folders), "folder/s")
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(p.files, 10) + " files/s " + strconv.FormatInt(p.folders, 10) + " folder/s"}
p.stamp("log", out, msg, "")
} | go | func (p *Project) Before() {
if p.parent.Before != nil {
p.parent.Before(Context{Project: p})
return
}
if hasGoMod(Wdir()) {
p.Tools.vgo = true
}
// setup go tools
p.Tools.Setup()
// global commands before
p.cmd(p.stop, "before", true)
// indexing files and dirs
for _, dir := range p.Watcher.Paths {
base, _ := filepath.Abs(p.Path)
base = filepath.Join(base, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, p.walk); err != nil {
p.Err(err)
}
}
}
// start message
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Blue.Bold("Watching"), Magenta.Bold(p.files), "file/s", Magenta.Bold(p.folders), "folder/s")
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(p.files, 10) + " files/s " + strconv.FormatInt(p.folders, 10) + " folder/s"}
p.stamp("log", out, msg, "")
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Before",
"(",
")",
"{",
"if",
"p",
".",
"parent",
".",
"Before",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Before",
"(",
"Context",
"{",
"Project",
":",
"p",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n\n",... | // Before start watcher | [
"Before",
"start",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L112-L140 | train |
oxequa/realize | realize/projects.go | Change | func (p *Project) Change(event fsnotify.Event) {
if p.parent.Change != nil {
p.parent.Change(Context{Project: p, Event: event})
return
}
// file extension
ext := ext(event.Name)
if ext == "" {
ext = "DIR"
}
// change message
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", Magenta.Bold(strings.ToUpper(ext)), "changed", Magenta.Bold(event.Name))
out = BufferOut{Time: time.Now(), Text: ext + " changed " + event.Name}
p.stamp("log", out, msg, "")
} | go | func (p *Project) Change(event fsnotify.Event) {
if p.parent.Change != nil {
p.parent.Change(Context{Project: p, Event: event})
return
}
// file extension
ext := ext(event.Name)
if ext == "" {
ext = "DIR"
}
// change message
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", Magenta.Bold(strings.ToUpper(ext)), "changed", Magenta.Bold(event.Name))
out = BufferOut{Time: time.Now(), Text: ext + " changed " + event.Name}
p.stamp("log", out, msg, "")
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Change",
"(",
"event",
"fsnotify",
".",
"Event",
")",
"{",
"if",
"p",
".",
"parent",
".",
"Change",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Change",
"(",
"Context",
"{",
"Project",
":",
"p",
",",
"Event... | // Change event message | [
"Change",
"event",
"message"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L156-L170 | train |
oxequa/realize | realize/projects.go | Watch | func (p *Project) Watch(wg *sync.WaitGroup) {
var err error
// change channel
p.stop = make(chan bool)
// init a new watcher
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
if err != nil {
log.Fatal(err)
}
defer func() {
close(p.stop)
p.watcher.Close()
}()
// before start checks
p.Before()
// start watcher
go p.Reload("", p.stop)
L:
for {
select {
case event := <-p.watcher.Events():
if p.parent.Settings.Recovery.Events {
log.Println("File:", event.Name, "LastFile:", p.last.file, "Time:", time.Now(), "LastTime:", p.last.time)
}
if time.Now().Truncate(time.Second).After(p.last.time) {
// switch event type
switch event.Op {
case fsnotify.Chmod:
case fsnotify.Remove:
p.watcher.Remove(event.Name)
if p.Validate(event.Name, false) && ext(event.Name) != "" {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload("", p.stop)
}
default:
if p.Validate(event.Name, true) {
fi, err := os.Stat(event.Name)
if err != nil {
continue
}
if fi.IsDir() {
filepath.Walk(event.Name, p.walk)
} else {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload(event.Name, p.stop)
p.last.time = time.Now().Truncate(time.Second)
p.last.file = event.Name
}
}
}
}
case err := <-p.watcher.Errors():
p.Err(err)
case <-p.exit:
p.After()
break L
}
}
wg.Done()
} | go | func (p *Project) Watch(wg *sync.WaitGroup) {
var err error
// change channel
p.stop = make(chan bool)
// init a new watcher
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
if err != nil {
log.Fatal(err)
}
defer func() {
close(p.stop)
p.watcher.Close()
}()
// before start checks
p.Before()
// start watcher
go p.Reload("", p.stop)
L:
for {
select {
case event := <-p.watcher.Events():
if p.parent.Settings.Recovery.Events {
log.Println("File:", event.Name, "LastFile:", p.last.file, "Time:", time.Now(), "LastTime:", p.last.time)
}
if time.Now().Truncate(time.Second).After(p.last.time) {
// switch event type
switch event.Op {
case fsnotify.Chmod:
case fsnotify.Remove:
p.watcher.Remove(event.Name)
if p.Validate(event.Name, false) && ext(event.Name) != "" {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload("", p.stop)
}
default:
if p.Validate(event.Name, true) {
fi, err := os.Stat(event.Name)
if err != nil {
continue
}
if fi.IsDir() {
filepath.Walk(event.Name, p.walk)
} else {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload(event.Name, p.stop)
p.last.time = time.Now().Truncate(time.Second)
p.last.file = event.Name
}
}
}
}
case err := <-p.watcher.Errors():
p.Err(err)
case <-p.exit:
p.After()
break L
}
}
wg.Done()
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Watch",
"(",
"wg",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"var",
"err",
"error",
"\n",
"// change channel",
"p",
".",
"stop",
"=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"// init a new watcher",
"p",
".",
"w... | // Watch a project | [
"Watch",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L277-L342 | train |
oxequa/realize | realize/projects.go | Validate | func (p *Project) Validate(path string, fcheck bool) bool {
if len(path) == 0 {
return false
}
// check if skip hidden
if p.Watcher.Hidden && isHidden(path) {
return false
}
// check for a valid ext or path
if e := ext(path); e != "" {
if len(p.Watcher.Exts) == 0 {
return false
}
// check ignored
for _, v := range p.Watcher.Ignore {
if v == e {
return false
}
}
// supported extensions
for index, v := range p.Watcher.Exts {
if e == v {
break
}
if index == len(p.Watcher.Exts)-1 {
return false
}
}
}
if p.shouldIgnore(path) {
return false
}
// file check
if fcheck {
fi, err := os.Stat(path)
if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0 {
return false
}
}
return true
} | go | func (p *Project) Validate(path string, fcheck bool) bool {
if len(path) == 0 {
return false
}
// check if skip hidden
if p.Watcher.Hidden && isHidden(path) {
return false
}
// check for a valid ext or path
if e := ext(path); e != "" {
if len(p.Watcher.Exts) == 0 {
return false
}
// check ignored
for _, v := range p.Watcher.Ignore {
if v == e {
return false
}
}
// supported extensions
for index, v := range p.Watcher.Exts {
if e == v {
break
}
if index == len(p.Watcher.Exts)-1 {
return false
}
}
}
if p.shouldIgnore(path) {
return false
}
// file check
if fcheck {
fi, err := os.Stat(path)
if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0 {
return false
}
}
return true
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Validate",
"(",
"path",
"string",
",",
"fcheck",
"bool",
")",
"bool",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// check if skip hidden",
"if",
"p",
".",
"Watcher"... | // Validate a file path | [
"Validate",
"a",
"file",
"path"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L345-L386 | train |
oxequa/realize | realize/projects.go | pname | func (p *Project) pname(name string, color int) string {
switch color {
case 1:
name = Yellow.Regular("[") + strings.ToUpper(name) + Yellow.Regular("]")
break
case 2:
name = Yellow.Regular("[") + Red.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 3:
name = Yellow.Regular("[") + Blue.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 4:
name = Yellow.Regular("[") + Magenta.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 5:
name = Yellow.Regular("[") + Green.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
}
return name
} | go | func (p *Project) pname(name string, color int) string {
switch color {
case 1:
name = Yellow.Regular("[") + strings.ToUpper(name) + Yellow.Regular("]")
break
case 2:
name = Yellow.Regular("[") + Red.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 3:
name = Yellow.Regular("[") + Blue.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 4:
name = Yellow.Regular("[") + Magenta.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 5:
name = Yellow.Regular("[") + Green.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
}
return name
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"pname",
"(",
"name",
"string",
",",
"color",
"int",
")",
"string",
"{",
"switch",
"color",
"{",
"case",
"1",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"strings",
".",
"ToUpper",
... | // Defines the colors scheme for the project name | [
"Defines",
"the",
"colors",
"scheme",
"for",
"the",
"project",
"name"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L389-L408 | train |
oxequa/realize | realize/projects.go | tools | func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) {
done := make(chan bool)
result := make(chan Response)
v := reflect.ValueOf(p.Tools)
go func() {
for i := 0; i < v.NumField()-1; i++ {
tool := v.Field(i).Interface().(Tool)
tool.parent = p
if tool.Status && tool.isTool {
if fi.IsDir() {
if tool.dir {
result <- tool.Exec(path, stop)
}
} else if !tool.dir {
result <- tool.Exec(path, stop)
}
}
}
close(done)
}()
for {
select {
case <-done:
return
case <-stop:
return
case r := <-result:
if r.Err != nil {
if fi.IsDir() {
path, _ = filepath.Abs(fi.Name())
}
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), Red.Regular("there are some errors in"), ":", Magenta.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: r.Name, Stream: r.Err.Error()}
p.stamp("error", buff, msg, r.Err.Error())
} else if r.Out != "" {
msg = fmt.Sprintln(p.pname(p.Name, 3), ":", Red.Bold(r.Name), Red.Regular("outputs"), ":", Blue.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "outputs", Path: path, Type: r.Name, Stream: r.Out}
p.stamp("out", buff, msg, r.Out)
}
}
}
} | go | func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) {
done := make(chan bool)
result := make(chan Response)
v := reflect.ValueOf(p.Tools)
go func() {
for i := 0; i < v.NumField()-1; i++ {
tool := v.Field(i).Interface().(Tool)
tool.parent = p
if tool.Status && tool.isTool {
if fi.IsDir() {
if tool.dir {
result <- tool.Exec(path, stop)
}
} else if !tool.dir {
result <- tool.Exec(path, stop)
}
}
}
close(done)
}()
for {
select {
case <-done:
return
case <-stop:
return
case r := <-result:
if r.Err != nil {
if fi.IsDir() {
path, _ = filepath.Abs(fi.Name())
}
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), Red.Regular("there are some errors in"), ":", Magenta.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: r.Name, Stream: r.Err.Error()}
p.stamp("error", buff, msg, r.Err.Error())
} else if r.Out != "" {
msg = fmt.Sprintln(p.pname(p.Name, 3), ":", Red.Bold(r.Name), Red.Regular("outputs"), ":", Blue.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "outputs", Path: path, Type: r.Name, Stream: r.Out}
p.stamp("out", buff, msg, r.Out)
}
}
}
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"tools",
"(",
"stop",
"<-",
"chan",
"bool",
",",
"path",
"string",
",",
"fi",
"os",
".",
"FileInfo",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"result",
":=",
"make",
"(",
"chan",
"Resp... | // Tool logs the result of a go command | [
"Tool",
"logs",
"the",
"result",
"of",
"a",
"go",
"command"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L411-L452 | train |
oxequa/realize | realize/projects.go | walk | func (p *Project) walk(path string, info os.FileInfo, err error) error {
if p.shouldIgnore(path) {
return filepath.SkipDir
}
if p.Validate(path, true) {
result := p.watcher.Walk(path, p.init)
if result != "" {
if p.parent.Settings.Recovery.Index {
log.Println("Indexing", path)
}
p.tools(p.stop, path, info)
if info.IsDir() {
// tools dir
p.folders++
} else {
// tools files
p.files++
}
}
}
return nil
} | go | func (p *Project) walk(path string, info os.FileInfo, err error) error {
if p.shouldIgnore(path) {
return filepath.SkipDir
}
if p.Validate(path, true) {
result := p.watcher.Walk(path, p.init)
if result != "" {
if p.parent.Settings.Recovery.Index {
log.Println("Indexing", path)
}
p.tools(p.stop, path, info)
if info.IsDir() {
// tools dir
p.folders++
} else {
// tools files
p.files++
}
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"walk",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"p",
".",
"shouldIgnore",
"(",
"path",
")",
"{",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}"... | // Watch the files tree of a project | [
"Watch",
"the",
"files",
"tree",
"of",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L487-L509 | train |
oxequa/realize | realize/projects.go | stamp | func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
ctime := time.Now()
content := []string{ctime.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n", stream}
switch t {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.parent.Settings.Files.Outputs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Outputs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.parent.Settings.Files.Logs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Logs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.parent.Settings.Files.Errors.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Errors.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
}
if msg != "" {
log.Print(msg)
}
if stream != "" {
fmt.Fprintln(Output, stream)
}
go func() {
p.parent.Sync <- "sync"
}()
} | go | func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
ctime := time.Now()
content := []string{ctime.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n", stream}
switch t {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.parent.Settings.Files.Outputs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Outputs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.parent.Settings.Files.Logs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Logs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.parent.Settings.Files.Errors.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Errors.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
}
if msg != "" {
log.Print(msg)
}
if stream != "" {
fmt.Fprintln(Output, stream)
}
go func() {
p.parent.Sync <- "sync"
}()
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"stamp",
"(",
"t",
"string",
",",
"o",
"BufferOut",
",",
"msg",
"string",
",",
"stream",
"string",
")",
"{",
"ctime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"content",
":=",
"[",
"]",
"string",
"{",
"ctim... | // Print on files, cli, ws | [
"Print",
"on",
"files",
"cli",
"ws"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L525-L563 | train |
oxequa/realize | realize/projects.go | print | func (r *Response) print(start time.Time, p *Project) {
if r.Err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error())
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}
p.stamp("error", out, msg, r.Out)
} else {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.stamp("log", out, msg, r.Out)
}
} | go | func (r *Response) print(start time.Time, p *Project) {
if r.Err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error())
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}
p.stamp("error", out, msg, r.Out)
} else {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.stamp("log", out, msg, r.Out)
}
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"print",
"(",
"start",
"time",
".",
"Time",
",",
"p",
"*",
"Project",
")",
"{",
"if",
"r",
".",
"Err",
"!=",
"nil",
"{",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name"... | // Print with time after | [
"Print",
"with",
"time",
"after"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L680-L690 | train |
oxequa/realize | realize/projects.go | exec | func (c *Command) exec(base string, stop <-chan bool) (response Response) {
var stdout bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ")
ex := exec.Command(args[0], args[1:]...)
ex.Dir = base
// make cmd path
if c.Path != "" {
if strings.Contains(c.Path, base) {
ex.Dir = c.Path
} else {
ex.Dir = filepath.Join(base, c.Path)
}
}
ex.Stdout = &stdout
ex.Stderr = &stderr
// Start command
ex.Start()
go func() { done <- ex.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
ex.Process.Kill()
case err := <-done:
// Command completed
response.Name = c.Cmd
response.Out = stdout.String()
if err != nil {
response.Err = errors.New(stderr.String() + stdout.String())
}
}
return
} | go | func (c *Command) exec(base string, stop <-chan bool) (response Response) {
var stdout bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ")
ex := exec.Command(args[0], args[1:]...)
ex.Dir = base
// make cmd path
if c.Path != "" {
if strings.Contains(c.Path, base) {
ex.Dir = c.Path
} else {
ex.Dir = filepath.Join(base, c.Path)
}
}
ex.Stdout = &stdout
ex.Stderr = &stderr
// Start command
ex.Start()
go func() { done <- ex.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
ex.Process.Kill()
case err := <-done:
// Command completed
response.Name = c.Cmd
response.Out = stdout.String()
if err != nil {
response.Err = errors.New(stderr.String() + stdout.String())
}
}
return
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"exec",
"(",
"base",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"var",
"stdout",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",... | // Exec an additional command from a defined path if specified | [
"Exec",
"an",
"additional",
"command",
"from",
"a",
"defined",
"path",
"if",
"specified"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L693-L727 | train |
oxequa/realize | realize.go | version | func version() {
log.Println(r.Prefix(realize.Green.Bold(realize.RVersion)))
} | go | func version() {
log.Println(r.Prefix(realize.Green.Bold(realize.RVersion)))
} | [
"func",
"version",
"(",
")",
"{",
"log",
".",
"Println",
"(",
"r",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"realize",
".",
"RVersion",
")",
")",
")",
"\n",
"}"
] | // Version print current version | [
"Version",
"print",
"current",
"version"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L107-L109 | train |
oxequa/realize | realize.go | clean | func clean() (err error) {
if err := r.Settings.Remove(realize.RFile); err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("folder successfully removed")))
return nil
} | go | func clean() (err error) {
if err := r.Settings.Remove(realize.RFile); err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("folder successfully removed")))
return nil
} | [
"func",
"clean",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"r",
".",
"Settings",
".",
"Remove",
"(",
"realize",
".",
"RFile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Println",
"(",
"r"... | // Clean remove realize file | [
"Clean",
"remove",
"realize",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L112-L118 | train |
oxequa/realize | realize.go | add | func add(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
projects := len(r.Schema.Projects)
// create and add a new project
r.Schema.Add(r.Schema.New(c))
if len(r.Schema.Projects) > projects {
// update config
err = r.Settings.Write(r)
if err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("project successfully added")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project can't be added")))
}
return nil
} | go | func add(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
projects := len(r.Schema.Projects)
// create and add a new project
r.Schema.Add(r.Schema.New(c))
if len(r.Schema.Projects) > projects {
// update config
err = r.Settings.Write(r)
if err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("project successfully added")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project can't be added")))
}
return nil
} | [
"func",
"add",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"// read a config if exist",
"err",
"=",
"r",
".",
"Settings",
".",
"Read",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"... | // Add a project to an existing config or create a new one | [
"Add",
"a",
"project",
"to",
"an",
"existing",
"config",
"or",
"create",
"a",
"new",
"one"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L121-L141 | train |
oxequa/realize | realize.go | remove | func remove(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
if c.String("name") != "" {
err := r.Schema.Remove(c.String("name"))
if err != nil {
return err
}
// update config
err = r.Settings.Write(r)
if err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("project successfully removed")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project name not found")))
}
return nil
} | go | func remove(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
if c.String("name") != "" {
err := r.Schema.Remove(c.String("name"))
if err != nil {
return err
}
// update config
err = r.Settings.Write(r)
if err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("project successfully removed")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project name not found")))
}
return nil
} | [
"func",
"remove",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"// read a config if exist",
"err",
"=",
"r",
".",
"Settings",
".",
"Read",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // Remove a project from an existing config | [
"Remove",
"a",
"project",
"from",
"an",
"existing",
"config"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L1168-L1189 | train |
oxequa/realize | realize/tools.go | Exec | func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
if t.dir {
if filepath.Ext(path) != "" {
path = filepath.Dir(path)
}
// check if there is at least one go file
matched := false
files, _ := ioutil.ReadDir(path)
for _, f := range files {
matched, _ = filepath.Match("*.go", f.Name())
if matched {
break
}
}
if !matched {
return
}
} else if !strings.HasSuffix(path, ".go") {
return
}
args := t.Args
if strings.HasSuffix(path, ".go") {
args = append(args, path)
path = filepath.Dir(path)
}
if s := ext(path); s == "" || s == "go" {
if t.parent.parent.Settings.Recovery.Tools {
log.Println("Tool:", t.name, path, args)
}
var out, stderr bytes.Buffer
done := make(chan error)
args = append(t.cmd, args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
err := cmd.Start()
if err != nil {
response.Name = t.name
response.Err = err
return
}
go func() { done <- cmd.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
response.Name = t.name
if err != nil {
response.Err = errors.New(stderr.String() + out.String() + err.Error())
} else {
if t.Output {
response.Out = out.String()
}
}
}
}
return
} | go | func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
if t.dir {
if filepath.Ext(path) != "" {
path = filepath.Dir(path)
}
// check if there is at least one go file
matched := false
files, _ := ioutil.ReadDir(path)
for _, f := range files {
matched, _ = filepath.Match("*.go", f.Name())
if matched {
break
}
}
if !matched {
return
}
} else if !strings.HasSuffix(path, ".go") {
return
}
args := t.Args
if strings.HasSuffix(path, ".go") {
args = append(args, path)
path = filepath.Dir(path)
}
if s := ext(path); s == "" || s == "go" {
if t.parent.parent.Settings.Recovery.Tools {
log.Println("Tool:", t.name, path, args)
}
var out, stderr bytes.Buffer
done := make(chan error)
args = append(t.cmd, args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
err := cmd.Start()
if err != nil {
response.Name = t.name
response.Err = err
return
}
go func() { done <- cmd.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
response.Name = t.name
if err != nil {
response.Err = errors.New(stderr.String() + out.String() + err.Error())
} else {
if t.Output {
response.Out = out.String()
}
}
}
}
return
} | [
"func",
"(",
"t",
"*",
"Tool",
")",
"Exec",
"(",
"path",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"if",
"t",
".",
"dir",
"{",
"if",
"filepath",
".",
"Ext",
"(",
"path",
")",
"!=",
"\"",
"\"",
"{",... | // Exec a go tool | [
"Exec",
"a",
"go",
"tool"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/tools.go#L105-L171 | train |
oxequa/realize | realize/tools.go | Compile | func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
var out bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
cmd.Start()
go func() { done <- cmd.Wait() }()
// Wait a result
response.Name = t.name
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
if err != nil {
response.Err = errors.New(stderr.String() + err.Error())
}
}
return
} | go | func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
var out bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
cmd.Start()
go func() { done <- cmd.Wait() }()
// Wait a result
response.Name = t.name
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
if err != nil {
response.Err = errors.New(stderr.String() + err.Error())
}
}
return
} | [
"func",
"(",
"t",
"*",
"Tool",
")",
"Compile",
"(",
"path",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"var",
"out",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",
... | // Compile is used for build and install | [
"Compile",
"is",
"used",
"for",
"build",
"and",
"install"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/tools.go#L174-L203 | train |
oxequa/realize | realize/utils.go | params | func params(params *cli.Context) []string {
argsN := params.NArg()
if argsN > 0 {
var args []string
for i := 0; i <= argsN-1; i++ {
args = append(args, params.Args().Get(i))
}
return args
}
return nil
} | go | func params(params *cli.Context) []string {
argsN := params.NArg()
if argsN > 0 {
var args []string
for i := 0; i <= argsN-1; i++ {
args = append(args, params.Args().Get(i))
}
return args
}
return nil
} | [
"func",
"params",
"(",
"params",
"*",
"cli",
".",
"Context",
")",
"[",
"]",
"string",
"{",
"argsN",
":=",
"params",
".",
"NArg",
"(",
")",
"\n",
"if",
"argsN",
">",
"0",
"{",
"var",
"args",
"[",
"]",
"string",
"\n",
"for",
"i",
":=",
"0",
";",
... | // Params parse one by one the given argumentes | [
"Params",
"parse",
"one",
"by",
"one",
"the",
"given",
"argumentes"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L14-L24 | train |
oxequa/realize | realize/utils.go | split | func split(args, fields []string) []string {
for _, arg := range fields {
arr := strings.Fields(arg)
args = append(args, arr...)
}
return args
} | go | func split(args, fields []string) []string {
for _, arg := range fields {
arr := strings.Fields(arg)
args = append(args, arr...)
}
return args
} | [
"func",
"split",
"(",
"args",
",",
"fields",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"for",
"_",
",",
"arg",
":=",
"range",
"fields",
"{",
"arr",
":=",
"strings",
".",
"Fields",
"(",
"arg",
")",
"\n",
"args",
"=",
"append",
"(",
"args",... | // Split each arguments in multiple fields | [
"Split",
"each",
"arguments",
"in",
"multiple",
"fields"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L27-L33 | train |
oxequa/realize | realize/utils.go | ext | func ext(path string) string {
var ext string
for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- {
if path[i] == '.' {
ext = path[i:]
if index := strings.LastIndex(ext, "."); index > 0 {
ext = ext[index:]
}
}
}
if ext != "" {
return ext[1:]
}
return ""
} | go | func ext(path string) string {
var ext string
for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- {
if path[i] == '.' {
ext = path[i:]
if index := strings.LastIndex(ext, "."); index > 0 {
ext = ext[index:]
}
}
}
if ext != "" {
return ext[1:]
}
return ""
} | [
"func",
"ext",
"(",
"path",
"string",
")",
"string",
"{",
"var",
"ext",
"string",
"\n",
"for",
"i",
":=",
"len",
"(",
"path",
")",
"-",
"1",
";",
"i",
">=",
"0",
"&&",
"!",
"os",
".",
"IsPathSeparator",
"(",
"path",
"[",
"i",
"]",
")",
";",
"... | // Get file extensions | [
"Get",
"file",
"extensions"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L46-L60 | train |
oxequa/realize | realize/utils.go | replace | func replace(a []string, b string) []string {
if len(b) > 0 {
return strings.Fields(b)
}
return a
} | go | func replace(a []string, b string) []string {
if len(b) > 0 {
return strings.Fields(b)
}
return a
} | [
"func",
"replace",
"(",
"a",
"[",
"]",
"string",
",",
"b",
"string",
")",
"[",
"]",
"string",
"{",
"if",
"len",
"(",
"b",
")",
">",
"0",
"{",
"return",
"strings",
".",
"Fields",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] | // Replace if isn't empty and create a new array | [
"Replace",
"if",
"isn",
"t",
"empty",
"and",
"create",
"a",
"new",
"array"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L63-L68 | train |
oxequa/realize | realize/utils.go | Wdir | func Wdir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err.Error())
}
return dir
} | go | func Wdir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err.Error())
}
return dir
} | [
"func",
"Wdir",
"(",
")",
"string",
"{",
"dir",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"dir",
"\n",
"}"
] | // Wdir return current working directory | [
"Wdir",
"return",
"current",
"working",
"directory"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L71-L77 | train |
oxequa/realize | realize/notify.go | PollingWatcher | func PollingWatcher(interval time.Duration) FileWatcher {
if interval == 0 {
interval = time.Duration(1) * time.Second
}
return &filePoller{
interval: interval,
events: make(chan fsnotify.Event),
errors: make(chan error),
}
} | go | func PollingWatcher(interval time.Duration) FileWatcher {
if interval == 0 {
interval = time.Duration(1) * time.Second
}
return &filePoller{
interval: interval,
events: make(chan fsnotify.Event),
errors: make(chan error),
}
} | [
"func",
"PollingWatcher",
"(",
"interval",
"time",
".",
"Duration",
")",
"FileWatcher",
"{",
"if",
"interval",
"==",
"0",
"{",
"interval",
"=",
"time",
".",
"Duration",
"(",
"1",
")",
"*",
"time",
".",
"Second",
"\n",
"}",
"\n",
"return",
"&",
"filePol... | // PollingWatcher returns a poll-based file watcher | [
"PollingWatcher",
"returns",
"a",
"poll",
"-",
"based",
"file",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L58-L67 | train |
oxequa/realize | realize/notify.go | NewFileWatcher | func NewFileWatcher(l Legacy) (FileWatcher, error) {
if !l.Force {
if w, err := EventWatcher(); err == nil {
return w, nil
}
}
return PollingWatcher(l.Interval), nil
} | go | func NewFileWatcher(l Legacy) (FileWatcher, error) {
if !l.Force {
if w, err := EventWatcher(); err == nil {
return w, nil
}
}
return PollingWatcher(l.Interval), nil
} | [
"func",
"NewFileWatcher",
"(",
"l",
"Legacy",
")",
"(",
"FileWatcher",
",",
"error",
")",
"{",
"if",
"!",
"l",
".",
"Force",
"{",
"if",
"w",
",",
"err",
":=",
"EventWatcher",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"w",
",",
"nil",
"\n"... | // NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error | [
"NewFileWatcher",
"tries",
"to",
"use",
"an",
"fs",
"-",
"event",
"watcher",
"and",
"falls",
"back",
"to",
"the",
"poller",
"if",
"there",
"is",
"an",
"error"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L70-L77 | train |
oxequa/realize | realize/notify.go | EventWatcher | func EventWatcher() (FileWatcher, error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &fsNotifyWatcher{Watcher: w}, nil
} | go | func EventWatcher() (FileWatcher, error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &fsNotifyWatcher{Watcher: w}, nil
} | [
"func",
"EventWatcher",
"(",
")",
"(",
"FileWatcher",
",",
"error",
")",
"{",
"w",
",",
"err",
":=",
"fsnotify",
".",
"NewWatcher",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"fsNotif... | // EventWatcher returns an fs-event based file watcher | [
"EventWatcher",
"returns",
"an",
"fs",
"-",
"event",
"based",
"file",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L80-L86 | train |
oxequa/realize | realize/notify.go | Close | func (w *filePoller) Close() error {
w.mu.Lock()
if w.closed {
w.mu.Unlock()
return nil
}
w.closed = true
for name := range w.watches {
w.remove(name)
delete(w.watches, name)
}
w.mu.Unlock()
return nil
} | go | func (w *filePoller) Close() error {
w.mu.Lock()
if w.closed {
w.mu.Unlock()
return nil
}
w.closed = true
for name := range w.watches {
w.remove(name)
delete(w.watches, name)
}
w.mu.Unlock()
return nil
} | [
"func",
"(",
"w",
"*",
"filePoller",
")",
"Close",
"(",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"w",
".",
"closed",
"{",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"w",
"... | // Close closes the poller
// All watches are stopped, removed, and the poller cannot be added to | [
"Close",
"closes",
"the",
"poller",
"All",
"watches",
"are",
"stopped",
"removed",
"and",
"the",
"poller",
"cannot",
"be",
"added",
"to"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L108-L122 | train |
oxequa/realize | realize/notify.go | Add | func (w *filePoller) Add(name string) error {
w.mu.Lock()
defer w.mu.Unlock()
if w.closed {
return errPollerClosed
}
f, err := os.Open(name)
if err != nil {
return err
}
fi, err := os.Stat(name)
if err != nil {
return err
}
if w.watches == nil {
w.watches = make(map[string]chan struct{})
}
if _, exists := w.watches[name]; exists {
return fmt.Errorf("watch exists")
}
chClose := make(chan struct{})
w.watches[name] = chClose
go w.watch(f, fi, chClose)
return nil
} | go | func (w *filePoller) Add(name string) error {
w.mu.Lock()
defer w.mu.Unlock()
if w.closed {
return errPollerClosed
}
f, err := os.Open(name)
if err != nil {
return err
}
fi, err := os.Stat(name)
if err != nil {
return err
}
if w.watches == nil {
w.watches = make(map[string]chan struct{})
}
if _, exists := w.watches[name]; exists {
return fmt.Errorf("watch exists")
}
chClose := make(chan struct{})
w.watches[name] = chClose
go w.watch(f, fi, chClose)
return nil
} | [
"func",
"(",
"w",
"*",
"filePoller",
")",
"Add",
"(",
"name",
"string",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"w",
".",
"closed",
"{",
"return",
"errPolle... | // Add adds a filename to the list of watches
// once added the file is polled for changes in a separate goroutine | [
"Add",
"adds",
"a",
"filename",
"to",
"the",
"list",
"of",
"watches",
"once",
"added",
"the",
"file",
"is",
"polled",
"for",
"changes",
"in",
"a",
"separate",
"goroutine"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L132-L159 | train |
oxequa/realize | realize/schema.go | Add | func (s *Schema) Add(p Project) {
for _, val := range s.Projects {
if reflect.DeepEqual(val, p) {
return
}
}
s.Projects = append(s.Projects, p)
} | go | func (s *Schema) Add(p Project) {
for _, val := range s.Projects {
if reflect.DeepEqual(val, p) {
return
}
}
s.Projects = append(s.Projects, p)
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Add",
"(",
"p",
"Project",
")",
"{",
"for",
"_",
",",
"val",
":=",
"range",
"s",
".",
"Projects",
"{",
"if",
"reflect",
".",
"DeepEqual",
"(",
"val",
",",
"p",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"... | // Add a project if unique | [
"Add",
"a",
"project",
"if",
"unique"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L17-L24 | train |
oxequa/realize | realize/schema.go | Remove | func (s *Schema) Remove(name string) error {
for key, val := range s.Projects {
if name == val.Name {
s.Projects = append(s.Projects[:key], s.Projects[key+1:]...)
return nil
}
}
return errors.New("project not found")
} | go | func (s *Schema) Remove(name string) error {
for key, val := range s.Projects {
if name == val.Name {
s.Projects = append(s.Projects[:key], s.Projects[key+1:]...)
return nil
}
}
return errors.New("project not found")
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Remove",
"(",
"name",
"string",
")",
"error",
"{",
"for",
"key",
",",
"val",
":=",
"range",
"s",
".",
"Projects",
"{",
"if",
"name",
"==",
"val",
".",
"Name",
"{",
"s",
".",
"Projects",
"=",
"append",
"(",
... | // Remove a project | [
"Remove",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L27-L35 | train |
oxequa/realize | realize/schema.go | New | func (s *Schema) New(c *cli.Context) Project {
var vgo bool
name := filepath.Base(c.String("path"))
if len(name) == 0 || name == "." {
name = filepath.Base(Wdir())
}
if hasGoMod(Wdir()) {
vgo = true
}
project := Project{
Name: name,
Path: c.String("path"),
Tools: Tools{
Vet: Tool{
Status: c.Bool("vet"),
},
Fmt: Tool{
Status: c.Bool("fmt"),
},
Test: Tool{
Status: c.Bool("test"),
},
Generate: Tool{
Status: c.Bool("generate"),
},
Build: Tool{
Status: c.Bool("build"),
},
Install: Tool{
Status: c.Bool("install"),
},
Run: Tool{
Status: c.Bool("run"),
},
vgo: vgo,
},
Args: params(c),
Watcher: Watch{
Paths: []string{"/"},
Ignore: []string{".git", ".realize", "vendor"},
Exts: []string{"go"},
},
}
return project
} | go | func (s *Schema) New(c *cli.Context) Project {
var vgo bool
name := filepath.Base(c.String("path"))
if len(name) == 0 || name == "." {
name = filepath.Base(Wdir())
}
if hasGoMod(Wdir()) {
vgo = true
}
project := Project{
Name: name,
Path: c.String("path"),
Tools: Tools{
Vet: Tool{
Status: c.Bool("vet"),
},
Fmt: Tool{
Status: c.Bool("fmt"),
},
Test: Tool{
Status: c.Bool("test"),
},
Generate: Tool{
Status: c.Bool("generate"),
},
Build: Tool{
Status: c.Bool("build"),
},
Install: Tool{
Status: c.Bool("install"),
},
Run: Tool{
Status: c.Bool("run"),
},
vgo: vgo,
},
Args: params(c),
Watcher: Watch{
Paths: []string{"/"},
Ignore: []string{".git", ".realize", "vendor"},
Exts: []string{"go"},
},
}
return project
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"New",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"Project",
"{",
"var",
"vgo",
"bool",
"\n",
"name",
":=",
"filepath",
".",
"Base",
"(",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"len",
... | // New create a project using cli fields | [
"New",
"create",
"a",
"project",
"using",
"cli",
"fields"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L38-L84 | train |
oxequa/realize | realize/schema.go | Filter | func (s *Schema) Filter(field string, value interface{}) []Project {
result := []Project{}
for _, item := range s.Projects {
v := reflect.ValueOf(item)
for i := 0; i < v.NumField(); i++ {
if v.Type().Field(i).Name == field {
if reflect.DeepEqual(v.Field(i).Interface(), value) {
result = append(result, item)
}
}
}
}
return result
} | go | func (s *Schema) Filter(field string, value interface{}) []Project {
result := []Project{}
for _, item := range s.Projects {
v := reflect.ValueOf(item)
for i := 0; i < v.NumField(); i++ {
if v.Type().Field(i).Name == field {
if reflect.DeepEqual(v.Field(i).Interface(), value) {
result = append(result, item)
}
}
}
}
return result
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Filter",
"(",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"[",
"]",
"Project",
"{",
"result",
":=",
"[",
"]",
"Project",
"{",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"s",
".",
"... | // Filter project list by field | [
"Filter",
"project",
"list",
"by",
"field"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L87-L100 | train |
oxequa/realize | realize/style.go | Regular | func (c colorBase) Regular(a ...interface{}) string {
return color.New(color.Attribute(c)).Sprint(a...)
} | go | func (c colorBase) Regular(a ...interface{}) string {
return color.New(color.Attribute(c)).Sprint(a...)
} | [
"func",
"(",
"c",
"colorBase",
")",
"Regular",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"color",
".",
"New",
"(",
"color",
".",
"Attribute",
"(",
"c",
")",
")",
".",
"Sprint",
"(",
"a",
"...",
")",
"\n",
"}"
] | // Regular font with a color | [
"Regular",
"font",
"with",
"a",
"color"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/style.go#L26-L28 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.