func oneDomainCheck(domain string, flagShowFreeOnly bool) { checkedDomain, isFree := check(domain) if isFree == true { color.Print("@g[FREE]", checkedDomain) } else if flagShowFreeOnly == false { color.Print("@r[NOT FREE]", checkedDomain) } }
func showNewsList(news []Item) { for i, item := range news { color.Print("@b", fmt.Sprintf("%2d", i+1)) fmt.Print(" ") color.Print("@{!g}", item.Title) fmt.Print(" ") color.Print("@y", fmt.Sprintf("%dc", item.CommentsCount)) fmt.Print(" ") color.Print("@m", fmt.Sprintf("%dp", item.Points)) fmt.Print(" ") color.Print("@w", item.Domain) fmt.Println() } }
func handle(file string) { filename, err := os.Open(file) defer filename.Close() if err != nil { log.Fatal(err) } scanner := bufio.NewScanner(filename) var domains []string for scanner.Scan() { domain, isFree := check(scanner.Text()) if isFree == true { domains = append(domains, domain) } else if showFreeOnly == false { domains = append(domains, domain) } } sort.Strings(domains) for i := 0; i < len(domains); i++ { if showFreeOnly == true { color.Print("@g[FREE]", domains[i]) } else { fmt.Print(domains[i]) } } }
func (msg *message) log(elapsed time.Duration) { if fmtstr := formatFor(msg.namespace); fmtstr != "" { payload := fmt.Sprintf(msg.message, msg.args...) content := fmt.Sprintf(fmtstr, msg.from_file, msg.from_line, payload, elapsed) colorfmt.Print(content) } }
func getFuncNames(filecontent []string) ([]string, []string) { r := make([]string, 0) r2 := make([]string, 0) var funcCounter int64 functionRx := regexp.MustCompile(FUNCTION_NAME_REGEX) functionDefRx := regexp.MustCompile(FUNCTION_DEFINITION_REGEX) for lineno, line := range filecontent { if functionRx.MatchString(line) { funcnameB := functionRx.FindSubmatch([]byte(line)) funcname := string(funcnameB[1]) funcCounter = funcCounter + 1 fmt.Printf("%v %d ", funcCounter, lineno) color.Print("@g", funcname) color.Println("@y|", line) r = append(r, funcname) if functionDefRx.MatchString(line) { funcdefB := functionDefRx.FindSubmatch([]byte(line)) funcdef := string(funcdefB[1]) r2 = append(r2, funcdef) } else { log.Fatal("Can detect the funciton name but not the function definition! That is not acceptable") } } } return r, r2 }
func prettyPrint(repo github.Repository, index int) { fmt.Print("[") color.Print("@b", index) fmt.Print("]") fmt.Print(*repo.FullName) if repo.StargazersCount != nil { color.Print("@r"+" "+strconv.Itoa(*repo.StargazersCount), "☆") } if repo.Language != nil { color.Print("@c" + " " + *repo.Language) } if repo.Description != nil { color.Print("@g" + " " + *repo.Description) } fmt.Println() }
func (logger *Logger) Info(msgs ...interface{}) { if isTestEnv() { logger.infos = append(logger.infos, msgs...) return } color.Print(msgs...) }
func LogMessage(message string, textColor string) { msg := fmt.Sprintf("%v", message) var c string if textColor != "" { c = fmt.Sprintf("@%v", textColor) } color.Print(c, fmt.Sprintf(" %v\n", msg)) }
func main() { terminal.Stdout.Color("y"). Print("Hello world").Nl(). Reset(). Colorf("@{kW}Hello world\n") color.Print("@rHello world") }
func (logger *Logger) Warn(msgs ...interface{}) { if isTestEnv() { logger.warns = append(logger.warns, msgs...) return } msgs = append([]interface{}{"@y"}, msgs...) color.Print(msgs...) }
// Draw all Cell structures func (game *Game) Draw() { clearScreen() fmt.Printf("Generation : %v\n", game.Generation) for _, r := range game.Rows { for _, c := range r.Cells { if c.Value == 1 { color.Print(fmt.Sprintf("%v ", c.Color)) } else { color.Print("@c.") } } fmt.Printf("\n") } game.Sleep() }
func (logger *Logger) Errors(status int, msgs ...interface{}) { if isTestEnv() { logger.errors = append(logger.errors, msgs...) return } msgs = append([]interface{}{"@r"}, msgs...) color.Print(msgs...) os.Exit(status) }
func (c *AddCategoryCommand) Run() error { c.Slug = c.Title category := models.NewCategory(db.USERID, c.CategoryType, c.Title, c.Slug) err := category.Save().Error if err != nil { return err } color.Print("@gCategory added{|}\n") return nil }
func (c *DeleteItemCommand) Run() error { item := models.Item{} item.Find(item.Id) if item.Id == 0 { return errors.New("Inavlid id") } err := item.Delete().Error if err != nil { return err } color.Print("@gItem deleted\n") return nil }
func (c *DeleteCategoryCommand) Run() error { category := models.Category{} category.Find(c.Id) if category.Id == 0 { return errors.New("Inavlid id") } err := category.Delete().Error if err != nil { return err } color.Print("@gCategory deleted\n") return nil }
func main() { reader := bufio.NewReader(os.Stdin) for { color.Print("@b>> ") words, _ := reader.ReadString('\n') text, err := request(strings.TrimSpace(words)) if err != nil { color.Println("@rERROR : ", err) } color.Println("@r>> ", text) } }
func (s *LoggingServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { s.mu.RLock() defer s.mu.RUnlock() if i := sort.SearchStrings(s.ExcludePaths, req.URL.Path); i < len(s.ExcludePaths) && req.URL.Path == s.ExcludePaths[i] { return } req.ParseForm() // Log request var data string for key, _ := range req.Form { data += "\n " if value := req.Form.Get(key); value != "" { data += color.Sprintf("@.%s@|@w = @|%s", key, value) } else { data += color.Sprintf("%s", key) } } log.Print(color.Sprintf("@c%s @{!y}%s", req.Method, req.RequestURI)) if data != "" { color.Printf(" @bRequest@|%s\n", data) } // Find matcher matcher := s.findMatcher(req) if matcher != nil { matcher.Write(w, req) // TODO Better response logging response := matcher.Response color.Printf(" @gResponse@|\n %+v\n", response) } else { color.Print(" @rUnmatched@|\n") w.WriteHeader(http.StatusNotFound) w.Header().Set("Content-Type", "text/html") io.WriteString(w, "<html><body>Unmatched request, please configure a mock request for path "+req.URL.Path+" and method "+req.Method+"</body></html>\n") } }
// Main command method func (c *AddItemCommand) Run() error { category := &models.Category{} err := category.FindCategoryOrCreate(map[string]interface{}{ "title": c.CategoryTitle, "type": c.ItemType, }).Error if err != nil { return err } item := models.NewItem(db.USERID, category.Id, c.ItemType, c.Comment, c.Amount) err = item.Save().Error if err != nil { return err } color.Print("@gItem added@{|}\n") return nil }
// Main command method func (c *EditItemCommand) Run() error { var item models.Item item.Find(c.Id) if item.Id == 0 { return errors.New("Invalid Item Id") } if c.Amount != 0 { item.Amount = c.Amount } if c.ItemType != "" { item.Type = c.ItemType } if c.Comment != "" { item.Comment = c.Comment } if c.CategoryTitle != "" { category := &models.Category{} err := category.FindCategoryOrCreate(map[string]interface{}{ "title": c.CategoryTitle, "type": item.Type, }).Error if err != nil { return err } item.CategoryId = category.Id } err := item.Save().Error if err != nil { return err } color.Print("@gItem edited\n") return nil }
func (c *EditCategoryCommand) Run() error { category := &models.Category{} category.Find(c.Id) if category.Id == 0 { return errors.New("Category not found") } if c.Title != "" { category.Title = c.Title } if c.CategoryType != "" { category.Type = c.CategoryType } err := category.Save().Error if err != nil { return err } color.Print("@gCategory edited\n") return nil }
func (c *DeleteCategoryCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman delete-category -id=<id>\n") }
func (c *AddCategoryCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman add-category -title=<title> -type=<spent|income>\n") }
func main() { //originalFile := "./OriginalPlotClusters.m" //className := "PC" originalFile := "./OriginalAllVPCs.m" className := "AllV" b, err := ioutil.ReadFile(originalFile) if err != nil { log.Fatal("Cant read the original,", err) } lines := strings.Split(string(b), "\n") funcnames, funcdefs := getFuncNames(lines) //revese the funcnames, to reduce the change of collision, like a funcname being embded inside another function name funcnames = reversSortStringSlice(funcnames) //TODO: in all the function declaration lines, replace `=([A-z])` with '= \1' functionRx := regexp.MustCompile(FUNCTION_NAME_REGEX) var funcCounter int64 //insidefunc := false //TODO: the assuption is the original file STARTS with a function declaration line, no comments of white space before it funclines := make([]string, 0) funcname := "" lineno := 0 line := "" for lineno, line = range lines { if functionRx.MatchString(line) { if len(funclines) != 0 { patchedfunclines := renameFuncs(className, funclines, funcnames) color.Println("@rWriting: ", funcname) err = ioutil.WriteFile(funcname+".m", []byte(strings.Join(patchedfunclines, "")), os.ModePerm) if err != nil { log.Fatal("Error writing the file", err) } funclines = make([]string, 0) } funcnameB := functionRx.FindSubmatch([]byte(line)) funcname = string(funcnameB[1]) funcCounter = funcCounter + 1 fmt.Printf("%v %d ", funcCounter, lineno) color.Print("@g", funcname) color.Println("@y|", line) } funclines = append(funclines, line) } //write the last function if len(funclines) != 0 { patchedfunclines := renameFuncs(className, funclines, funcnames) color.Println("@rWriting: ", funcname) err = ioutil.WriteFile(funcname+".m", []byte(strings.Join(patchedfunclines, "")), os.ModePerm) if err != nil { log.Fatal("Error writing the file", err) } funclines = make([]string, 0) } //TODO: do the main class def file classdeflines := "" classdeflines = classdeflines + "classdef " + className + "\r" classdeflines = classdeflines + `properties Version = '1' end methods (Static) ` classdeflines = classdeflines + strings.Join(funcdefs, "\r") classdeflines = classdeflines + ` end end ` err = ioutil.WriteFile(className+".m", []byte(classdeflines), os.ModePerm) if err != nil { log.Fatal("Error writing the Classdefninition file", err) } }
// Print how to use this command func (c *EditItemCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman edit-item -id=id [-amount=<amount>] [-type=<spent|income>] [-category=<category>] [-comment=<comment>]\n") }
// Print how to use this command func (c *AddItemCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman add-item -amount=<amount> -type=<spent|income> -category=<category> [-comment=<comment>]\n") }
func (c *EditCategoryCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman edit-category -id=<id> [-title=<title>] [-type=<spent|income>]\n") }
func (c *ListItemCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman list-item -type=type [-category=category]\n") }
// Print how to use this command func (c *InitCommand) Usage(err error) { color.Print("@rError:\n", err, "\n") fmt.Println("Usage: karman init -username=<username> -email=<email>") }
func (c *BalanceCommand) Usage(err error) { color.Print("@rError: ", err, "@{|}\n") fmt.Printf("Usage: karman balance\n") }
func main() { path := os.Getenv("TANGORPATH") if path == "" { path = os.Getenv("HOME") + "/.tangor" } config := getConfig(path) keyfile := flag.String("i", path+"/id_dsa", "Identity file") bootstrap := flag.String("b", "", "Additional bootstrap node") web := flag.Bool("web", false, "Open web browser") flag.Parse() color.Print("\n@{Gk} @{Yk} tangor @{Gk} @{|}\n\n") if len(*bootstrap) > 0 { config.B = append(config.B, *bootstrap) } key, err := getKey(*keyfile) if err != nil { color.Printf(" -> @{Rk}ERROR:@{|} %v\n", err) os.Exit(-1) } id := utils.NewNodeID(utils.GlobalNamespace, key.Digest()) color.Printf("Your ID: @{Wk} %s @{|}\n\n", id.String()) client, err := murcott.NewClient(key, config) if err != nil { panic(err) } defer client.Close() filename := filepath.Join(path, id.Digest.String()+".dat") data, err := ioutil.ReadFile(filename) if err == nil { client.UnmarshalBinary(data) } if *web { go webui() open.Run("http://localhost:3000") } exit := make(chan int) s := Session{cli: client} go func() { for { select { case <-exit: return case <-time.After(time.Minute): s.save(filename) } } }() s.bootstrap() s.commandLoop() s.save(filename) close(exit) }