• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang text.Wrap函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kr/text.Wrap函数的典型用法代码示例。如果您正苦于以下问题:Golang Wrap函数的具体用法?Golang Wrap怎么用?Golang Wrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Wrap函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: createListFileContent

func createListFileContent(filePaths []string, includeHeader bool) string {
	output := ""
	header := ""

	if includeHeader {
		// NOTE: kr/text.Wrap returns lines separated by \n for all platforms.
		// So here hard-code \n too. Later it will be changed to \r\n for Windows.
		header = text.Wrap("Please change the filenames that need to be renamed and save the file. Lines that are not changed will be ignored (no file will be renamed), so will empty lines.", LINE_LENGTH-3)
		header += "\n"
		header += "\n" + text.Wrap("You may delete a file by putting \"//\" at the beginning of the line. Note that this operation cannot be undone (though the file can be recovered from the trash on Windows and OSX).", LINE_LENGTH-3)
		header += "\n"
		header += "\n" + text.Wrap("Please do not swap the order of lines as this is what is used to match the original filenames to the new ones. Also do not delete lines as the rename operation will be cancelled due to a mismatch between the number of filenames before and after saving the file. You may test the effect of the rename operation using the --dry-run parameter.", LINE_LENGTH-3)
		header += "\n"
		header += "\n" + text.Wrap("Caveats: "+APPNAME+" expects filenames to be reasonably sane. Filenames that include newlines or non-printable characters for example will probably not work.", LINE_LENGTH-3)

		headerLines := strings.Split(header, "\n")
		temp := ""
		for _, line := range headerLines {
			if temp != "" {
				temp += newline()
			}
			temp += "// " + line
		}
		header = temp + newline() + newline()
	}

	for _, filePath := range filePaths {
		output += filepath.Base(filePath) + newline()
	}

	return header + output
}
开发者ID:flyeven,项目名称:massren,代码行数:32,代码来源:main.go


示例2: wrapDescription

// wrapDescription wraps the text in a cliflags.FlagInfo.Description.
func wrapDescription(s string) string {
	var result bytes.Buffer

	// split returns the parts of the string before and after the first occurrence
	// of the tag.
	split := func(str, tag string) (before, after string) {
		pieces := strings.SplitN(str, tag, 2)
		switch len(pieces) {
		case 0:
			return "", ""
		case 1:
			return pieces[0], ""
		default:
			return pieces[0], pieces[1]
		}
	}

	for len(s) > 0 {
		var toWrap, dontWrap string
		// Wrap everything up to the next stop wrap tag.
		toWrap, s = split(s, "<PRE>")
		result.WriteString(text.Wrap(toWrap, wrapWidth))
		// Copy everything up to the next start wrap tag.
		dontWrap, s = split(s, "</PRE>")
		result.WriteString(dontWrap)
	}
	return result.String()
}
开发者ID:yaojingguo,项目名称:cockroach,代码行数:29,代码来源:flags.go


示例3: drawnode

func drawnode(f *os.File, r *node, prefix []int) {
	r.depth = len(prefix)
	s := prefToString(prefix)

	kvs := map[string]string{}

	kvs["label"] = fmt.Sprintf("\"%s\"", text.Wrap(r.label, 20))
	if r.colour != "" {
		kvs["style"] = "filled"
		kvs["color"] = r.colour
	}
	var strs []string
	for k, v := range kvs {
		strs = append(strs, k+"="+v)
	}
	fmt.Fprintf(f, "    %s [%s]\n", s, strings.Join(strs, ","))
	if len(r.children) > 0 {
		lastAnd := ""
		for i, c := range r.children {
			newp := append(prefix, i+1)
			if lastAnd != "" {
				fmt.Fprintf(f, "    %s -> %s [label=\"and\",constraint=false]\n", lastAnd, prefToString(newp))
				lastAnd = ""
			}
			if c.refine == "AND" {
				lastAnd = prefToString(newp)
			}
			drawnode(f, c, newp)
			fmt.Fprintf(f, "    %s -> %s\n", s, prefToString(newp))
		}
	} else {
	}
}
开发者ID:tcolgate,项目名称:test,代码行数:33,代码来源:main.go


示例4: wrap

// this isn't real efficient, but that's not a problem here
func wrap(s string, indent int) string {
	if indent > 3 {
		indent = 3
	}

	wrapped := text.Wrap(s, maxLine)
	lines := strings.SplitN(wrapped, "\n", 2)
	if len(lines) == 1 {
		return lines[0]
	}

	if (maxLine - indentLen(indent)) <= 0 {
		panic("too much indentation")
	}

	rest := strings.Join(lines[1:], " ")
	wrapped = text.Wrap(rest, maxLine-indentLen(indent))
	return lines[0] + "\n" + text.Indent(wrapped, makeIndent(indent))
}
开发者ID:leobcn,项目名称:goutils-1,代码行数:20,代码来源:util.go


示例5: outputErrors

func outputErrors(errors []compilercommon.SourceError) {
	sort.Sort(ErrorsSlice(errors))

	highlight := color.New(color.FgRed, color.Bold)
	location := color.New(color.FgWhite)
	message := color.New(color.FgHiWhite)

	for _, err := range errors {
		highlight.Print("ERROR: ")
		location.Printf("At %v:%v:%v:\n", err.SourceAndLocation().Source(), err.SourceAndLocation().Location().LineNumber()+1, err.SourceAndLocation().Location().ColumnPosition()+1)
		message.Printf("%s\n\n", text.Indent(text.Wrap(err.Error(), 80), "  "))
	}
}
开发者ID:Serulian,项目名称:compiler,代码行数:13,代码来源:builder.go


示例6: outputWarnings

func outputWarnings(warnings []compilercommon.SourceWarning) {
	sort.Sort(WarningsSlice(warnings))

	highlight := color.New(color.FgYellow, color.Bold)
	location := color.New(color.FgWhite)
	message := color.New(color.FgHiWhite)

	for _, warning := range warnings {
		highlight.Print("WARNING: ")
		location.Printf("At %v:%v:%v:\n", warning.SourceAndLocation().Source(), warning.SourceAndLocation().Location().LineNumber()+1, warning.SourceAndLocation().Location().ColumnPosition()+1)
		message.Printf("%s\n\n", text.Indent(text.Wrap(warning.String(), 80), "  "))
	}
}
开发者ID:Serulian,项目名称:compiler,代码行数:13,代码来源:builder.go


示例7: main

func main() {
	minLogLevel_ = 1

	// -----------------------------------------------------------------------------------
	// Handle SIGINT (Ctrl + C)
	// -----------------------------------------------------------------------------------

	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, os.Interrupt, os.Kill)
	go func() {
		<-signalChan
		logInfo("Operation has been aborted.")
		onExit()
		os.Exit(2)
	}()

	defer onExit()

	// -----------------------------------------------------------------------------------
	// Parse arguments
	// -----------------------------------------------------------------------------------

	var opts CommandLineOptions
	flagParser_ = flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash)
	args, err := flagParser_.Parse()
	if err != nil {
		t := err.(*flags.Error).Type
		if t == flags.ErrHelp {
			printHelp()
			return
		} else {
			criticalError(err)
		}
	}

	if opts.Verbose {
		minLogLevel_ = 0
	}

	err = profileOpen()
	if err != nil {
		logError(fmt.Sprintf("%s", err))
	}

	// -----------------------------------------------------------------------------------
	// Handle selected command
	// -----------------------------------------------------------------------------------

	var commandName string
	if opts.Config {
		commandName = "config"
	} else if opts.Undo {
		commandName = "undo"
	} else if opts.Version {
		commandName = "version"
	} else {
		commandName = "rename"
	}

	var commandErr error
	switch commandName {
	case "config":
		commandErr = handleConfigCommand(&opts, args)
	case "undo":
		commandErr = handleUndoCommand(&opts, args)
	case "version":
		commandErr = handleVersionCommand(&opts, args)
	}

	if commandErr != nil {
		criticalError(commandErr)
	}

	if commandName != "rename" {
		return
	}

	filePaths, err := filePathsFromArgs(args)

	if err != nil {
		criticalError(err)
	}

	if len(filePaths) == 0 {
		criticalError(errors.New("no file to rename"))
	}

	// -----------------------------------------------------------------------------------
	// Build file list
	// -----------------------------------------------------------------------------------

	listFileContent := ""
	baseFilename := ""

	// NOTE: kr/text.Wrap returns lines separated by \n for all platforms.
	// So here hard-code \n too. Later it will be changed to \r\n for Windows.
	header := text.Wrap("Please change the filenames that need to be renamed and save the file. Lines that are not changed will be ignored (no file will be renamed), so will empty lines.", LINE_LENGTH-3)
	header += "\n"
	header += "\n" + text.Wrap("You may delete a file by putting \"//\" at the beginning of the line. Note that this operation cannot be undone (though the file can be recovered from the trash on Windows and OSX).", LINE_LENGTH-3)
	header += "\n"
//.........这里部分代码省略.........
开发者ID:vidyacraghav,项目名称:massren,代码行数:101,代码来源:main.go


示例8:

are preserved across updating *if and only if* the primary keys provided by
IMDb don't change. Unfortunately, IMDb primary keys can change (for example,
by adding a title to an episode). This results in stale rows in the 'atom' and
'name' tables (but will be hidden from search results).
`,
	flags: flag.NewFlagSet("load", flag.ExitOnError),
	run:   cmd_load,
	addFlags: func(c *command) {
		c.flags.StringVar(&flagLoadDownload, "download", flagLoadDownload,
			"When set, the data retrieved will be stored in the directory\n"+
				"specified. Then goim will quit.")
		c.flags.BoolVar(&flagLoadUrls, "urls", flagLoadUrls,
			"When set, the URLs for downloading the lists specified will\n"+
				"be printed to stdout, each on their own line. Then goim\n"+
				"will quit.")
		lists := text.Wrap(strings.Join(loadLists, ", "), 80)
		c.flags.StringVar(&flagLoadLists, "lists", flagLoadLists,
			"Set to a comma separated list of IMDB movie lists to load, with\n"+
				"no whitespace. Only lists named here will be loaded. If not\n"+
				"specified, then only the 'movie' list is loaded.\n"+
				"Use 'all' to load all lists or 'attr' to load all attribute\n"+
				"lists (e.g., quotes, running times, etc.).\n"+
				"Available lists: "+lists)
		c.flags.BoolVar(&flagWarnings, "warn", flagWarnings,
			"When set, warnings messages about the data will be shown.\n"+
				"When enabled, this can produce a lot of output saying that\n"+
				"an identifier could not be found for some entries. This is\n"+
				"(likely) a result of inconsistent data in IMDb's text files.")
	},
}
开发者ID:BurntSushi,项目名称:goim,代码行数:30,代码来源:cmd_load.go


示例9: wrappedIndent

func wrappedIndent(s string, indentS string) string {
	return text.Indent(text.Wrap(s, 80-len(indentS)), indentS)
}
开发者ID:sr,项目名称:operator,代码行数:3,代码来源:command.go


示例10: wrap

func wrap(s string) string {
	return text.Wrap(s, 80)
}
开发者ID:sr,项目名称:operator,代码行数:3,代码来源:command.go


示例11: wrap

func wrap(limit int, s interface{}) string {
	return text.Wrap(sf("%s", s), limit)
}
开发者ID:BurntSushi,项目名称:goim,代码行数:3,代码来源:helpers.go


示例12: AnalyzeLocalImage


//.........这里部分代码省略.........
		select {
		case err := <-ch:
			return fmt.Errorf("An error occured when starting HTTP server: %s", err)
		case <-time.After(100 * time.Millisecond):
			break
		}

		tmpPath = "http://" + myAddress + ":" + strconv.Itoa(httpPort)
	}

	// Analyze layers.
	log.Printf("Analyzing %d layers... \n", len(layerIDs))
	for i := 0; i < len(layerIDs); i++ {
		log.Printf("Analyzing %s\n", layerIDs[i])

		if i > 0 {
			err = analyzeLayer(endpoint, tmpPath+"/"+layerIDs[i]+"/layer.tar", layerIDs[i], layerIDs[i-1])
		} else {
			err = analyzeLayer(endpoint, tmpPath+"/"+layerIDs[i]+"/layer.tar", layerIDs[i], "")
		}
		if err != nil {
			return fmt.Errorf("Could not analyze layer: %s", err)
		}
	}

	// Get vulnerabilities.
	log.Println("Retrieving image's vulnerabilities")
	layer, err := getLayer(endpoint, layerIDs[len(layerIDs)-1])
	if err != nil {
		return fmt.Errorf("Could not get layer information: %s", err)
	}

	// Print report.
	fmt.Printf("Clair report for image %s (%s)\n", imageName, time.Now().UTC())

	if len(layer.Features) == 0 {
		fmt.Printf("%s No features have been detected in the image. This usually means that the image isn't supported by Clair.\n", color.YellowString("NOTE:"))
		return nil
	}

	isSafe := true
	hasVisibleVulnerabilities := false

	var vulnerabilities = make([]vulnerabilityInfo, 0)
	for _, feature := range layer.Features {
		if len(feature.Vulnerabilities) > 0 {
			for _, vulnerability := range feature.Vulnerabilities {
				severity := types.Priority(vulnerability.Severity)
				isSafe = false

				if minSeverity.Compare(severity) > 0 {
					continue
				}

				hasVisibleVulnerabilities = true
				vulnerabilities = append(vulnerabilities, vulnerabilityInfo{vulnerability, feature, severity})
			}
		}
	}

	// Sort vulnerabilitiy by severity.
	priority := func(v1, v2 vulnerabilityInfo) bool {
		return v1.severity.Compare(v2.severity) >= 0
	}

	By(priority).Sort(vulnerabilities)

	for _, vulnerabilityInfo := range vulnerabilities {
		vulnerability := vulnerabilityInfo.vulnerability
		feature := vulnerabilityInfo.feature
		severity := vulnerabilityInfo.severity

		fmt.Printf("%s (%s)\n", vulnerability.Name, coloredSeverity(severity))

		if vulnerability.Description != "" {
			fmt.Printf("%s\n\n", text.Indent(text.Wrap(vulnerability.Description, 80), "\t"))
		}

		fmt.Printf("\tPackage:       %s @ %s\n", feature.Name, feature.Version)

		if vulnerability.FixedBy != "" {
			fmt.Printf("\tFixed version: %s\n", vulnerability.FixedBy)
		}

		if vulnerability.Link != "" {
			fmt.Printf("\tLink:          %s\n", vulnerability.Link)
		}

		fmt.Printf("\tLayer:         %s\n", feature.AddedBy)
		fmt.Println("")
	}

	if isSafe {
		fmt.Printf("%s No vulnerabilities were detected in your image\n", color.GreenString("Success!"))
	} else if !hasVisibleVulnerabilities {
		fmt.Printf("%s No vulnerabilities matching the minimum severity level were detected in your image\n", color.YellowString("NOTE:"))
	}

	return nil
}
开发者ID:robinjha,项目名称:clair,代码行数:101,代码来源:main.go


示例13: init

func init() {
	var directives []string
	for _, cmd := range search.Commands {
		s := cmd.Name
		if len(cmd.Synonyms) > 0 {
			s += sf(" (synonyms: %s)", strings.Join(cmd.Synonyms, ", "))
		}
		s += "\n"
		s += text.Indent(text.Wrap(cmd.Description, 78), "  ")
		directives = append(directives, s)
	}
	cmdDoc := strings.Join(directives, "\n\n")

	cmdSearch.help = sf(`
The search command exposes a flexible interface for quickly searching IMDb
for entities, where entities includes movies, TV shows, episodes and actors.

A search query has two different components: text to search the names of 
entities in the database and directives to do additional filtering on 
attributes of entities (like year released, episode number, cast/credits, 
etc.). Included in those directives are options to sort the results or specify 
a limit on the number of results returned.

The search query is composed of whitespace delimited tokens. Each token that 
starts and ends with a '{' and '}' is a directive. All other tokens are used as 
text to search the names of entities.

If you're using PostgreSQL with the 'pg_trgm' extension enabled, then text 
searching is fuzzy. Otherwise, text may contain the wildcard '%%' which matches 
any sequence of characters or the wildcard '_' which matches any single 
character. Whenever a wildcard character is used, fuzzy search is disabled (and 
the search will be case insensitive).

Directives have the form '{NAME[:ARGUMENT]}', where NAME is the name of the 
directive and ARGUMENT is an argument for the directive. Each directive either 
requires no argument or requires a single argument.

Examples
--------
The following are some example query strings. They can be used in 'goim search'
as is. Note that examples without wildcards assume that a PostgreSQL database 
is used with the 'pg_trgm' extension enabled. Some also assume that your 
database has certain data (for example, the 'actors' list must be loaded to use 
the 'cast' and 'credits' directives).

Find all entities with names beginning with 'The Matrix' (case insensitive):

  'the matrix%%'

Now restrict those results to only movies:

  'the matrix%%' {movie}

Or restrict them further by only listing movies where Keanu Reeves is a 
credited cast member:

  'the matrix%%' {movie} {cast:keanu reeves}

Finally, sort the list of movies by IMDb rank and restrict the results to only
movies with 10,000 votes or more:

  'the matrix%%' {movie} {cast:keanu reeves} {sort:rank desc} {votes:10000-}

We could also search in the other direction, for example, by finding the top
5 credits in the movie The Matrix:

  {credits:the matrix} {billing:1-5} {sort:billing asc}

If you try this with 'goim search', then you'll get a prompt that 'credits is
ambiguous' with a list of entities to choose. This can be rather inconvenient
to see every time. Luckily, directives like 'credits' and 'cast' are actually
entire sub-searches that support directives themselves. For example, we can 
specify that the matrix is a movie, which should be enough to make an 
umabiguous selection:

  {credits:the matrix {movie}} {billing:1-5} {sort:billing asc}

Let's switch gears and look at searching episodes for television shows. For 
example, we can list the episode names for the first season of The Simpsons:

  {show:simpsons} {seasons:1} {sort:episode asc}

Note here that there is no text to search here. But we could add some if we 
wanted to, for example, to see all episodes in the entire series with 'bart' in 
the title:

  {show:simpsons} {sort:season asc} {sort:episode asc} '%%bart%%' {limit:1000}

Note the changes here: we removed the restriction on the first season, added
a limit of 1000 (since the default limit is 30, but there may be more than 30 
episodes with 'bart' in the title) and added an additional sorting criterion.
In this case, we want to sort by season first and then by episode. (The order
in which they appear in the query matters.)

We can view this data in a lot of different ways, for example, by finding the
top 10 best ranked Simpsons episodes with more than 500 votes:

  {show:simpsons} {sort:rank desc} {limit:10} {votes:500-}

All search directives
//.........这里部分代码省略.........
开发者ID:BurntSushi,项目名称:goim,代码行数:101,代码来源:cmd_search.go



注:本文中的github.com/kr/text.Wrap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang bson.Raw类代码示例发布时间:2022-05-23
下一篇:
Golang text.Indent函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap