Skip to content

Commit 73d3bf7

Browse files
Merge pull request #195 from technote-space/release/v0.7.0
Release/v0.7.0
2 parents 30ca8e0 + 7d862c1 commit 73d3bf7

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

__tests__/logger.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
spyOnStdout,
44
stdoutCalledWith,
55
} from '@technote-space/github-action-test-helper';
6-
import { Logger } from '../src';
6+
import {Logger} from '../src';
77

88
describe('Logger', () => {
99
beforeEach(() => {
@@ -110,12 +110,12 @@ describe('Logger', () => {
110110

111111
describe('getColorString', () => {
112112
it('should return color string', () => {
113-
expect(logger.getColorString('Hello World!!!', 'blue', 'red', 'bold')).toBe('\x1b[34;41;1mHello World!!!\x1b[0m');
113+
expect(logger.getColorString('Hello World!!!', {color: 'blue', backColor: 'red', attribute: 'bold'})).toBe('\x1b[34;41;1mHello World!!!\x1b[0m');
114114
expect(logger.getColorString('Hello World!!!')).toBe('\x1b[37;40;0mHello World!!!\x1b[0m');
115-
expect(logger.getColorString('Hello World!!!', 'green')).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
115+
expect(logger.getColorString('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
116116
expect(logger.c('Hello World!!!')).toBe('\x1b[37;40;0mHello World!!!\x1b[0m');
117-
expect(logger.c('Hello World!!!', 'green')).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
118-
expect(logger.c('Hello World!!!', 'yellow', undefined, 'underline')).toBe('\x1b[33;40;4mHello World!!!\x1b[0m');
117+
expect(logger.c('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
118+
expect(logger.c('Hello World!!!', {color: 'yellow', attribute: 'underline'})).toBe('\x1b[33;40;4mHello World!!!\x1b[0m');
119119
});
120120
});
121121
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/github-action-helper",
3-
"version": "0.6.29",
3+
"version": "0.7.0",
44
"description": "Helper to filter GitHub Action.",
55
"author": "Technote <[email protected]> (https://technote.space)",
66
"license": "MIT",

src/logger.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import {sprintf} from 'sprintf-js';
33
import {info, debug, error, warning, startGroup, endGroup} from '@actions/core';
44
import {split} from './utils';
55

6-
export type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
7-
export type Attribute = undefined | 'none' | 'bold' | 'underline' | 'italic';
86
const COLOR_MAP = {
97
'black': 0,
108
'red': 1,
@@ -21,6 +19,13 @@ const ATTRIBUTE_MAP = {
2119
'underline': 4,
2220
'italic': 3,
2321
};
22+
type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
23+
type Attribute = undefined | 'none' | 'bold' | 'underline' | 'italic';
24+
type Setting = {
25+
color?: Color;
26+
backColor?: Color;
27+
attribute?: Attribute;
28+
};
2429

2530
/**
2631
* Logger
@@ -156,21 +161,17 @@ export default class Logger {
156161

157162
/**
158163
* @param {string} string string
159-
* @param {Color|undefined} color color
160-
* @param {Color|undefined} backColor background color
161-
* @param {Attribute|undefined} attribute attribute
164+
* @param {Setting|undefined} setting setting
162165
* @return {string} color string
163166
*/
164-
public getColorString = (string: string, color?: Color, backColor?: Color, attribute?: Attribute): string => sprintf('\x1b[3%d;4%d;%dm%s\x1b[0m', COLOR_MAP[color ?? 'white'], COLOR_MAP[backColor ?? 'black'], ATTRIBUTE_MAP[attribute ?? 'none'], string);
167+
public getColorString = (string: string, setting?: Setting): string => sprintf('\x1b[3%d;4%d;%dm%s\x1b[0m', COLOR_MAP[setting?.color ?? 'white'], COLOR_MAP[setting?.backColor ?? 'black'], ATTRIBUTE_MAP[setting?.attribute ?? 'none'], string);
165168

166169
/**
167170
* @param {string} string string
168-
* @param {Color|undefined} color color
169-
* @param {Color|undefined} backColor background color
170-
* @param {Attribute|undefined} attribute attribute
171+
* @param {Setting|undefined} setting setting
171172
* @return {string} color string
172173
*/
173-
public c = (string: string, color?: Color, backColor?: Color, attribute?: Attribute): string => this.getColorString(string, color, backColor, attribute);
174+
public c = (string: string, setting?: Setting): string => this.getColorString(string, setting);
174175

175176
/**
176177
* @return {void}

0 commit comments

Comments
 (0)