-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(git): Add --color and --no-color options
These allow the user to force color on or off. The chalk library is used for the output, because it's already used elsewhere in Puter and seems like a good choice. Ideally, the default will be based on whether stdout is a tty, but Puter doesn't yet have that concept, so we just default to color.
- Loading branch information
1 parent
364d580
commit d6dd1a5
Showing
9 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2024 Puter Technologies Inc. | ||
* | ||
* This file is part of Puter's Git client. | ||
* | ||
* Puter's Git client is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
import chalk from 'chalk'; | ||
|
||
export const color_options = { | ||
'color': { | ||
// TODO: '--color[=<when>]' syntax, once we have an args parser that supports optional string option-arguments. | ||
description: 'Force colored output.', | ||
type: 'boolean', | ||
}, | ||
'no-color': { | ||
description: 'Disable colored output.', | ||
type: 'boolean', | ||
}, | ||
} | ||
|
||
/** | ||
* Process command-line options related to color, and modify them in place. | ||
* Sets the chalk color level based on whether color is enabled or disabled. | ||
* @param options Parsed command-line options, which will be modified in place. | ||
*/ | ||
export const process_color_options = (options) => { | ||
|
||
if (!options['color'] && !options['no-color']) { | ||
// TODO: Default to whether we're running in a TTY, once we have that concept. | ||
options['color'] = true; | ||
} | ||
|
||
if (options['no-color']) { | ||
options['color'] = false; | ||
delete options['no-color']; | ||
} | ||
|
||
chalk.level = options.color ? 3 : 0; | ||
} |
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
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