From 8ba26814b21f49a6e1df6ae9475697a5bcd75d07 Mon Sep 17 00:00:00 2001 From: qeesung <1245712564@qq.com> Date: Mon, 29 Oct 2018 21:19:49 +0800 Subject: [PATCH] fixed the lint issue --- ascii/ascii.go | 3 +++ ascii/ascii_test.go | 2 +- convert/convert.go | 4 ++++ convert/convert_test.go | 2 +- convert/resize.go | 6 ++++++ convert/resize_test.go | 2 +- terminal/terminal.go | 6 ++++++ 7 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ascii/ascii.go b/ascii/ascii.go index 1d900b7..6bd142b 100644 --- a/ascii/ascii.go +++ b/ascii/ascii.go @@ -38,14 +38,17 @@ func (options *Options) mergeOptions(newOptions *Options) { options.Colored = newOptions.Colored } +// NewPixelConverter create a new pixel converter func NewPixelConverter() PixelConverter { return PixelASCIIConverter{} } +// PixelConverter define the convert pixel operation type PixelConverter interface { ConvertPixelToASCII(pixel color.Color, options *Options) string } +// PixelASCIIConverter responsible for pixel ascii conversion type PixelASCIIConverter struct { } diff --git a/ascii/ascii_test.go b/ascii/ascii_test.go index aa6306b..66c8630 100644 --- a/ascii/ascii_test.go +++ b/ascii/ascii_test.go @@ -115,7 +115,7 @@ func TestReverseSlice(t *testing.T) { } // ExampleConvertPixelToASCII is a example convert pixel to ascii char -func ExampleConvertPixelToASCII() { +func ExamplePixelASCIIConverter_ConvertPixelToASCII() { converter := NewPixelConverter() // Create the pixel r, g, b, a := uint8(255), uint8(255), uint8(255), uint8(255) diff --git a/convert/convert.go b/convert/convert.go index 51f1943..2299c77 100644 --- a/convert/convert.go +++ b/convert/convert.go @@ -36,6 +36,7 @@ var DefaultOptions = Options{ StretchedScreen: false, } +// NewImageConverter create a new image converter func NewImageConverter() *ImageConverter { return &ImageConverter{ resizeHandler: NewResizeHandler(), @@ -43,6 +44,7 @@ func NewImageConverter() *ImageConverter { } } +// Converter define the convert image basic operations type Converter interface { Image2ASCIIMatrix(image image.Image, imageConvertOptions *Options) []string Image2ASCIIString(image image.Image, options *Options) string @@ -50,6 +52,8 @@ type Converter interface { ImageFile2ASCIIString(imageFilename string, option *Options) string } +// ImageConverter implement the Convert interface, and responsible +// to image conversion type ImageConverter struct { resizeHandler ResizeHandler pixelConverter ascii.PixelConverter diff --git a/convert/convert_test.go b/convert/convert_test.go index 58a7997..7dd7f01 100644 --- a/convert/convert_test.go +++ b/convert/convert_test.go @@ -151,7 +151,7 @@ func BenchmarkSmallImage2ASCIIMatrix(b *testing.B) { } // ExampleImage2ASCIIMatrix is example -func ExampleImage2ASCISString() { +func ExampleImageConverter_ImageFile2ASCIIString() { converter := NewImageConverter() imageFilename := "testdata/3x3_white.png" convertOptions := DefaultOptions diff --git a/convert/resize.go b/convert/resize.go index 3b79c76..5ccc6bb 100644 --- a/convert/resize.go +++ b/convert/resize.go @@ -7,16 +7,20 @@ import ( "log" ) +// NewResizeHandler create a new resize handler func NewResizeHandler() ResizeHandler { return &ImageResizeHandler{ terminal: terminal.NewTerminalAccessor(), } } +// ResizeHandler define the operation to resize a image type ResizeHandler interface { ScaleImage(image image.Image, options *Options) (newImage image.Image) } +// ImageResizeHandler implement the ResizeHandler interface and +// responsible for image resizing type ImageResizeHandler struct { terminal terminal.Terminal } @@ -119,10 +123,12 @@ func (handler *ImageResizeHandler) CalcFitSize(width, height, toBeFitWidth, toBe return } +// ScaleWidthByRatio scaled the width by ratio func (handler *ImageResizeHandler) ScaleWidthByRatio(width float64, ratio float64) int { return int(width * ratio) } +// ScaleHeightByRatio scaled the height by ratio func (handler *ImageResizeHandler) ScaleHeightByRatio(height float64, ratio float64) int { return int(height * ratio * handler.terminal.CharWidth()) } diff --git a/convert/resize_test.go b/convert/resize_test.go index bcdc9ce..39055e0 100644 --- a/convert/resize_test.go +++ b/convert/resize_test.go @@ -194,7 +194,7 @@ func TestStretchTheTerminalScreenSize(t *testing.T) { } // ExampleScaleImage is scale image example -func ExampleScaleImage() { +func ExampleImageResizeHandler_ScaleImage() { handler := NewResizeHandler() imageFilePath := "testdata/cat_2000x1500.jpg" img, err := OpenImageFile(imageFilePath) diff --git a/terminal/terminal.go b/terminal/terminal.go index bd4df15..8bf9b6b 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -13,6 +13,7 @@ const ( charWidthOther = 0.5 ) +// NewTerminalAccessor create a new terminal accessor func NewTerminalAccessor() Terminal { return Accessor{} } @@ -24,9 +25,12 @@ type Terminal interface { IsWindows() bool } +// Accessor implement the Terminal interface and +// fetch the terminal basic information type Accessor struct { } +// CharWidth get the terminal char width func (accessor Accessor) CharWidth() float64 { if accessor.IsWindows() { return charWidthWindows @@ -34,10 +38,12 @@ func (accessor Accessor) CharWidth() float64 { return charWidthOther } +// IsWindows check if current system is windows func (accessor Accessor) IsWindows() bool { return runtime.GOOS == "windows" } +// ScreenSize get the terminal screen size func (accessor Accessor) ScreenSize() (newWidth, newHeight int, err error) { if !isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()) { return 0, 0, -- 2.45.2