Documentation
¶
Overview ¶
Package github.com/sttk/linebreak is a library for breaking a given text into lines within a specified width. This library also supports per-line indentation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RuneWidth ¶ added in v0.4.0
RuneWidth is the function that returns the display width of the specified rune. A display width is determined by the Unicode Standard Annex #11 (UAX11) East-Asian-Width.
func TermCols ¶ added in v0.4.0
func TermCols() int
TermCols is the function that returns the column count of the current terminal. This count is the number of ASCII printable characters. If it failed to get the count, this function returns the fixed number: 80.
func TermSize ¶ added in v0.4.0
func TermSize() (cols, rows int)
TermSize is the function that returns the column count and row count of the current terminal. These counts are the numbers of ASCII printable characters. If it failed to get these counts, this function returns the fixed numbers: 80 columns and 24 rows..
Types ¶
type LineIter ¶
type LineIter struct {
// contains filtered or unexported fields
}
LineIter is the struct that outputs the given string line by line. This struct can control the overall line width and the indentation from any desired line.
Example ¶
package main import ( "fmt" "github.com/sttk/linebreak" ) func main() { text := "Go is a new language. Although it borrows ideas from existing " + "languages, it has unusual properties that make effective Go programs " + "different in character from programs written in its relatives. " + "\n\n(Quoted from 'Effective Go')" fmt.Println("....:....1....:....2....:....3....:....4....:....5") iter := linebreak.New(text, 50) for iter.HasNext() { line, _ := iter.Next() fmt.Println(line) } }
Output: ....:....1....:....2....:....3....:....4....:....5 Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different in character from programs written in its relatives. (Quoted from 'Effective Go')
func New ¶
New is the function that creates a LineIter instance which outputs the given string line by line. The second arguument is the width of the output lines.
func (*LineIter) Init ¶
Init is the method to re-initialize with an argument string for reusing this instance.
func (*LineIter) Next ¶
Next is the method that returns a string of the next line and a bool which indicates whether the returned line exists.
func (*LineIter) SetIndent ¶
SetIndent is the method to set an indentation for the subsequent lines.
Example ¶
package main import ( "fmt" "strings" "github.com/sttk/linebreak" ) func main() { text := "Go is a new language. Although it borrows ideas from existing " + "languages, it has unusual properties that make effective Go programs " + "different in character from programs written in its relatives. " + "\n\n(Quoted from 'Effective Go')" fmt.Println("....:....1....:....2....:....3....:....4....:....5") iter := linebreak.New(text, 50) line, exists := iter.Next() if exists { fmt.Println(line) for i := 1; iter.HasNext(); i++ { iter.SetIndent(strings.Repeat(" ", i*2)) line, _ := iter.Next() fmt.Println(line) } } }
Output: ....:....1....:....2....:....3....:....4....:....5 Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different in character from programs written in its relatives. (Quoted from 'Effective Go')