Rename Par to Paragraph

This commit is contained in:
Caleb Bassi 2018-11-28 18:24:38 -08:00
parent ea15e228f4
commit 7f3648562a
10 changed files with 77 additions and 77 deletions

View File

@ -20,7 +20,7 @@ func main() {
}
defer ui.Close()
p := ui.NewPar("PRESS q TO QUIT DEMO")
p := ui.NewParagraph("PRESS q TO QUIT DEMO")
p.Height = 3
p.Width = 50
p.TextFgColor = ui.ColorWhite
@ -120,7 +120,7 @@ func main() {
lc2.AxesColor = ui.ColorWhite
lc2.LineColor["default"] = ui.ColorYellow | ui.AttrBold
p2 := ui.NewPar("Hey!\nI am a borderless block!")
p2 := ui.NewParagraph("Hey!\nI am a borderless block!")
p2.Border = false
p2.Width = 26
p2.Height = 2

View File

@ -76,9 +76,9 @@ func main() {
}
ls.Height = 5
par := ui.NewPar("<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget")
par.Height = 5
par.BorderLabel = "Demonstration"
p := ui.NewParagraph("<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget")
p.Height = 5
p.BorderLabel = "Demonstration"
// build layout
ui.Body.AddRows(
@ -88,7 +88,7 @@ func main() {
ui.NewRow(
ui.NewCol(3, 0, ls),
ui.NewCol(3, 0, gs[0], gs[1], gs[2]),
ui.NewCol(6, 0, par)))
ui.NewCol(6, 0, p)))
// calculate layout
ui.Body.Align()

View File

@ -1,52 +0,0 @@
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import ui "github.com/gizak/termui"
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
par0 := ui.NewPar("Borderless Text")
par0.Height = 1
par0.Width = 20
par0.Y = 1
par0.Border = false
par1 := ui.NewPar("你好,世界。")
par1.Height = 3
par1.Width = 17
par1.X = 20
par1.BorderLabel = "标签"
par2 := ui.NewPar("Simple colored text\nwith label. It [can be](fg-red) multilined with \\n or [break automatically](fg-red,fg-bold)")
par2.Height = 5
par2.Width = 37
par2.Y = 4
par2.BorderLabel = "Multiline"
par2.BorderFg = ui.ColorYellow
par3 := ui.NewPar("Long text with label and it is auto trimmed.")
par3.Height = 3
par3.Width = 37
par3.Y = 9
par3.BorderLabel = "Auto Trim"
ui.Render(par0, par1, par2, par3)
for {
e := <-ui.PollEvent()
switch e.ID {
case "q", "<C-c>":
return
}
}
}

52
_examples/paragraph.go Normal file
View File

@ -0,0 +1,52 @@
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import ui "github.com/gizak/termui"
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
p0 := ui.NewParagraph("Borderless Text")
p0.Height = 1
p0.Width = 20
p0.Y = 1
p0.Border = false
p1 := ui.NewParagraph("你好,世界。")
p1.Height = 3
p1.Width = 17
p1.X = 20
p1.BorderLabel = "标签"
p2 := ui.NewParagraph("Simple colored text\nwith label. It [can be](fg-red) multilined with \\n or [break automatically](fg-red,fg-bold)")
p2.Height = 5
p2.Width = 37
p2.Y = 4
p2.BorderLabel = "Multiline"
p2.BorderFg = ui.ColorYellow
p3 := ui.NewParagraph("Long text with label and it is auto trimmed.")
p3.Height = 3
p3.Width = 37
p3.Y = 9
p3.BorderLabel = "Auto Trim"
ui.Render(p0, p1, p2, p3)
for {
e := <-ui.PollEvent()
switch e.ID {
case "q", "<C-c>":
return
}
}
}

View File

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -18,20 +18,20 @@ func main() {
}
defer ui.Close()
header := ui.NewPar("Press q to quit, Press h or l to switch tabs")
header := ui.NewParagraph("Press q to quit, Press h or l to switch tabs")
header.Height = 1
header.Width = 50
header.Border = false
header.TextBgColor = ui.ColorBlue
tab1 := extra.NewTab("pierwszy")
par2 := ui.NewPar("Press q to quit\nPress h or l to switch tabs\n")
par2.Height = 5
par2.Width = 37
par2.Y = 0
par2.BorderLabel = "Keys"
par2.BorderFg = ui.ColorYellow
tab1.AddBlocks(par2)
p2 := ui.NewParagraph("Press q to quit\nPress h or l to switch tabs\n")
p2.Height = 5
p2.Width = 37
p2.Y = 0
p2.BorderLabel = "Keys"
p2.BorderFg = ui.ColorYellow
tab1.AddBlocks(p2)
tab2 := extra.NewTab("drugi")
bc := ui.NewBarChart()

View File

@ -33,7 +33,7 @@ func main() {
"gauge.percent.fg": ui.ColorBlue,
"barchart.bar.bg": ui.ColorRed,
}
p := ui.NewPar(":PRESS q TO QUIT DEMO")
p := ui.NewParagraph(":PRESS q TO QUIT DEMO")
p.Height = 3
p.Width = 50
p.BorderLabel = "Text Box"
@ -118,7 +118,7 @@ func main() {
lc1.X = 51
lc1.Y = 14
p1 := ui.NewPar("Hey!\nI am a borderless block!")
p1 := ui.NewParagraph("Hey!\nI am a borderless block!")
p1.Border = false
p1.Width = 26
p1.Height = 2

View File

@ -284,7 +284,7 @@ func main() {
termWidth := 70
header := ui.NewPar("Press q to quit, Press h or l to switch tabs")
header := ui.NewParagraph("Press q to quit, Press h or l to switch tabs")
header.Height = 1
header.Width = 50
header.Border = false

View File

@ -15,7 +15,7 @@ func main() {
}
defer ui.Close()
p := ui.NewPar("Press q to QUIT THE DEMO. [There](fg-blue) are other things [that](fg-red) are going to fit in here I think. What do you think? Now is the time for all good [men to](bg-blue) come to the aid of their country. [This is going to be one really really really long line](fg-green) that is going to go together and stuffs and things. Let's see how this thing renders out.\n Here is a new paragraph and stuffs and things. There should be a tab indent at the beginning of the paragraph. Let's see if that worked as well.")
p := ui.NewParagraph("Press q to QUIT THE DEMO. [There](fg-blue) are other things [that](fg-red) are going to fit in here I think. What do you think? Now is the time for all good [men to](bg-blue) come to the aid of their country. [This is going to be one really really really long line](fg-green) that is going to go together and stuffs and things. Let's see how this thing renders out.\n Here is a new paragraph and stuffs and things. There should be a tab indent at the beginning of the paragraph. Let's see if that worked as well.")
p.WrapLength = 48 // this should be at least p.Width - 2
p.Height = 20
p.Width = 50

View File

@ -4,14 +4,14 @@
package termui
// Par displays a paragraph.
// Paragraph displays a paragraph.
/*
par := termui.NewPar("Simple Text")
par := termui.NewParagraph("Simple Text")
par.Height = 3
par.Width = 17
par.BorderLabel = "Label"
*/
type Par struct {
type Paragraph struct {
Block
Text string
TextFgColor Attribute
@ -19,9 +19,9 @@ type Par struct {
WrapLength int // words wrap limit. Note it may not work properly with multi-width char
}
// NewPar returns a new *Par with given text as its content.
func NewPar(s string) *Par {
return &Par{
// NewParagraph returns a new *Paragraph with given text as its content.
func NewParagraph(s string) *Paragraph {
return &Paragraph{
Block: *NewBlock(),
Text: s,
TextFgColor: ThemeAttr("par.text.fg"),
@ -31,7 +31,7 @@ func NewPar(s string) *Par {
}
// Buffer implements Bufferer interface.
func (p *Par) Buffer() Buffer {
func (p *Paragraph) Buffer() Buffer {
buf := p.Block.Buffer()
fg, bg := p.TextFgColor, p.TextBgColor