Skip to content

Commit 9e23a14

Browse files
committed
Add theming support
Closes #151
1 parent 5c670f0 commit 9e23a14

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
66
### Added
7-
...
7+
- Added support for Terminal with a light theme. To enable specify `light` as a value of `theme` config setting in `~/.svn-buddy/config.json` file.
88

99
### Changed
1010
- Show executed SVN commands in real time (when started; how long was executed) in verbose mode (the `-v` flag).

src/SVNBuddy/Command/AbstractCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ abstract class AbstractCommand extends BaseCommand
5858
*/
5959
protected $workingDirectory = null;
6060

61+
/**
62+
* Accent style.
63+
*
64+
* @var string
65+
*/
66+
protected $accentStyle;
67+
6168
/**
6269
* Working copy resolver.
6370
*
@@ -169,6 +176,8 @@ protected function prepareDependencies()
169176
$this->workingDirectory = $container['working_directory'];
170177
$this->_commandConfig = $container['command_config'];
171178
$this->_updateManager = $container['update_manager'];
179+
180+
$this->accentStyle = $container['dark_theme'] ? 'fg=white;options=bold' : 'fg=cyan';
172181
}
173182

174183
/**

src/SVNBuddy/Command/CommitCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
183183
$edited_commit_message = trim(substr($edited_commit_message, 0, $stop_line_pos));
184184
}
185185

186-
$this->io->writeln(array('<fg=white;options=bold>Commit message:</>', $edited_commit_message, ''));
186+
$this->io->writeln(array('<' . $this->accentStyle . '>Commit message:</>', $edited_commit_message, ''));
187187

188188
if ( !$this->io->askConfirmation('Run "svn commit"', false) ) {
189189
throw new CommandException('Commit aborted by user.');
@@ -208,7 +208,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
208208
}
209209

210210
$this->repositoryConnector->getCommand('commit', $arguments)->runLive(array(
211-
'/(Committed revision [\d]+\.)/' => '<fg=white;options=bold>$1</>',
211+
'/(Committed revision [\d]+\.)/' => '<' . $this->accentStyle . '>$1</>',
212212
));
213213
$this->_workingCopyConflictTracker->erase($wc_path);
214214
unlink($tmp_file);

src/SVNBuddy/Command/MergeCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ protected function performMerge($source_url, $wc_path, array $revisions)
673673
$revision_log = $this->getRevisionLog($source_url);
674674
$revisions_data = $revision_log->getRevisionsData('summary', $revisions);
675675

676-
$revision_title_mask = $revision_log->getRevisionURLBuilder()->getMask('fg=white;options=bold,underscore');
676+
if ( strpos($this->accentStyle, 'options') !== false ) {
677+
$title_accent_style = $this->accentStyle . ',underscore';
678+
}
679+
else {
680+
$title_accent_style = $this->accentStyle . ';options=underscore';
681+
}
682+
683+
$revision_title_mask = $revision_log->getRevisionURLBuilder()->getMask($title_accent_style);
677684

678685
// Added " revision" text, when URL wasn't detected.
679686
if ( strpos($revision_title_mask, '://') === false ) {
@@ -689,7 +696,7 @@ protected function performMerge($source_url, $wc_path, array $revisions)
689696
$progress_bar = $this->createMergeProgressBar($used_revision_count + $index + 1, $revision_count);
690697

691698
// 1. Add revision link with a progress bar.
692-
$merge_heading = PHP_EOL . '<fg=white;options=bold>';
699+
$merge_heading = PHP_EOL . '<' . $this->accentStyle . '>';
693700
$merge_heading .= '--- $1 ' . \str_replace('{revision}', $revision, $revision_title_mask);
694701
$merge_heading .= " into '$2' " . $progress_bar . ':</>';
695702

@@ -698,7 +705,7 @@ protected function performMerge($source_url, $wc_path, array $revisions)
698705
$commit_message = wordwrap($commit_message, 68); // FIXME: Not UTF-8 safe solution.
699706
$merge_heading .= PHP_EOL . $commit_message;
700707
$merge_heading .= PHP_EOL;
701-
$merge_heading .= PHP_EOL . '<fg=white;options=bold>Changed Paths:</>';
708+
$merge_heading .= PHP_EOL . '<' . $this->accentStyle . '>Changed Paths:</>';
702709

703710
$command->runLive(array(
704711
$wc_path => '.',

src/SVNBuddy/Container.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,16 @@ public function __construct(array $values = array())
9393
'repository-connector.password' => '',
9494
'repository-connector.last-revision-cache-duration' => '10 minutes',
9595
'update-channel' => 'stable',
96+
'theme' => 'dark',
9697
);
9798

99+
$this['dark_theme'] = function ($c) {
100+
/** @var ConfigEditor $config_editor */
101+
$config_editor = $c['config_editor'];
102+
103+
return $config_editor->get('theme', $c['config_defaults']['theme']) === 'dark';
104+
};
105+
98106
$this->extend('output', function ($output) {
99107
/** @var OutputInterface $output */
100108
$output->getFormatter()->setStyle('debug', new OutputFormatterStyle('white', 'magenta'));
@@ -184,7 +192,7 @@ public function __construct(array $values = array())
184192
};
185193

186194
$this['revision_printer'] = function ($c) {
187-
return new RevisionPrinter($c['date_helper'], $c['output_helper']);
195+
return new RevisionPrinter($c['date_helper'], $c['output_helper'], $c['dark_theme']);
188196
};
189197

190198
$this['command_factory'] = function ($c) {

src/SVNBuddy/Repository/RevisionLog/RevisionPrinter.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class RevisionPrinter
4747
*/
4848
private $_outputHelper;
4949

50+
/**
51+
* Accent style.
52+
*
53+
* @var string
54+
*/
55+
private $_accentStyle;
56+
5057
/**
5158
* Columns.
5259
*
@@ -87,11 +94,13 @@ class RevisionPrinter
8794
*
8895
* @param DateHelper $date_helper Date helper.
8996
* @param OutputHelper $output_helper Output helper.
97+
* @param boolean $is_dark_theme Is dark theme.
9098
*/
91-
public function __construct(DateHelper $date_helper, OutputHelper $output_helper)
99+
public function __construct(DateHelper $date_helper, OutputHelper $output_helper, $is_dark_theme)
92100
{
93101
$this->_dateHelper = $date_helper;
94102
$this->_outputHelper = $output_helper;
103+
$this->_accentStyle = $is_dark_theme ? 'fg=white;options=bold' : 'fg=cyan';
95104

96105
$this->_resetState();
97106
}
@@ -302,7 +311,7 @@ public function printRevisions(RevisionLog $revision_log, array $revisions, Outp
302311

303312
if ( $revision === $this->_currentRevision ) {
304313
foreach ( $row as $index => $cell ) {
305-
$row[$index] = $this->applyStyle($cell, 'fg=white;options=bold');
314+
$row[$index] = $this->applyStyle($cell, $this->_accentStyle);
306315
}
307316
}
308317

@@ -558,11 +567,11 @@ private function _generateDetailsRowContent(
558567
$details = '';
559568

560569
if ( $revision_url_mask ) {
561-
$details .= '<fg=white;options=bold>Revision URL:</>' . PHP_EOL;
570+
$details .= '<' . $this->_accentStyle . '>Revision URL:</>' . PHP_EOL;
562571
$details .= str_replace('{revision}', $revision, $revision_url_mask) . PHP_EOL . PHP_EOL;
563572
}
564573

565-
$details .= '<fg=white;options=bold>Changed Paths:</>';
574+
$details .= '<' . $this->_accentStyle . '>Changed Paths:</>';
566575
$path_cut_off_regexp = $this->getPathCutOffRegExp($project_path, $revisions_refs[$revision]);
567576

568577
foreach ( $revision_paths as $path_data ) {

0 commit comments

Comments
 (0)