mirror of
https://gitea.com/Sirherobrine23/tea.git
synced 2024-08-21 16:47:25 +00:00
Merge branch 'master' into use-glamour select Glamour Theme based on BackgroundColor Merge branch 'master' into use-glamour Merge branch 'master' into use-glamour update termev update go.mod label color colorate use glamour for issue content Vendor: Add glamour Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/181 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
38 lines
771 B
Go
38 lines
771 B
Go
package colorful
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// A HexColor is a Color stored as a hex string "#rrggbb". It implements the
|
|
// database/sql.Scanner and database/sql/driver.Value interfaces.
|
|
type HexColor Color
|
|
|
|
type errUnsupportedType struct {
|
|
got interface{}
|
|
want reflect.Type
|
|
}
|
|
|
|
func (hc *HexColor) Scan(value interface{}) error {
|
|
s, ok := value.(string)
|
|
if !ok {
|
|
return errUnsupportedType{got: reflect.TypeOf(value), want: reflect.TypeOf("")}
|
|
}
|
|
c, err := Hex(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*hc = HexColor(c)
|
|
return nil
|
|
}
|
|
|
|
func (hc *HexColor) Value() (driver.Value, error) {
|
|
return Color(*hc).Hex(), nil
|
|
}
|
|
|
|
func (e errUnsupportedType) Error() string {
|
|
return fmt.Sprintf("unsupported type: got %v, want a %s", e.got, e.want)
|
|
}
|