incluidas las librerias de transformacion de strings

master
DEV 3 years ago
parent 188dc68192
commit 6c058bb090

@ -0,0 +1,241 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name code.go
// Created by DEV
// Modified 06/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package ansi
import "strings"
/*
const (
ColorNone Code = iota
ColorBlack
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite
ColorHBlack
ColorHRed
ColorHGreen
ColorHYellow
ColorHBlue
ColorHMagenta
ColorHCyan
ColorHWhite
ColorDefault
)
*/
const (
TextBoldOn Code = 1024 << iota
TextUnderlineOn
TextBlinkOn
TextBoldOff
TextUnderlineOff
TextBlinkOff
//bgMask Code = 0b0000000000011111
bgMask Code = 0b1111110000011111
fgMask Code = 0b1111111111100000
clMask Code = 0b0000001111111111
txMask Code = 0b1111110000000000
bgShift int = 5
)
type (
Code uint16
)
func (c Code) Atts () string {
if c == 0 {
return ""
}
var r []string
m := c & txMask
if m != 0 {
dc := TextBoldOn
for i:=0; i<6; i++ {
if m & dc != 0 {
r = append(r,string(g.itx[i].name))
}
dc <<= 1
}
}
r = append(r,strings.Join([]string{c.FgColorName(),c.BgColorName()},":"))
return strings.Join(r,";")
}
func (c Code) Clear () Code {
return 0 }
func (c Code) ClearColor () Code {
return c & txMask }
func (c Code) ClearText () Code {
return c & clMask }
func (c Code) FgColor() Code {
return (c & clMask) & bgMask }
func (c Code) SetFgColor(color Code) Code {
return (c & fgMask) | color& bgMask }
func (c Code) FgColorName () string {
return string(g.ics[(c & clMask) & bgMask].name) }
func (c Code) BgColor() Code {
return ((c & clMask) & fgMask) >> bgShift }
func (c Code) SetBgColor(color Code) Code {
return (c & bgMask) | (color<< bgShift) & fgMask }
func (c Code) BgColorName () string {
return string(g.ics[((c & clMask) & fgMask) >> bgShift].name) }
func (c Code) SetColors(fg, bg Code) Code {
return c.SetFgColor(fg).SetBgColor(bg) }
func (c Code) IsBoldOn () bool {
return c & TextBoldOn != 0 }
func (c Code) IsBoldOff() bool {
return c & TextBoldOff != 0 }
func (c Code) IsBlinkOn() bool {
return c & TextBlinkOn != 0 }
func (c Code) IsBlinkOff() bool {
return c & TextBlinkOff != 0 }
func (c Code) IsUnderlineOn () bool {
return c & TextUnderlineOn != 0 }
func (c Code) IsUnderlineOff() bool {
return c & TextUnderlineOff != 0 }
func (c Code) SetBold (on bool) Code {
if on {
return (c &^ TextBoldOff) | TextBoldOn
}
return (c &^ TextBoldOn) | TextBoldOff
}
func (c Code) SetBlink (on bool) Code {
if on {
return (c &^ TextBlinkOff) | TextBlinkOn
}
return (c &^ TextBlinkOn) | TextBlinkOff
}
func (c Code) SetUnderline (on bool) Code {
if on {
return (c &^ TextUnderlineOff) | TextUnderlineOn
}
return (c &^ TextUnderlineOn) | TextUnderlineOff
}
func (c Code) scapeText () []byte {
m := c & txMask
if m == 0 {
return nil
}
var r []byte
dc := TextBoldOn
for i:=0; i<6; i++ {
if m & dc != 0 {
if r != nil {
r = append(r,';')
}
r = append(r, g.itx[i].esc...)
}
dc <<= 1
}
return r
}
func (c Code) scapeColor () []byte {
m := c & clMask
if m == 0 {
return nil
}
var r []byte
f := m & bgMask
b := (m & fgMask) >> bgShift
if f != 0 {
r = append(r, g.ics[f].fgEsc...)
}
if b != 0 {
if f > 0 {
r=append(r,';')
}
r = append(r, g.ics[b].bgEsc...)
}
return r
}
func (c Code) escape () []byte {
if c == 0 {
return []byte{'0'}
}
st := c.scapeText ()
sc := c.scapeColor()
if len(sc) == 0 {
return st
}
if len(st) == 0 {
return sc
}
return append(st,append([]byte{';'},sc...)...)
}
func (c Code) Escape() string {
if c == 0 {
return ""
}
r := c.escape()
return string(append(g.beginEscIni, append(r, g.beginEscEnd...)...))
}

@ -0,0 +1,231 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File n code.go
// Created by DEV
// Modified 06/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package ansi
import "strings"
const (
TextBoldOn Code = 1024 << iota
TextUnderlineOn
TextBlinkOn
TextBoldOff
TextUnderlineOff
TextBlinkOff
//bgMask Code = 0b0000000000011111
bgMask Code = 0b1111110000011111
fgMask Code = 0b1111111111100000
clMask Code = 0b0000001111111111
txMask Code = 0b1111110000000000
bgShift int = 5
)
type (
Code uint16
)
func (c Code) Atts () string {
if c == 0 {
return ""
}
var r []string
m := c & txMask
if m != 0 {
dc := TextBoldOn
for i:=0; i<6; i++ {
if m & dc != 0 {
r = append(r,string(g.itx[i].n))
}
dc <<= 1
}
}
r = append(r,strings.Join([]string{c.FgColor().Name(),c.BgColor().Name()},":"))
return strings.Join(r,";")
}
func (c Code) Clear () Code {
return 0 }
func (c Code) ClearColor () Code {
return c & txMask }
func (c Code) ClearText () Code {
return c & clMask }
func (c Code) FgColor() Color {
return Color((c & clMask) & bgMask) }
func (c Code) SetFgColor(color Color) Code {
if !color.IsValid() {
return c
}
return (c & fgMask) | Code(color)& bgMask
}
func (c Code) ResetFgColor() Code {
return (c & fgMask) | Code(colorDefault)& bgMask }
func (c Code) BgColor() Color {
return Color(((c & clMask) & fgMask) >> bgShift) }
func (c Code) SetBgColor(color Color) Code {
if !color.IsValid() {
return c
}
return (c & bgMask) | (Code(color)<< bgShift) & fgMask
}
func (c Code) ResetBgColor() Code {
return (c & bgMask) | (Code(colorDefault)<< bgShift) & fgMask }
func (c Code) SetColors(fg, bg Color) Code {
return c.SetFgColor(fg).SetBgColor(bg) }
func (c Code) IsBoldOn () bool {
return c & TextBoldOn != 0 }
func (c Code) IsBoldOff() bool {
return c & TextBoldOff != 0 }
func (c Code) IsBlinkOn() bool {
return c & TextBlinkOn != 0 }
func (c Code) IsBlinkOff() bool {
return c & TextBlinkOff != 0 }
func (c Code) IsUnderlineOn () bool {
return c & TextUnderlineOn != 0 }
func (c Code) IsUnderlineOff() bool {
return c & TextUnderlineOff != 0 }
func (c Code) SetBold (on bool) Code {
if on {
return (c &^ TextBoldOff) | TextBoldOn
}
return (c &^ TextBoldOn) | TextBoldOff
}
func (c Code) SetBlink (on bool) Code {
if on {
return (c &^ TextBlinkOff) | TextBlinkOn
}
return (c &^ TextBlinkOn) | TextBlinkOff
}
func (c Code) SetUnderline (on bool) Code {
if on {
return (c &^ TextUnderlineOff) | TextUnderlineOn
}
return (c &^ TextUnderlineOn) | TextUnderlineOff
}
func (c Code) scapeText () []byte {
m := c & txMask
if m == 0 {
return nil
}
var r []byte
dc := TextBoldOn
for i:=0; i<6; i++ {
if m & dc != 0 {
if r != nil {
r = append(r,';')
} else {
r = append(r,'0',';')
}
r = append(r, g.itx[i].s...)
}
dc <<= 1
}
return r
}
func (c Code) scapeColor () []byte {
m := c & clMask
if m == 0 {
return nil
}
var r []byte
f := m & bgMask
b := (m & fgMask) >> bgShift
if f != 0 {
r = append(r, g.ics[f].f...)
}
if b != 0 {
if f > 0 {
r=append(r,';')
}
r = append(r, g.ics[b].b...)
}
return r
}
func (c Code) escape () []byte {
if c == 0 {
return []byte{'0'}
}
st := c.scapeText ()
sc := c.scapeColor()
if len(sc) == 0 {
return st
}
if len(st) == 0 {
return sc
}
return append(st,append([]byte{';'},sc...)...)
}
func (c Code) EscapeValues () string {
return string(c.escape())
}
func (c Code) Esc() string {
if c == 0 {
return g.endEscStr
}
r := c.escape()
return string(append(g.beginEscIni, append(r, g.beginEscEnd...)...))
}

@ -59,18 +59,29 @@ func (c MiCustomErr) Unwrap () error {
func main() {
result := GenerateBinaryString()
fmt.Println(result)
c1 := ansi.Code(0).SetBold(true)
c2 := c1.SetBold(false)
//fmt.Printf("C1: %s C2: %s\n",c1.EscapeValues(),c2.EscapeValues())
fmt.Printf("%sCon Atributo Bold -> %ssin atributo Bold\n",c1.Esc(),c2.Esc())
c := ansi.ColorRed.SetBgColor(ansi.ColorHWhite).SetBlink(true).SetBold(true)
fmt.Printf("Attributes %s\n",c.Atts())
s := fmt.Sprintf("%sColor Red y White \n",c.Escape())
c1 = c1.Clear().SetUnderline(true)
c2 = c1.SetUnderline(false)
fmt.Printf("C1: %s C2: %s\n",c1.EscapeValues(),c2.EscapeValues())
fmt.Printf("%sCon Atributo -> %ssin atributo \n",c1.Esc(),c2.Esc())
sf := ansi.FilterEscapes([]byte(s))
c1 = c1.Clear().SetBlink(true).SetBgColor(ansi.ColorRed)
fmt.Printf("Filtrados %s\n",sf)
fmt.Printf("No filtrados %s\n",s)
c1 = c1.Clear().SetBlink(false).SetFgColor(ansi.ColorGreen)
fmt.Printf("C1: %s \n",c1.EscapeValues())
fmt.Println(c1)
c1 = c1.SetStyle(ansi.StyleBold)
fmt.Printf("C1: %s \n",c1.EscapeValues())
fmt.Println(c1)
c1 = c1.SetStyle(ansi.StyleBlink)
fmt.Printf("C1: %s \n",c1.EscapeValues())
fmt.Println(c1)
}

@ -2,7 +2,7 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name active.go
// File n active.go
// Created by DEV
// Modified 05/04/2024
//
@ -36,8 +36,8 @@ var (
charsEscs []byte
endEscStr string
ics []colorInfo
itx []textInfo
ics []struct { n []byte; f []byte; b []byte }
itx []struct { n []byte; s []byte }
}{
beginEscIni : []byte("\x1b["),
@ -45,37 +45,37 @@ var (
endEsc : []byte("\x1b[0m"),
endEscStr : "\x1b[0m",
ics : []colorInfo{
{[]byte("none") ,[]byte{},[]byte{}},
{[]byte("black") ,[]byte{'3','0'},[]byte{'4','0'}},
{[]byte("red") ,[]byte{'3','1'},[]byte{'4','1'}},
{[]byte("green") ,[]byte{'3','2'},[]byte{'4','2'}},
{[]byte("yellow") ,[]byte{'3','3'},[]byte{'4','3'}},
{[]byte("blue") ,[]byte{'3','4'},[]byte{'4','4'}},
{[]byte("magenta"),[]byte{'3','5'},[]byte{'4','5'}},
{[]byte("cyan") ,[]byte{'3','6'},[]byte{'4','6'}},
{[]byte("white") ,[]byte{'3','7'},[]byte{'4','7'}},
{[]byte("hblack") ,[]byte{'9','0'},[]byte{'1','0','0'}},
{[]byte("hred") ,[]byte{'9','1'},[]byte{'1','0','1'}},
{[]byte("hgreen") ,[]byte{'9','2'},[]byte{'1','0','2'}},
{[]byte("hyellow"),[]byte{'9','3'},[]byte{'1','0','3'}},
{[]byte("hblue") ,[]byte{'9','4'},[]byte{'1','0','4'}},
{[]byte("hmagent"),[]byte{'9','5'},[]byte{'1','0','5'}},
{[]byte("hcyan") ,[]byte{'9','6'},[]byte{'1','0','6'}},
{[]byte("hwhite") ,[]byte{'9','7'},[]byte{'1','0','7'}},
{[]byte("default"),[]byte{'3','7'},[]byte{'4','9'}},
ics : []struct { n []byte; f []byte; b []byte } {
{[]byte("none"), []byte{},[]byte{}},
{[]byte("black"), []byte{'3','0'},[]byte{'4','0'}},
{[]byte("red"), []byte{'3','1'},[]byte{'4','1'}},
{[]byte("green"), []byte{'3','2'},[]byte{'4','2'}},
{[]byte("yellow"), []byte{'3','3'},[]byte{'4','3'}},
{[]byte("blue"), []byte{'3','4'},[]byte{'4','4'}},
{[]byte("magenta"), []byte{'3','5'},[]byte{'4','5'}},
{[]byte("cyan"), []byte{'3','6'},[]byte{'4','6'}},
{[]byte("white"), []byte{'3','7'},[]byte{'4','7'}},
{[]byte("hblack"), []byte{'9','0'},[]byte{'1','0','0'}},
{[]byte("hred"), []byte{'9','1'},[]byte{'1','0','1'}},
{[]byte("hgreen"), []byte{'9','2'},[]byte{'1','0','2'}},
{[]byte("hyellow"), []byte{'9','3'},[]byte{'1','0','3'}},
{[]byte("hblue"), []byte{'9','4'},[]byte{'1','0','4'}},
{[]byte("hmagent"), []byte{'9','5'},[]byte{'1','0','5'}},
{[]byte("hcyan"), []byte{'9','6'},[]byte{'1','0','6'}},
{[]byte("hwhite"), []byte{'9','7'},[]byte{'1','0','7'}},
{[]byte("default"), []byte{'3','7'},[]byte{'4','9'}},
},
itx : []textInfo{
itx : []struct { n []byte; s []byte }{
{[]byte("bold-on"), []byte{'1'}},
{[]byte("underline-on"), []byte{'4'}},
{[]byte("blink-on"), []byte{'5'}},
{[]byte("bold-off"), []byte{'2','1'}},
{[]byte("underline-off"), []byte{'2','4'}},
{[]byte("blink-off"), []byte{'2','5'}},
{[]byte("bold-off"), []byte{'2','2'}},
{[]byte("underline-off"),[]byte{'2','5'}},
{[]byte("blink-off"), []byte{'2','7'}},
},
charsEscs: genCharEscapes(),
charsEscs : genCharEscapes(),
}
)
@ -83,21 +83,19 @@ var (
func genCharEscapes () []byte {
r := make([]byte,255)
for i:=int('a'); i<=int('c'); i++ {
r[i]=1
}
r['@']=1
for i:=int('A'); i<=int('Z'); i++ {
r[i]=1
r[i+32]=1
}
r[int('@')]=1
return r
}
func BeginEscape (code Code) string {
return code.Escape() }
func Esc (code Code) string {
return code.Esc() }
func EndEscape () string {
func EscEnd () string {
return g.endEscStr }

@ -1,35 +0,0 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name text-info.go
// Created by DEV
// Modified 06/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package ansi
type (
textInfo struct {
name []byte
esc []byte
}
)

@ -2,7 +2,7 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name code.go
// File n code.go
// Created by DEV
// Modified 06/04/2024
//
@ -23,30 +23,11 @@
package ansi
import "strings"
const (
ColorNone Code = iota
ColorBlack
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite
ColorHBlack
ColorHRed
ColorHGreen
ColorHYellow
ColorHBlue
ColorHMagenta
ColorHCyan
ColorHWhite
ColorDefault
import (
"strings"
)
const (
TextBoldOn Code = 1024 << iota
@ -62,6 +43,7 @@ const (
clMask Code = 0b0000001111111111
txMask Code = 0b1111110000000000
bgShift int = 5
stShift int = 10
)
@ -81,12 +63,12 @@ func (c Code) Atts () string {
dc := TextBoldOn
for i:=0; i<6; i++ {
if m & dc != 0 {
r = append(r,string(g.itx[i].name))
r = append(r,string(g.itx[i].n))
}
dc <<= 1
}
}
r = append(r,strings.Join([]string{c.FgColorName(),c.BgColorName()},":"))
r = append(r,strings.Join([]string{c.FgColor().Name(),c.BgColor().Name()},":"))
return strings.Join(r,";")
}
@ -102,32 +84,49 @@ func (c Code) ClearText () Code {
return c & clMask }
func (c Code) FgColor() Code {
return (c & clMask) & bgMask }
func (c Code) FgColor() Color {
return Color((c & clMask) & bgMask) }
func (c Code) SetFgColor(color Color) Code {
if !color.IsValid() {
return c
}
return (c & fgMask) | Code(color)& bgMask
}
func (c Code) SetFgColor(color Code) Code {
return (c & fgMask) | color& bgMask }
func (c Code) ResetFgColor() Code {
return (c & fgMask) | Code(colorDefault)& bgMask }
func (c Code) FgColorName () string {
return string(g.ics[(c & clMask) & bgMask].name) }
func (c Code) BgColor() Color {
return Color(((c & clMask) & fgMask) >> bgShift) }
func (c Code) BgColor() Code {
return ((c & clMask) & fgMask) >> bgShift }
func (c Code) SetBgColor(color Color) Code {
if !color.IsValid() {
return c
}
return (c & bgMask) | (Code(color)<< bgShift) & fgMask
}
func (c Code) SetBgColor(color Code) Code {
return (c & bgMask) | (color<< bgShift) & fgMask }
func (c Code) ResetBgColor() Code {
return (c & bgMask) | (Code(colorDefault)<< bgShift) & fgMask }
func (c Code) BgColorName () string {
return string(g.ics[((c & clMask) & fgMask) >> bgShift].name) }
func (c Code) SetColors(fg, bg Code) Code {
func (c Code) SetColors(fg, bg Color) Code {
return c.SetFgColor(fg).SetBgColor(bg) }
func (c Code) SetStyle (sty Style) Code {
v := Code(sty)
s := c >> 10
if s != 0 {
v = (((s >> 3) & ^ v) << 3) | v
}
return v << 10 | (c & clMask)
}
func (c Code) IsBoldOn () bool {
@ -182,8 +181,10 @@ func (c Code) scapeText () []byte {
if m & dc != 0 {
if r != nil {
r = append(r,';')
} else {
r = append(r,'0',';')
}
r = append(r, g.itx[i].esc...)
r = append(r, g.itx[i].s...)
}
dc <<= 1
}
@ -200,13 +201,13 @@ func (c Code) scapeColor () []byte {
f := m & bgMask
b := (m & fgMask) >> bgShift
if f != 0 {
r = append(r, g.ics[f].fgEsc...)
r = append(r, g.ics[f].f...)
}
if b != 0 {
if f > 0 {
r=append(r,';')
}
r = append(r, g.ics[b].bgEsc...)
r = append(r, g.ics[b].b...)
}
return r
}
@ -227,11 +228,15 @@ func (c Code) escape () []byte {
return append(st,append([]byte{';'},sc...)...)
}
func (c Code) EscapeValues () string {
return string(c.escape())
}
func (c Code) Escape() string {
func (c Code) Esc() string {
if c == 0 {
return ""
return g.endEscStr
}
r := c.escape()
return string(append(g.beginEscIni, append(r, g.beginEscEnd...)...))
}

@ -2,7 +2,7 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name code_color.go
// File n code_color.go
// Created by DEV
// Modified 06/04/2024
//
@ -26,7 +26,7 @@ package ansi
const (
ColorNone AnsiColor = iota
ColorNone Color = iota
ColorBlack
ColorRed
ColorGreen
@ -43,13 +43,23 @@ const (
ColorHMagenta
ColorHCyan
ColorHWhite
ColorDefault
colorDefault
)
type (
AnsiColor uint8
Color uint8
)
func (c Color) Name () string {
if c.IsValid() {
return string(g.ics[c].n)
}
return string(g.ics[0].n)
}
func (c Color) IsValid () bool {
return c >= ColorNone && c <= colorDefault
}

@ -2,7 +2,7 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name non_escape_reader.go
// File n non_escape_reader.go
// Created by DEV
// Modified 06/04/2024
//

@ -2,7 +2,7 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name non_colorable_writer.go
// File n non_colorable_writer.go
// Created by DEV
// Modified 06/04/2024
//
@ -24,6 +24,7 @@
package ansi
import (
"bytes"
"io"
)
@ -41,6 +42,33 @@ func NewNonEscapeWriter(w io.Writer) *NonEscapeWriter {
func (w *NonEscapeWriter) Write (data []byte) (c int, e error) {
return w.writer.Write(FilterEscapes(data)) }
func (w *NonEscapeWriter) Write(data []byte) (n int, e error) {
var pt bytes.Buffer
var ef bool
for _, b := range data {
if b == 0x1b {
ef = true
continue
}
if ef && b == 0x5b {
ef = false
continue
}
if ef {
ef = g.charsEscs[b] == 0
continue
}
pt.WriteByte(b)
}
_, e = pt.WriteTo(w.writer)
if e != nil {
return n, e
}
return len(data), nil
}

@ -2,7 +2,7 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name color.go
// File name style.go
// Created by DEV
// Modified 06/04/2024
//
@ -23,17 +23,28 @@
package ansi
const (
StyleBold Style = 1 << iota
StyleUnderline
StyleBlink
//StyleNonBold
//StyleNonUnderline
//StyleNonBlink
type (
StyleNone Style = 0
)
colorInfo struct {
name []byte
fgEsc []byte
bgEsc []byte
type (
}
Style uint8
)
func (s Style) IsValid () bool {
return true
}

@ -23,6 +23,8 @@
package bins
import "errs"
const (
minBitSize = 6
@ -45,7 +47,7 @@ var (
ErrNegativeRead errs.ErrCode
ErrUnreadInvalid errs.ErrCode
bufferPool *BufferPool
}{
ErrOutOfRange: errs.ErrCode("core:bins.out-of-range"),
@ -55,6 +57,14 @@ var (
ErrNegativeRead: errs.ErrCode("core:bins.negative-read"),
ErrUnreadInvalid: errs.ErrCode("core:bins.unread-invalid"),
}
g = struct {
bufferPool *BufferPool
}{
bufferPool: NewBufferPool(),
}
)
@ -62,9 +72,9 @@ var (
func AcquireBuffer () *Buffer {
return G.bufferPool.Get() }
return g.bufferPool.Get() }
func ReleaseBuffer (buffer *Buffer) {
G.bufferPool.Put(buffer) }
g.bufferPool.Put(buffer) }

@ -46,7 +46,6 @@ const (
var (
G = struct {
mux sync.RWMutex
Formatter fmts.Formatter
@ -54,18 +53,20 @@ var (
ErrParamInvalid ErrCode
ErrParamOutOfRange ErrCode
stackTraceRType reflect.Type
}{
ErrParamNil : ErrCode("param-CodePanicError"),
ErrParamInvalid : ErrCode("param-invalid"),
ErrParamOutOfRange : ErrCode("param-out-of-range"),
stackTraceRType : reflect.TypeOf(stack.Trace(nil)),
Formatter : ftext.DefaultFormatter(),
}
g = struct {
mux sync.RWMutex
stackTraceRType reflect.Type
}{
stackTraceRType : reflect.TypeOf(stack.Trace(nil)),
}
)

Loading…
Cancel
Save

Powered by TurnKey Linux.