-
Notifications
You must be signed in to change notification settings - Fork 70
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
feat: enable themes (#852) #862
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fc3d81e
feat: enable themes (#852)
AllanOricil 418d124
fix: https in yarn.lock
mdonnalley 52f2240
feat: use chalk for standard colors
mdonnalley 8cd05e4
fix: change http to https in order to pass lockfile-check workflow (#…
AllanOricil 295dd30
fix: streamline coloring
mdonnalley a21b119
Merge branch 'mdonnalley/852' of github.com:oclif/core into mdonnalle…
mdonnalley d2c1696
Merge branch 'main' into mdonnalley/852
mdonnalley cd746a6
fix: remove standardized id from usage string
mdonnalley 0db78d3
test: provide id to mocked command class
mdonnalley ccad43c
Merge branch 'main' into mdonnalley/852
mdonnalley 1a4c32b
chore: code review and clean up
mdonnalley 0194eaa
fix: support more chalk standards
mdonnalley 31604f8
fix: prepare for plugin-theme
mdonnalley 80cbda2
chore: add jsdoc to ux.colorize
mdonnalley 10fccf8
chore(release): 3.11.1-dev.0 [skip ci]
svc-cli-bot 171c983
fix: always convert to hex
mdonnalley 78bdacc
chore(release): 3.11.1-dev.1 [skip ci]
svc-cli-bot 0886fbf
chore: remove unused type
mdonnalley cdff2ad
chore: revert to single theme.json
mdonnalley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import chalk from 'chalk' | ||
import * as Color from 'color' | ||
|
||
import {STANDARD_CHALK, StandardChalk, Theme, Themes} from '../interfaces/theme' | ||
|
||
function isStandardChalk(color: any): color is StandardChalk { | ||
return STANDARD_CHALK.includes(color) | ||
} | ||
|
||
/** | ||
* Add color to text. | ||
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a chalk color (e.g. `red`) | ||
* @param text string to colorize | ||
* @returns colorized string | ||
*/ | ||
export function colorize(color: string | StandardChalk | undefined, text: string): string { | ||
if (isStandardChalk(color)) return chalk[color](text) | ||
|
||
return color ? chalk.hex(color)(text) : text | ||
} | ||
|
||
export function parseTheme(theme: Themes): Theme { | ||
const themes = theme.themes ?? {} | ||
const selected = theme.selected ? themes[theme.selected] ?? {} : {} | ||
return Object.fromEntries( | ||
Object.entries(selected) | ||
.map(([key, value]) => [key, getColor(value)]) | ||
.filter(([_, value]) => value), | ||
) | ||
} | ||
|
||
export function getColor(color: string): string | ||
export function getColor(color: StandardChalk): StandardChalk | ||
export function getColor(color: string | StandardChalk): string | StandardChalk | undefined { | ||
try { | ||
// eslint-disable-next-line new-cap | ||
return isStandardChalk(color) ? color : new Color.default(color).hex() | ||
} catch {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why loading all themes in memory if only one is used at a time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be used by https://github.com/oclif/plugin-theme/pull/7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not answer the question. What is the use case to have all themes in memory?