Skip to content

Release/v0.7.0 #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions __tests__/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
spyOnStdout,
stdoutCalledWith,
} from '@technote-space/github-action-test-helper';
import { Logger } from '../src';
import {Logger} from '../src';

describe('Logger', () => {
beforeEach(() => {
Expand Down Expand Up @@ -110,12 +110,12 @@ describe('Logger', () => {

describe('getColorString', () => {
it('should return color string', () => {
expect(logger.getColorString('Hello World!!!', 'blue', 'red', 'bold')).toBe('\x1b[34;41;1mHello World!!!\x1b[0m');
expect(logger.getColorString('Hello World!!!', {color: 'blue', backColor: 'red', attribute: 'bold'})).toBe('\x1b[34;41;1mHello World!!!\x1b[0m');
expect(logger.getColorString('Hello World!!!')).toBe('\x1b[37;40;0mHello World!!!\x1b[0m');
expect(logger.getColorString('Hello World!!!', 'green')).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
expect(logger.getColorString('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
expect(logger.c('Hello World!!!')).toBe('\x1b[37;40;0mHello World!!!\x1b[0m');
expect(logger.c('Hello World!!!', 'green')).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
expect(logger.c('Hello World!!!', 'yellow', undefined, 'underline')).toBe('\x1b[33;40;4mHello World!!!\x1b[0m');
expect(logger.c('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40;0mHello World!!!\x1b[0m');
expect(logger.c('Hello World!!!', {color: 'yellow', attribute: 'underline'})).toBe('\x1b[33;40;4mHello World!!!\x1b[0m');
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-helper",
"version": "0.6.29",
"version": "0.7.0",
"description": "Helper to filter GitHub Action.",
"author": "Technote <[email protected]> (https://technote.space)",
"license": "MIT",
Expand Down
21 changes: 11 additions & 10 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {sprintf} from 'sprintf-js';
import {info, debug, error, warning, startGroup, endGroup} from '@actions/core';
import {split} from './utils';

export type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
export type Attribute = undefined | 'none' | 'bold' | 'underline' | 'italic';
const COLOR_MAP = {
'black': 0,
'red': 1,
Expand All @@ -21,6 +19,13 @@ const ATTRIBUTE_MAP = {
'underline': 4,
'italic': 3,
};
type Color = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
type Attribute = undefined | 'none' | 'bold' | 'underline' | 'italic';
type Setting = {
color?: Color;
backColor?: Color;
attribute?: Attribute;
};

/**
* Logger
Expand Down Expand Up @@ -156,21 +161,17 @@ export default class Logger {

/**
* @param {string} string string
* @param {Color|undefined} color color
* @param {Color|undefined} backColor background color
* @param {Attribute|undefined} attribute attribute
* @param {Setting|undefined} setting setting
* @return {string} color string
*/
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);
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);

/**
* @param {string} string string
* @param {Color|undefined} color color
* @param {Color|undefined} backColor background color
* @param {Attribute|undefined} attribute attribute
* @param {Setting|undefined} setting setting
* @return {string} color string
*/
public c = (string: string, color?: Color, backColor?: Color, attribute?: Attribute): string => this.getColorString(string, color, backColor, attribute);
public c = (string: string, setting?: Setting): string => this.getColorString(string, setting);

/**
* @return {void}
Expand Down